Bug 14 - Incorrect rendering when calling glOrtho() outside of GLDrawable.reshape()
Summary: Incorrect rendering when calling glOrtho() outside of GLDrawable.reshape()
Status: VERIFIED INVALID
Alias: None
Product: Jogl
Classification: JogAmp
Component: core (show other bugs)
Version: 1
Hardware: All windows
: P2 normal
Assignee: Sven Gothel
URL: http://www.javagaming.org/cgi-bin/JGN...
Depends on:
Blocks:
 
Reported: 2003-06-22 10:33 CEST by Sven Gothel
Modified: 2010-03-24 07:45 CET (History)
0 users

See Also:
Type: DEFECT
SCM Refs:
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Gothel 2010-03-24 07:45:26 CET


---- Reported by ckline 2003-06-22 10:33:24 ----

Please see the attached reproduction case. When this program is compiled with 
setCameraInRepaint=true, the app renders correctly (diagonal and vertical lines, 
plus a small box at bottom left corner). When setCameraInRepaint is false, nothing 
renders.

I am unsure as to why the app does not render correctly in the second case, 
since glOrtho() is being called in display() and hence should be called after the call 
to glViewport() is made in GLCanvas.reshape(). 

I suspect some strange behavior with respect to the AWT integration and 
threading -- perhaps because GLCanvas.reshape() is called in a different thread 
from that used to call GLDrawable.reshape()?
 
--------

import java.awt.Frame; 
import java.awt.event.WindowAdapter; 
import java.awt.event.WindowEvent; 
 
import net.java.games.jogl.*; 
 
/** 
 *   Vectrix 
 *  
 * @author John 
 * @author Ckline modified to demostrate bug
 */ 
public class Vectrix implements GLEventListener 
{
  // BUG REPRO: app does not render correctly when setCameraInReshape is false
  private boolean setCameraInReshape = true;

  public static Vectrix app = new Vectrix(); 
  
  private Frame frame; 
  
  // private MouseHandler mouseHandler; 
  private Animator animator; 
  
 
  private GLCanvas canvas; 
 
  /** 
   *  
   */ 
  private Vectrix() 
  { 
    System.out.println("Vectrix instance created"); 
    
    // Canvas setup 
    GLCapabilities caps = new GLCapabilities(); 
    caps.setDoubleBuffered(true); 
    caps.setAlphaBits(8); 
    caps.setStencilBits(8); 
    canvas = GLDrawableFactory.getFactory().createGLCanvas(caps); 
     
    //canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities
()); 
    canvas.addGLEventListener(this); 
    canvas.setGL(new DebugGL(canvas.getGL()));
    // Frame setup 
    frame = new Frame("Vectrix"); 
    frame.add(canvas); 
    frame.setSize(800, 600); 
 
    frame.addWindowListener(
      new WindowAdapter() 
      { 
        public void windowClosing(WindowEvent e) 
        { 
          animator.stop(); 
          System.exit(0); 
        } 
      } 
      ); 
   
    // Event handlers 
    animator = new Animator(canvas); 
  } 
  
  public void initialiseDisplay() 
  { 
    frame.show(); 
  } 
  
  public void run() 
  { 
    animator.start(); 
  } 
 
  public static void main(String[] args) 
  { 
    System.out.println("Vectrix starting..."); 
   
    app = new Vectrix(); 
    app.initialiseDisplay(); 
  
    // Other loading/initialisation 
    // .. 
   
    // Start main game loop 
    app.run(); 
  } 
 
  
  // GL Event Listener methods 
  
  // Called when GL has been initialised for the first time. 
  public void init(GLDrawable canvas) 
  { 
    System.out.println("Vectrix.init(): GL init event"); 
   
    GL gl = canvas.getGL(); 
   
    gl.glMatrixMode(GL.GL_PROJECTION); 
    gl.glLoadIdentity(); 
    gl.glMatrixMode(GL.GL_TEXTURE); 
    gl.glLoadIdentity(); 
    gl.glMatrixMode(GL.GL_MODELVIEW); 
    gl.glLoadIdentity(); 
    
  } 
 
  public void display(GLDrawable canvas) 
  {
    //System.err.println("DISPLAY THREAD: " + Thread.currentThread());
    GL gl = canvas.getGL(); 
    GLU glu = canvas.getGLU(); 
   
    gl.glClearColor(0.2f, 0.2f, 0.2f, 0.0f); 
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | 
GL.GL_STENCIL_BUFFER_BIT); 
  
    if (!setCameraInReshape)
    {
      //   l/r  b/t  near/far 
      gl.glMatrixMode(GL.GL_PROJECTION); 
      gl.glOrtho(0, 4, 0, 3, -8, 8); 
      gl.glMatrixMode(GL.GL_MODELVIEW); 
    }
  
    gl.glPushMatrix(); 
    {
      // draw a polygon 
      gl.glBegin(GL.GL_POLYGON); 
      gl.glColor3f(1f, 0f, 0f); 
      gl.glVertex3f(.25f, .25f, 0f); 
      gl.glVertex3f(.75f, .25f, 0f); 
      gl.glVertex3f(.75f, .75f, 0f); 
      gl.glVertex3f(.25f, .75f, 0f); 
      gl.glEnd();   

      // draw some lines
      gl.glBegin(GL.GL_LINES); 
      { 
        int xMin = 0; 
        int xMax = 10; 
        gl.glColor3f(1f, 0f, 0f); 
     
        for (int x=xMin; x<=xMax; x++) 
        { 
          gl.glVertex3f(x, -1, 0f); 
          gl.glVertex3f(x, +1, 0f); 
  
        } 
     
        gl.glVertex3f(0f, 0f, 0f); 
        gl.glVertex3f(4f, 4f, 4f); 
     
      } 
      gl.glEnd();
      
    } 
    gl.glPopMatrix(); 
   
  } 
 
 
  public void reshape(GLDrawable arg0, int arg1, int arg2, int arg3, int arg4) 
  {
    //System.err.println("RESHAPE THREAD: " + Thread.currentThread());
    GL gl = arg0.getGL();

    System.out.println("Vectrix.init(): GL reshape event " + arg1 + " " + arg2
                       + " " + arg3 + " " + arg4); 

    if (setCameraInReshape)
    {
      //   l/r  b/t  near/far 
      gl.glMatrixMode(GL.GL_PROJECTION); 
      gl.glOrtho(0, 4, 0, 3, -8, 8); 
    }

  } 
 
  public void displayChanged(GLDrawable arg0, boolean arg1, boolean arg2) 
  { 
 
  } 
}



---- Additional Comments From ckline 2003-06-22 10:34:13 ----

This bug was initiated from the discussion at

http://www.javagaming.org/cgi-bin/JGNetForums/YaBB.cgi?
board=jogl;action=display;num=1056274375



---- Additional Comments From ckline 2003-06-22 13:50:39 ----

After some experimentation, I now believe this is not a bug. If you change all the 
calls around glOrtho() to look like this:

gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.glOrtho(...)
gl.glMatrixMode(gl.GL_MODELVIEW)

the app works correctly regardless of the value of setCameraInReshape. Unless 
further issues crop up, I would like to declare this not-a-bug.




--- Bug imported by sgothel@jausoft.com 2010-03-24 07:45 EDT  ---

This bug was previously known as _bug_ 14 at https://jogl.dev.java.net/bugs/show_bug.cgi?id=14

The original assignee of this bug does not have
   an account here. Reassigning to the default assignee
   for the component, sgothel@jausoft.com.
   Previous assignee was kbr.
CC member ckline does not have an account here