GUI - Terrain Clipping Problem

Posted on 2005-04-09
Last Modified: 2013-12-06
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
Question by:akiskal
    LVL 17

    Expert Comment

    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.


    Author Comment

    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!!!
    LVL 17

    Accepted Solution

    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. ;)


    Author Comment

    OK! glScissor worked fine! Thank you very much - excellent answers!

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    USB HID read speed 3 581
    old35  java challenge 4 99
    teenSum java challenge 7 70
    3D rotation changing an axis 4 65
    Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
    As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now