Frustum view culling in opengl

To learn 3d programming and the opengl api i have made a terraindemo which generates a terrain model with triangles.
All works fine but i need to do some optimizations because i fill the renderpipeline with all of the tousends of triangles per frame but only a few of them are seen. How to do a frustum view culling in opengl when i am in modelmatrix mode?


glTranslatef( - position[0],- position[1],-position[2] );
glRotatef(rot[0], 1.0f, 0.0f, 0.0f); //roll
glRotatef(rot[1], 0.0f, 1.0f, 0.0f); //pitch
glRotatef(rot[2], 0.0f, 0.0f, 1.0f); //heading

here i have a terrain model with tousends of triangles.
how do i determine which triangles are visible?
how to set up the frustum planes and do a visibility test with the triangle vertices?

hope for any usefull hints.

Frustum culling is done automatically by OpenGL, and it’s done wether you want it to or not (even though I see no reason to turn it off ). All you need to do is setup the projection matrix, which I can see you do, and when passing primitives to OpenGL that is outside this frustum, they aren’t processed any further, since there is no way you can see them. You can also let OpenGL perform backface culling too. But, any other kind of visibility test is up to you to code. Then I’m talking about more advanced stuff like occlusion culling.

To speed up your terrain renderer, you need some type of heirarchical culling. This is to minimize the number of triangles you even consider sending to OpenGL. For simple terrain renderers, quad-trees are fairly popular for heirarchical culling.

frustum culling is NOT implemented in OpenGL except maybe by the high end HP Visualize workstation cards…

clipping is however implemented by default and you can NOT turn it off…

culling refers to not doing calculations on geometry that is not inside the frustum clipping is cutting up you geometry so it is inside the frustum…

you need to implement a culler by youself…
I have done this by creating bounding boxes around logical groups of geometry and testing this box against the view frustum… Sorry, but I cannot post code as I do not have the rights to it (It is used in a project for work)… but if you look up view frustum in this and the advaced forum you will probably find some help


the anonymous mr x

Just a nitpick here. IIRC, there is an extension that allows you to at least request disabling of volume clipping. Implementations are free to ignore the request though.

thank you all for reply
my problem is that i dont know how to calculate the plane equationes that exactly matches the “logical” frustum position. in my above sample code i translate and rotate the world. the view frustum lies at origin and is defined by the projection matrix. But for culling the model i need a modelview position of the frustum planes. When i have an idea how to do that or a sample code to see how its made i will go on and implement a quad-tree or something other of these interesting things.