I have first person program where you can run around a level and stuff. My problem is that I want to post health on the screen though the only way I can think of is to trace where I am looking at and do about 50 lines of code which I do not plan on doing any time soon. Do you have any suggestions?
you should display a textured quad displaying the health in the way you like more like for example a health bar, you will need 2 though one red and another green (just in example) so you will place them on top of everything close to the screen and render before anything else (theoricaly) then you will make the red bar bigger (on the X axis if your health bar is horizontal) based on th health of the player.
i dont know if that would work but it should
can someone tell me how to render something like this ? because if i place a quad very close to the frustum the rendering goes very slow! why is this!!!??
Step 1: render the 3D environment using perspective projection
Step 2: render the 2D overlays, ignoring the depth-buffer, using an Ortho projection. (This is where you also render your text)
Step 3: swap buffers
So it would look like this?
Is this correct?
Yup. And with something like:
you can specify screen coordinates
I like the idea, but wouldn’t this slow down my program a bit.
Well, you’re introducing one set of state changes so part of the pipeline may need to flush, but I think it still beats transforming every 2D coordinate to 3D coordinates on the CPU.
And you don’t have to worry about 3D stuff poking through your overlays.
One correction though:
It should be
if you want the origin in the topleft corner.
I understand the Orthographic view it was changing from the two that confused me.
Originally posted by T101:
[b]Yup. And with something like:
you can specify screen coordinates[/b]
Why do you use width-1 and height-1 ?
I always use simple left+width , top+height and everything works as it should.
Even in the Red Book is written:
If exact two-dimensional rasterization is desired, you must carefully specify both the orthographic
projection and the vertices of primitives that are to be rasterized. The orthographic projection
should be specified with integer coordinates, as shown in the following example:
gluOrtho2D(0, width, 0, height);
where width and height are the dimensions of the viewport.
Actually, I don’t disagree with that.