LWJGL Forum

Programming => OpenGL => Topic started by: emzic on March 22, 2009, 15:46:01

Title: getting basic opengl in jframe / frame to work.
Post by: emzic on March 22, 2009, 15:46:01
hello, i tried to get an opengl rendering in a window which i can also resize, but all i get is an opengl-canvas that is way larger than the window and the window is kinda frozen.

here is what i tried:

try {
JFrame f = new JFrame("Test");
f.setSize(400, 400);
f.setVisible(true);
Display.create() ;
AWTGLCanvas c = new AWTGLCanvas();
f.add(c);
Display.setParent( c );
Display.releaseContext();
} catch (LWJGLException e) {
e.printStackTrace();
}


then in a new thread i render my scene like this:

try {
Display.makeCurrent();
while(true) {
render();
Thread.yield();
Display.update();
}
} catch (LWJGLException e) {
e.printStackTrace();
}


but as i said, the display's size is not the same as the frame's size and the frame does not respond. what am i doing wrong here?

thanks for any help!
Title: Re: getting basic opengl in jframe / frame to work.
Post by: kappa on March 22, 2009, 17:00:55
firstly you don't use Display.setParent() and AWTGLCanvas together, you used either one. Secondly just curious is it a requirement that you use JFrame?

I would recommend just using the pure Display class with no JFrame, its much faster and more either to get up and running.
Title: Re: getting basic opengl in jframe / frame to work.
Post by: emzic on March 22, 2009, 17:21:07
thanks for your help!

but still if i user either setParent or the frame.add the frame does not respond.

and yes, i would very much like to use a jframe or awt-frame if possible, since there might be other swing/awt controls too.

i dont care so much about performance, but much more about a responsive window. ;)

thanks!
Title: Re: getting basic opengl in jframe / frame to work.
Post by: kappa on March 22, 2009, 18:02:58
well if you must use awt, then i'd say go with Display.setParent() an example on how to use it can be found in the the tests included in the lwjgl source or in the online svn at http://java-game-lib.svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/DisplayParentTest.java?view=markup

Also if you can avoid awt it'd be better to use just pure Display and use an OpenGL GUI for controls such as the TWL Gui library found at http://twl.l33tlabs.org/ it'd be much more responsive than using a mix of awt and opengl.