FPS style HUD and gun rendering.

Started by
9 comments, last by V-man 17 years, 11 months ago
How does one keep a player's gun and the heads-up display (like health and ammo counts) from clipping into other 3D objects? I think I could solve the gun problem by simply adjusting the bounding box a little. Say I want to draw a crosshair with GL_LINES, though. Is there a way I can keep it from clipping into walls and the ground when I look around?
Advertisement
Just draw it last I guess, if you draw it last, then it's going to be drawn over anything else that you've already drawn.
I just ran across a similar thread where zedzeek suggested using glOrtho for orthographic perspective. I thought I might be able to use orthographic.. I just didn't know how! :) I'll try it out.
You should definately be using orthographic projection for the HUD.
Also you can do glDisable(GL_DEPTH_TEST) before drawing the hud to make sure it doesn't get clipped by anyting.

The gun will look weird if you render it with orthographic projection. So, either you need to have your collision detection keep the gun from sticking through stuff, or you can clear the depth buffer before drawing the gun, so that none of it is clipped.
Draw the HUD using ortho projection. The gun should be rendered using normal perspective projection. To avoid penetrating objects by the gun just clear the depth buffer before drawing it (clearing the depth buffer is very fast).
if (time() == $) { $ = 0; }
You don't need to clear the depth buffer, just disable depth testing as echohead said.
Quote:Original post by Boder
You don't need to clear the depth buffer, just disable depth testing as echohead said.


No, disabling the depth buffer will simply lead to all the polygons of the gun model drawn in the order they are parsed and throughly wrong. You want to keep the depth buffer enabled but ensure it is cleared first before drawing the weapon model so it is not affected by the world that was rendered previously.

And only use orthographic for your hud, your model will be best drawn with a perspective projection.

Hmm. I guess the only way you could disable depth testing is if you sorted the polygons from the gun yourself or if you had a 2D bitmap that you used as the gun.
Quote:Original post by Boder
Hmm. I guess the only way you could disable depth testing is if you sorted the polygons from the gun yourself or if you had a 2D bitmap that you used as the gun.


Yes, and why would you want to do that when you can clear the depth buffer?
Clearing the depth buffer is very fast nowdays. You can safely use it.
if (time() == $) { $ = 0; }

This topic is closed to new replies.

Advertisement