Init

There seems to be an error somewhere in the code but I am not sure where. Anyone can take a look? Thanks :slight_smile:

// test.java

// Import classes from some necessary places
import java.awt.;
import java.awt.event.
;
import javax.swing.;
import javax.swing.event.
;

import net.java.games.jogl.*;

public class test extends JFrame implements WindowListener,
GLEventListener
{
// enables gl and glu calls
GL gl;
GLU glu;

     // The OpenGL component to render onto
     public GLCanvas glc = null;

     // set up GUI (constructor)
public test()
{       
      super( "Canvas" );
  
        // Set the layout of the frame
        final Container c = getContentPane(); 
        c.setLayout(new BorderLayout());
        
        // create and set capabilities
        GLCapabilities cap = new GLCapabilities();
        cap.setDoubleBuffered(true);
        cap.setDepthBits(12);
        cap.setRedBits(24);
        cap.setGreenBits(24);
        cap.setBlueBits(24);
        cap.setAlphaBits(24);
        
        // create canvas component
        glc = GLDrawableFactory.getFactory().createGLCanvas(cap);
        glc.setSize(300,300);
        
        // Add the Component into the window 
         c.add( "Center", glc );
         pack(); show();
         glc.requestFocus();
        
        // Add Windows Listener to the component
        this.addWindowListener( this );
    
        //Add GLEventListener to handle GL events
        glc.addGLEventListener(this);
                
  }
  
  public void init(GLDrawable drawable)
  {
        gl = drawable.getGL();
        glu = drawable.getGLU();
                    
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glShadeModel(GL.GL_SMOOTH);
        gl.glEnable(GL.GL_DEPTH_TEST);

  }
  
  public void display(GLDrawable drawable)
  {
        // clear colour and depth buffer
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    
        // Set drawing colour to white
        gl.glColor3f(1.0f,1.0f,1.0f);
        
        // Draw a rectangle
        gl.glBegin(GL.GL_POLYGON);
              gl.glVertex3f(0.25f,0.25f,0.0f);
              gl.glVertex3f(0.75f,0.25f,0.0f);
              gl.glVertex3f(0.75f,0.75f,0.0f);
              gl.glVertex3f(0.25f,0.75f,0.0f);
        gl.glEnd();
    
}

public void reshape(GLDrawable drawable, int x, int y, int width, int height)
{
        gl.glViewport (0, 0, width, height);
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
        gl.glMatrixMode(GL.GL_MODELVIEW);
}

public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
  
// WindowListener methods
public void windowActivated( WindowEvent evt ) {}
public void windowClosed( WindowEvent evt ) {}

public void windowClosing( WindowEvent evt )
{
      System.exit( 0 );
}

public void windowDeactivated( WindowEvent evt ) {}
public void windowDeiconified( WindowEvent evt ) {}
public void windowIconified( WindowEvent evt ) {}
public void windowOpened( WindowEvent evt ) {}

  
  public static void main( String args[] )
  {
         // Set the look and feel of application
        try
        {
              UIManager.setLookAndFeel(
             UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e){}
      
      test application = new test();
      application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
  }

}

Pretty funky stuff you’re doing there with the GLCapabilities - asking for a 96-bit RGBA mode and a 12-bit depth buffer. If you want RGBA mode - replace those 24s with 8s, and use 16 (or 24) for the the depth bits. BUt aside from that, what sort of error are you getting? Throwing out that much code and saying ‘What’s wrong?’ doesn’t give anyone enough info to go on.

I am using java sdk 1.4.1_02-b06 (comes with JBuilder)

The Gears demo works fine…

The real problem arises when i try to resize the window after running it.

java.lang.NullPointerException
at test.display(test.java:70)
at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.java:74)
at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:191)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:186)
at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:179)
at net.java.games.jogl.GLCanvas.display(GLCanvas.java:84)
at net.java.games.jogl.GLCanvas.paint(GLCanvas.java:95)
at sun.awt.RepaintArea.paint(RepaintArea.java:177)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
at java.awt.Component.dispatchEventImpl(Component.java:3699)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

Hmm, gl is null which implies that the init method of your test class isn’t called. try to move that glc.addGlEventListenerThingy to above where you make the frame visible - not sure if this is the problem though…

Gee… you are right, it works like a charm… :wink:
But it worked fine with GL4Java… weird…

Anyway, I got a Application error next:

The instruction at “0x69571cb9” referenced memory at “0x00000020”. The memory cannot be “read”

[quote]Anyway, I got a Application error next:

The instruction at “0x69571cb9” referenced memory at “0x00000020”. The memory cannot be “read”
[/quote]
…And that sounds like a bug! Looks to me like something somewhere tried to use a dodgy pointer. Anyone from the JoGL team got a firm answer?

Love that message though - The memory cannot be “read” ;D

I haven’t had time to look into this particular example yet but it is certainly possible to crash the VM with incorrect OpenGL code. There are several demos in the jogl-demos project and hopefully they can be of some help. It’s also possible there is a bug with Jogl’s internal OpenGL context handling in particular when integrating with the JFrame class; there is already an open bug about this. Please try integrating your GLCanvas into an AWT Frame instead of a JFrame and if that works then let us know so that we have another known instance of that bug.

[quote]It’s also possible there is a bug with Jogl’s internal OpenGL context handling in particular when integrating with the JFrame class; there is already an open bug about this.
[/quote]
Do you have an issue number so we can track this? I looked in Issuezilla but it wasn’t immediately obvious which issue you are referring to.

** I also just noticed that as an observer I am unable to edit issues in any way… so I can’t add myself to the CC: list if there is an issue that is important to me. Could we get that changed? It’s also unclear how to use votes - maybe I can’t, but it says I have 10 votes to use.

Interesting topic!
I also get an unusual Java stack trace when I hit the ALT key. It could be similar to the original poster’s problem…

My Jogl’s GlCanvas resides in an AWT Frame, with some Swing components (JButtons and JLabels) sitting next to the GlCanvas. Is this a problem? (I read SUN’s document about mixing AWT and SWING components.)

I’ve registered an KeyListener, MouseListenerand and MouseMotionListener to that ClCanvas. I issue a glKanvas.setFocusable(true) and a glKanvas.requestFocus() so that just this glCanvas gets the keys (not the swing components).

The JVM is 1.4.2_X. Whenever I hit the ALT key the following happens (all other keys, mouse etc. work fine) :

java.lang.NullPointerException
at javax.swing.SwingUtilities.getWindowAncestor(Unknown Source)
at com.sun.java.swing.plaf.windows.WindowsRootPaneUI$AltProcessor.postProcessKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Unforunately I don’t have the slightest idea what this could mean…

I had thought there was a bug about the Frame/JFrame issue but went through the issue list last night and you’re right, there doesn’t appear to be anything there. However I also wrote a test yesterday of this and there doesn’t seem to be a problem with at least this.

To the posters: please feel free to file issues so we can try to track down what is happening. Note that the JOGL demos (http://jogl-demos.dev.java.net/) use key, mouse, and mouse motion listeners in combination with the Alt key and this works fine, so I suspect the second bug mentioned above is an application error.

Please email djp@dev.java.net about the changes you’d like to see to IssueZilla.

I tried the same program using the same compiler and same sdk on a different machine with a more powerful video card with 32mb memory and OpenGL 1.4, the error miraculously dissapeared.

The earlier machine had a savage Mx video card with 8mb memory and OpenGL 1.1

Does this have anithing to do with hardware acceleration?

Its a matter of fact that jogl cannot be better than your opengl gfx drivers (except of the nvidia bug the glcanvas circumvents :slight_smile: ).

maybe the newer card’s driver is more stable.

has anyone noticed that dotandcross is using the glcanvas inside of a jframe? is this a possible/stable combination?

It will work, but GLJPanel is the more appropriate component for doing work within a Swing context.