Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Init  (Read 3538 times)
0 Members and 1 Guest are viewing this topic.
Offline dotandcross

Senior Newbie




I'm a Java Bean


« Posted 2003-07-11 07:21:47 »

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

// 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);
       
     }

}
Offline aldacron

Senior Devvie


Medals: 9
Exp: 16 years


Java games rock!


« Reply #1 - Posted 2003-07-11 12:10:18 »

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.
Offline dotandcross

Senior Newbie




I'm a Java Bean


« Reply #2 - Posted 2003-07-11 13:21:20 »

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)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline AndersDahlberg

Junior Devvie





« Reply #3 - Posted 2003-07-11 13:58:19 »

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...
Offline dotandcross

Senior Newbie




I'm a Java Bean


« Reply #4 - Posted 2003-07-11 14:16:53 »

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"
Offline cfmdobbie

Senior Devvie


Medals: 1


Who, me?


« Reply #5 - Posted 2003-07-13 22:42:08 »

Quote
Anyway, I got a Application error next:

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


...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" Grin

Hellomynameis Charlie Dobbie.
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #6 - Posted 2003-07-14 09:21:23 »

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.
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #7 - Posted 2003-07-14 10:40:52 »

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.


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.

8: Undefined index: online
File: /home/jgo/public_html/Themes/default/Display.template.php (main sub template - eval?)
Line: 161