Re: [sdljava-users] Usage example for glGetDoublev
Status: Beta
Brought to you by:
ivan_ganza
|
From: Ivan Z. G. <iva...@ya...> - 2005-09-09 23:38:13
|
Gregor,
I had a look in the code and intact SDLSurface isn't a good example
because the buffer is created in the native code. Have a look at
ByteBufferPool instead.
-Ivan/
Gregor M=FCckl wrote:
>Hi!
>
>I"m trying to use glGetDoublev to read back the modelview and projection=
=20
>matrices from OpenGL. However, it looks like I'm doing something wrong w=
ith=20
>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)=20
> {
> super();
>
> matrixBuffer=3DDoubleBuffer.allocate(16);
> modelViewMatrix=3Dnew Matrix4();
> projectionMatrix=3Dnew Matrix4();
> =09
> currentRenderMode=3DRenderMode.Solid;
>
> initGLContext();
>
> // snip: unrelated code
>
> addListener(new LifeCycleListener() {
>
> public void lifeCycleEvent(LifeCycleEvent e)
> {
> // TODO Auto-generated method stub
> if(e.getType()=3D=3DLifeCycleEvent.Type.REALIZE) {
> setupViewingAreaInitial();
> }
> =20
> }
> }
>
> // snip: unrelated code
> }
>
> protected void setupViewingAreaInitial()=20
> {
> viewFieldOfView=3D45.0;
> =20
> glBegin();
> GlewJNI.SWIG_glew_init();
> gl=3Dnew GlewImpl();
> int width =3D getWidth();
> int height =3D getHeight();
> gl.glViewport(0, 0, width, height); =20
> gl.glMatrixMode(GL.GL_PROJECTION); // select the projection=
=20
>matrix
> gl.glLoadIdentity(); // reset the=20
>projection matrix
> float fAspect =3D (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);
> =20
> glEnd();
> }
>
>What this does:
>
>The constructor allocates the DoubleBuffer in question and registers an =
event=20
>handler to do the rest of the initialilsation once the opengl context ca=
n=20
>actually be used. When this is the case, setupViewingAreaInitial is call=
ed to=20
>perform the init of the gl context. This fails with a NullPointerExcepti=
on in
>the first call to gl.glGetDoublev(). The console output for this except=
ion is=20
>as follows:
>
>Exception in thread "main" java.lang.NullPointerException: null address=20
>returned from GetDirectBufferAddress() call. Make sure the buffer is a=20
>_direct_ buffer.
> at org.gljava.opengl.x.swig.GlewJNI.glGetDoublev(Native Method)
> at org.gljava.opengl.impl.glew.GlewImpl.glGetDoublev(GlewImpl.java:143)
> at=20
>ml.ui.plugins.view.ViewWindowSpace.setupViewingAreaInitial(ViewWindowSpa=
ce.java:322)
> at=20
>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 que=
stion=20
>badly? Is there any example that shows how it should be done? Any help w=
ould=20
>be appreciated.
>
>Regards,
>Gregor
>
>
>-------------------------------------------------------
>SF.Net email is Sponsored by the Better Software Conference & EXPO
>September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practi=
ces
>Agile & Plan-Driven Development * Managing Projects & Teams * Testing & =
QA
>Security * Process Improvement & Measurement * http://www.sqe.com/bsce5s=
f
>_______________________________________________
>sdljava-users mailing list
>sdl...@li...
>https://lists.sourceforge.net/lists/listinfo/sdljava-users
> =20
>
|