PDA

View Full Version : Text drawing



t3jem
06-07-2005, 09:03 PM
Hi,

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?

bansheeogl
06-07-2005, 10:20 PM
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!!!??

T101
06-08-2005, 12:10 AM
Easy:

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

t3jem
06-08-2005, 08:28 AM
So it would look like this?

gluPerspective...
drawscene()
gluOrtho...
drawhealth()
glutSwapBuffers();

Is this correct?

T101
06-08-2005, 08:43 AM
Yup. And with something like:

gluOrtho2D(0,width-1,0,height-1)

you can specify screen coordinates

t3jem
06-08-2005, 08:49 AM
I like the idea, but wouldn't this slow down my program a bit.

T101
06-08-2005, 11:15 PM
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

gluOrtho2D(0,width-1,height-1,0);if you want the origin in the topleft corner.

t3jem
06-09-2005, 12:10 AM
OK thanks,

I understand the Orthographic view it was changing from the two that confused me.

Trahern
06-09-2005, 12:04 PM
Originally posted by T101:
Yup. And with something like:

gluOrtho2D(0,width-1,0,height-1)

you can specify screen coordinatesWhy 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.

T101
06-09-2005, 09:49 PM
Actually, I don't disagree with that.