getting basic opengl in jframe / frame to work.

Started by emzic, March 22, 2009, 15:46:01

Previous topic - Next topic

emzic

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!

kappa

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.

emzic

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!

kappa

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.