Frustum Culling

Started by sprite, July 02, 2003, 22:08:52

Previous topic - Next topic


Hey : )

I'm trying to work on porting an OpenGL tutorial by DigiBen from dealing with frustum culling.  So in calculating the current frustum you need to extract both the Projection and Modelview matrices from the gl state... this is normally done with the following code :

  float proj[] = new float[16];		
   float modl[] = new float[16];	

   gl.getFloatv( GL.PROJECTION, proj );
   gl.getFloatv( GL.MODELVIEW, modl );
   // and then you multiply them together and perform other matrix operations

Unfortunately gl.getFloatv does not accept the correct arguments in version 0.6 of Lew-Jiggle.  The current definition for getFloatv in org.lwjgl.opengl.CoreGL is:

native public void getFloatv(int arg, int arg)

In addition, getBooleanv, getDoublev, and getIntegerv all have (int arg, int arg) as arguments.  8 days ago they made a change in the cvsrepo that supports the correct arguments (using a FloatBuffer), but it hasn't been released yet, etc.

Does anyone know how to extract the projection and modelview matrices without using the getFloatv method ?   :(


The int-argument system is the "oldstyle" LWJGL way of doing things - and is perfectly valid and does work!  If you can't wait until 0.7 is released (with the "newstyle" system), try the old system:

You may notice that any argument that in OpenGL would be a pointer to an array, in oldstyle LWJGL it's an int.  This int is doing exactly the same thing as that pointer!  It is the address of a ByteBuffer that contains the data.  E.g.:

IntBuffer ib = ByteBuffer.allocateDirect(1 * 4).order(ByteOrder.nativeOrder()).asIntBuffer() ;
int addr = Sys.getDirectBufferAddress(ib) ;
gl.getIntegerv(GL.SUBPIXEL_PRECISION_BITS, addr) ;
int result = ib.get(0) ;

You should be able to follow this scheme to get the data you want.

NB. the size of the buffer is in bytes, and as ints are 32-bit (4 bytes) the required size of the buffer is 4.
ellomynameis Charlie Dobbie.