views:

199

answers:

3

The function gluPerspective() can be used to set near Z and far Z clipping planes.

I want to draw a scene clipped at a certain far Z plane, and draw another scene beyond this Z plane. Is it possible to do this clipping twice per frame?

+1  A: 

There's no reason you shouldn't be able to do this.

Simply setup the first perspective, draw the first scene and then setup the second perspective and draw the seconds scene, all within the drawing of the same frame.
This is generally referred to as multi-pass rendering.

shoosh
+1  A: 

You might need to do a draw the farthest scene first and do a glClear(GL_DEPTH_BUFFER_BIT); before you draw the nearest scene.

epatel
+1  A: 

A possibility is to assign different depth ranges for the scenes. Some pseudo code would be :

  glDepthRange(0.5, 1.0)
  draw_far_scene
  glDepthRange(0.0, 0.5)
  draw_near_scene

You have to setup your projection matrices to perform the proper clipping for the near / far scenes.

The depth ranges assignment is needed to prevent the depth buffer to 'merge' both renderings.

rotoglup