• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 435
  • Last Modified:

GUI - Terrain Clipping Problem

Hello everyone.

I am creating an FPS game with a GUI like DOOM. At the bottom of the screen I draw a "bar" which displays information about the player (health, armor etc), and above the bar I draw the rest of the action (terrain, enemies, the world...). My problem is that when the player moves in the world, the terrain is drawn over the GUI. The GUI (the player info bar) is actually a series of planes with a texture and text that shows player info. How can i prevent the terrain (and everything else in the world) from drawing like that? I want all the action above the gui not on it.

Thank you
0
akiskal
Asked:
akiskal
  • 2
  • 2
1 Solution
 
davebytesCommented:
First, you can set the viewport or clipping to the rectangle above the bar.  If you don't clip, you're overdrawing into the GUI region, which is wasteful processing.

Second, you can draw the GUI >last<, and disable z-testing for all the GUI elements (just make sure you draw in back-to-front order).  That's the easier solution, but can be combined with the first if you want.  But alone, it'll solve your issues.

-d
0
 
akiskalAuthor Commented:
Thx!! Disabling z-buffering worked! But I'd like to do something about your first tip. The problem is that I don't know how to set the viewport to the rectangle above the bar. I'm just a little confused! Could you tell me something about that? Thx again for answering!!!
0
 
davebytesCommented:
before rendering the 3d scene:
glViewport(0, guiHeight, windowWidth, windowHeight-guiHeight);

before rendering the gui, you could then (for safety) do:
glViewport(0, 0, windowWidth, guiHeight);

or just:
glViewport(0, 0, windowWidth, windowHeight)
...if you want to be able to overdraw the entire screen, say for alpha hud elements, debugging text, etc...)

Alternately, you can leave the glViewport as the entire screen, and instead use glScissor (which is generally supported on all modern hardware).  It takes the exact same parameters as glViewport above.  Also, I believe glViewport might affect the modelview (since the height has been shortened, the transformation changes) -- been a while since I coded that up in GL. ;)

-d
0
 
akiskalAuthor Commented:
OK! glScissor worked fine! Thank you very much - excellent answers!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now