Re: [sdljava-users] Usage example for glGetDoublev
Status: Beta
Brought to you by:
ivan_ganza
|
From: Gregor <Gre...@gm...> - 2005-09-10 11:39:13
|
Hi, Ivan!
Thanks for your help. Indeed, ByteBuffer.allocateDirect() is the right=20
solution and it seems to work now. I cannot tell for sure yet as the=20
gtk-based input handling is still not working properly and I therefore can'=
t=20
navigate the 3D view.
However, I feel that relyinig on java.nio.ByteBuffer and derivates is a bit=
=20
strange, especially given their somewhat peculiar design. Looking at the co=
de=20
I have now which has to copy data to newly created buffers every time I nee=
d=20
to pass an array to OpenGL, I get the feeling that this slower than dealing=
=20
directly with arrays, which are readiy available in my case and probably mo=
re=20
optimizeable by the Java compiler and JVM.
What was the reason for using these buffers instead of arrays? Am I missing=
=20
something here?
Regards,
Gregor
On Saturday 10 September 2005 01:37, Ivan Z. Ganza wrote:
> 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
> >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=3DDoubleBuffer.allocate(16);
> > modelViewMatrix=3Dnew Matrix4();
> > projectionMatrix=3Dnew Matrix4();
> >
> > 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();
> > }
> >
> > }
> > }
> >
> > // snip: unrelated code
> > }
> >
> > protected void setupViewingAreaInitial()
> > {
> > viewFieldOfView=3D45.0;
> >
> > glBegin();
> > GlewJNI.SWIG_glew_init();
> > gl=3Dnew GlewImpl();
> > int width =3D getWidth();
> > int height =3D getHeight();
> > gl.glViewport(0, 0, width, height);
> > gl.glMatrixMode(GL.GL_PROJECTION); // select the projection
> >matrix
> > gl.glLoadIdentity(); // reset the
> >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);
> >
> > 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=20
> > 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(ViewWindowSpa=
ce
> >.java:322) at
> >ml.ui.plugins.view.ViewWindowSpace$2.lifeCycleEvent(ViewWindowSpace.java=
:2
> >77) 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
> >
> >
> >-------------------------------------------------------
> >SF.Net email is Sponsored by the Better Software Conference & EXPO
> >September 19-22, 2005 * San Francisco, CA * Development Lifecycle
> > Practices Agile & Plan-Driven Development * Managing Projects & Teams *
> > Testing & QA Security * Process Improvement & Measurement *
> > http://www.sqe.com/bsce5sf
> > _______________________________________________
> >sdljava-users mailing list
> >sdl...@li...
> >https://lists.sourceforge.net/lists/listinfo/sdljava-users
>
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practic=
es
> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> _______________________________________________
> sdljava-users mailing list
> sdl...@li...
> https://lists.sourceforge.net/lists/listinfo/sdljava-users
|