Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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 3407 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 Member


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 Member





« 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 Member


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




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.

Archimedes
Guest
« Reply #8 - Posted 2003-07-15 07:50:09 »

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...
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #9 - Posted 2003-07-15 13:30:48 »

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.


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

Senior Newbie




I'm a Java Bean


« Reply #10 - Posted 2003-07-17 06:29:35 »

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?
Offline TheBohemian

Junior Member




Java will rule them all!


« Reply #11 - Posted 2003-07-17 22:20:43 »

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

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?

cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #12 - Posted 2003-07-17 23:40:07 »

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

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (23 views)
2014-08-19 09:29:53

Tekkerue (22 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (57 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (29 views)
2014-08-08 02:01:56

Norakomi (36 views)
2014-08-06 19:49:38

BurntPizza (66 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!