import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import java.nio.*; import java.util.*; import javax.imageio.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; /** * Example JOGL application showing bug when using gluScaleImage. The application * simply displays a quad with a texture map. Load any non square image, the * sample included is 134x57. Run the application with and without the following * JVM command line argument: * * -Djogl.glu.nojava * * When the application is ran *with* this command line argument the texture is * displayed correctly. When the application is ran without the texture is not * scaled correctly. * * Run environment: * Machine : Dell Precision M70 laptop * OS : Windows XP SP2 * Graphics : NVIDIA Quadro FX Go1400 * Drivers : lastest from DELL dated: 22/03/2006 ver. 8.4.3.0 * JVM : j2sdk1.4.2_10 * JOGL : release 1.1.0-rc3 from Feb 14 2007 * * @author Alan Michael Gay, AVS Inc. */ public class JOGLTexture extends Frame implements GLEventListener, ImageConsumer { // Name of example mage file to load String nonSquareImageFileName = ".\\non-squareimage.jpg"; // // OpenGL variables. // private GLU glu = new GLU(); private int textureName; // // Workspace variables for consuming image. // boolean imageComplete = false; private int imageWidth = 0; private int imageHeight = 0; private byte[] imageBuffer = null; public JOGLTexture() { // Loads the image we are going to use in this example. loadImage(nonSquareImageFileName); // Specify the Frame window title and initial size. setTitle("gluScaleImage bug"); // Create a listener object that will cause the application // to exit when the user dismisses the Frame window. this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // Use the default capabilities. GLCapabilities capabilities = new GLCapabilities(); GLCanvas canvas = new GLCanvas(capabilities); canvas.addGLEventListener(this); this.add(canvas); } /** * Loads the specified image from file. * @param fileName The string filename for the image. */ private void loadImage(String fileName) { File input = new File(fileName); Image image = null; try { image = ImageIO.read(input); } catch (Throwable e) { System.out.println("Failed to load image file: " + e.getMessage()); } ImageProducer imageSource = image.getSource(); imageSource.startProduction(this); } /** * Gets a new width and height based on a power of 2. * @param width The original image width * @param height The original image height * @return An in array with two values. The zeroth element containing the new width and the first * element the new height. */ private int[] newImageSize(int width, int height) { int nN=1; while((width >> nN)>0) { nN++; } width = (width == (1<<(nN-1))) ? width : (1<> nN)>0) { nN++; } height = (height == (1<<(nN-1))) ? height : (1<> 8); imageBuffer[dstIndex*4 + 2] = (byte)((color & 0x00ff0000) >> 16); imageBuffer[dstIndex*4 + 3] = (byte) 0xff; dstIndex++; } srcRowIndex += scansize; dstRowIndex += imageWidth; } } public synchronized final void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pixels, int off, int scansize) { // ignore this version } public synchronized final void setHints(int hintflags) {} public synchronized final void setColorModel(ColorModel model) {} public synchronized final void setProperties(Hashtable props) {} /** * The main() method is called when the Java Virtual Machine starts up. It * just creates and displays an instance of the application. */ public static void main(String args[]) { JOGLTexture app = new JOGLTexture(); app.pack(); app.setSize(300, 300); app.setVisible(true); } }