[sdljava-users] Usage example for glGetDoublev
Status: Beta
Brought to you by:
ivan_ganza
From: Gregor <Gre...@gm...> - 2005-09-08 20:28:05
|
Hi! I"m trying to use glGetDoublev to read back the modelview and projection matrices from OpenGL. However, it looks like I'm doing something wrong with the DoubleBuffers required for that. What I'm doing basically is in this code: GlewImpl gl; private ml.math.Matrix4 modelViewMatrix; private ml.math.Matrix4 projectionMatrix; private double viewFieldOfView; private DoubleBuffer matrixBuffer; public ViewWindowSpace(Widget parent) { super(); matrixBuffer=DoubleBuffer.allocate(16); modelViewMatrix=new Matrix4(); projectionMatrix=new Matrix4(); currentRenderMode=RenderMode.Solid; initGLContext(); // snip: unrelated code addListener(new LifeCycleListener() { public void lifeCycleEvent(LifeCycleEvent e) { // TODO Auto-generated method stub if(e.getType()==LifeCycleEvent.Type.REALIZE) { setupViewingAreaInitial(); } } } // snip: unrelated code } protected void setupViewingAreaInitial() { viewFieldOfView=45.0; glBegin(); GlewJNI.SWIG_glew_init(); gl=new GlewImpl(); int width = getWidth(); int height = getHeight(); gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL.GL_PROJECTION); // select the projection matrix gl.glLoadIdentity(); // reset the projection matrix float fAspect = (float) width / (float) height; gl.gluPerspective(viewFieldOfView, fAspect, 0.5f, 400.0f); gl.glMatrixMode(GL.GL_MODELVIEW); // select the modelview matrix gl.glLoadIdentity(); gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX,matrixBuffer); modelViewMatrix.setFromOpenGLMatrix(matrixBuffer); gl.glGetDoublev(GL.GL_PROJECTION_MATRIX,matrixBuffer); projectionMatrix.setFromOpenGLMatrix(matrixBuffer); glEnd(); } What this does: The constructor allocates the DoubleBuffer in question and registers an event handler to do the rest of the initialilsation once the opengl context can actually be used. When this is the case, setupViewingAreaInitial is called to perform the init of the gl context. This fails with a NullPointerException in the first call to gl.glGetDoublev(). The console output for this exception is as follows: Exception in thread "main" java.lang.NullPointerException: null address returned from GetDirectBufferAddress() call. Make sure the buffer is a _direct_ buffer. at org.gljava.opengl.x.swig.GlewJNI.glGetDoublev(Native Method) at org.gljava.opengl.impl.glew.GlewImpl.glGetDoublev(GlewImpl.java:143) at ml.ui.plugins.view.ViewWindowSpace.setupViewingAreaInitial(ViewWindowSpace.java:322) at ml.ui.plugins.view.ViewWindowSpace$2.lifeCycleEvent(ViewWindowSpace.java:277) at org.gnu.gtk.Widget.fireLifeCycleEvent(Widget.java:735) at org.gnu.gtk.Widget.handleRealize(Widget.java:764) at org.gnu.gtk.Widget.gtk_widget_show(Native Method) at org.gnu.gtk.Widget.show(Widget.java:119) at ml.core.State.createMainWindow(State.java:158) at ml.ML3D.<init>(ML3D.java:49) at ml.ML3D.main(ML3D.java:66) I have no clue why this happens. Do I initialize the DoubleBuffer in question badly? Is there any example that shows how it should be done? Any help would be appreciated. Regards, Gregor |