import java.awt.*; import java.awt.event.*; import javax.media.opengl.*; import javax.swing.*; /** * Example JOGL application showing bug when drawing a line strip with flat shading * turned on. The bug occurs when using GLJPanel under the Windows Vista operating system. * The bug does not occur under Windows XP. * * Run environment: * Machine : n/a * OS : Windows Vista Business (no service pack) * Graphics : NVIDIA Geforce3 * Drivers : Microsoft Driver 6.0.6000.16386 * JVM : java 1.4.2_16 and 1.6.0_04 * JOGL : 1.1.1-rc4 and 1.1.1-rc7 * @author Alan Michael Gay, AVS Inc. */ public class LineAlignmentBug extends JFrame implements GLEventListener { public LineAlignmentBug() { // Specify the Frame window title and initial size. setTitle("Line Alignment 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(); GLJPanel canvas = new GLJPanel(capabilities); canvas.addGLEventListener(this); this.getContentPane().add(canvas); } /** * Sets the OpenGL color using the specified java.awt.Color. * @param gl The OpenGL context whose color is to be set. * @param color The color to set. */ private void setColor(GL gl, Color color) { float red = color.getRed()/255.0f; float green = color.getGreen()/255.0f; float blue = color.getBlue()/255.0f; gl.glColor3f(red, green, blue); } /** * Implementation of GLEventListener.display * Draws a triangle with a border using a line strip. */ public void display(GLAutoDrawable arg0) { GL gl = arg0.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glMatrixMode(GL.GL_MODELVIEW); // BUG // Line is drawn in the incorrect position when turning flat shading on. gl.glShadeModel(GL.GL_FLAT); // // Triangles // setColor(gl, Color.GREEN); gl.glBegin(GL.GL_TRIANGLES); gl.glVertex3f(-0.5f, 0.5f, 0.0f); gl.glVertex3f(0.5f, 0.5f, 0.0f); gl.glVertex3f(0.5f, -0.5f, 0.0f); gl.glEnd(); /// // Line strip // setColor(gl, Color.RED); gl.glBegin(GL.GL_LINE_STRIP); gl.glVertex3f(-0.5f, 0.5f, 0.0f); gl.glVertex3f(0.5f, 0.5f, 0.0f); gl.glVertex3f(0.5f, -0.5f, 0.0f); gl.glVertex3f(-0.5f, 0.5f, 0.0f); gl.glEnd(); } public void init(GLAutoDrawable arg0) { } public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { } public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) { } /** * 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[]) { LineAlignmentBug app = new LineAlignmentBug(); app.pack(); app.setSize(300, 300); app.setVisible(true); } }