Results 1 to 5 of 5

Thread: Frustum culling in Terrain rendering

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    3

    Frustum culling in Terrain rendering

    Hi!

    Two friends and myself are working on a project, simulating terrain in 3D with possibilities of 'flying' around in the terrain.

    I am trying to implement frustum culling into our engine, but I am having some problems with getting my hands on the Modelview- and Projection matrix.

    Code :
    // Get The Current PROJECTION Matrix From OpenGL
       glGetFloatv( GL_PROJECTION_MATRIX, proj );
     
    // Get The Current MODELVIEW Matrix From OpenGL
       glGetFloatv( GL_MODELVIEW_MATRIX, modl );

    As far as I have heard, "glGetFloatv" haven't been implemented yet. Though, I have found a 'work-around', using "MatrixStack.java" and "MatrixTrackingGL" to get a hand on the modelview- and projectionmatrix, but I still don't get it to work properly. It seems everytime i call 'extractFrustum()' the view seems to change drastically. It looks like it moves "into" the terrain, as the whole screen turns green/brown/blue depending where in the terrain I am looking. It looks like it happens when i use the following calls:

    Code :
    /* Get the current PROJECTION matrix from OpenGL */   
    	    getMatrix(gl, GL10.GL_MODELVIEW, modl);
     
    	   /* Get the current MODELVIEW matrix from OpenGL */
    	    getMatrix(gl, GL10.GL_PROJECTION, proj);

    This method looks like this:

    Code :
    private void getMatrix(GL10 gl, int mode, float[] mat) {
            MatrixTrackingGL gl2 = (MatrixTrackingGL) gl;
            gl2.glMatrixMode(mode);
            gl2.getMatrix(mat, 0);      
        }

    I would really appreciate some help with this.
    Many thanks in advance.

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: Frustum culling in Terrain rendering

    I suppose you are talking about OpenGL ES on Android? Please always mention the platform you are using.

    It appears that the getMatrix method sets the GL matrix mode, but does not reset it to the previous state after obtaining the matrix. Thus subsequent matrix updates in GL might affect the wrong GL matrix stack.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    3

    Re: Frustum culling in Terrain rendering

    Yes, OpenGL ES on Android. Sorry for not mentioning that.

    I have noticed that, yes. That the method sets the matrix mode, but if that's the problem, how can I fix it?
    Can i simply just call gl.glLoadIdentity() ?

  4. #4
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: Frustum culling in Terrain rendering

    You need to save the current matrix mode in a local variable, then restore it at the end.

    Code :
    private void getMatrix(GL10 gl, int mode, float[] mat) {
            MatrixTrackingGL gl2 = (MatrixTrackingGL) gl;
            IntBuffer matrixMode = IntBuffer.allocate(1);
            gl2.glGetIntegerv(GL11.GL_MATRIX_MODE, matrixMode);
            gl2.glMatrixMode(mode);
            gl2.getMatrix(mat, 0);     
            gl2.glMatrixMode(matrixMode.get(0));
        }
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  5. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    3

    Re: Frustum culling in Terrain rendering

    Thanks. I will try it tomorrow when we're back at work. Although, we got to test on the new HTC Desire today, and the calls I didn't think were implemented actually worked, so I got that part working after all. We have tested on a HTC Magic till now, so I guess Desire fully supports OpenGL ES 1.1.

    But thanks for fast replies, I'm sure that way would have done the job as well.

    I will come back to you if I meet further problems

Similar Threads

  1. GPU terrain rendering
    By miroslav_karpis in forum Developers Coding:Beginner
    Replies: 3
    Last Post: 06-11-2010, 12:32 AM
  2. BackFace Culling on Vincent
    By cobrahc in forum OpenGL ES general technical discussions
    Replies: 6
    Last Post: 03-18-2008, 09:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •