howto hud? very nub, I think...

Started by
6 comments, last by GhostTask 22 years, 3 months ago
I''m currently writing on a Head Up Display like display laid over my 3D scene. Unfortunately I''m experiencing various Problems: 1.) The text I display is affected by lighting. I use Nehe''s Bitmap-Font code to generate the Output, and I position the Lights directly in front of the text, but it doesnt get "enlighted". 2.) How can I render to normal Screen coordinates? I tried glOrtho but.... I think I am too stupid to use it or whatever. 3.) somehow the same as 1.) : how can I render Parts of the scene without lighting effects. I tried to gldisable and glenable Lighting, but that doesn''t work for parts of the scene. So can anyone give me hints or a resource on howto code a hud, and give me some enlightenment about light? Thanks in advance for any help, GT waiting for a live after death
waiting for a life after death
Advertisement
1/ Do you have set materials before rendering the fonts ?

2/
  glViewport( 0, winWidth, 0, winHeight);glMatrixMode( GL_PROJECTION);glLoadIdentity();gluOrtho2D( 0, winWidth, 0, winHeight);glMatrixMode( GL_MODELVIEW);   


3/ Weird, it should work. Could you tell us what the problem is more precisely ? Do you do disable lighting with :
glDisable( GL_LIGHTING); // good
or
glDisable( GL_LIGHT0); // bad, with no light, objects will be black
glDisable( GL_LIGHT1);
... ?
To use 2d coordinates just reset your matrix. Then (0,0,0) will be in the center of the screen and the screen will be 2 units wide. Make sure to draw your HUD at (or just behind) the near clipping plane to make it draw in front of your scene.
To draw "over" the scene, just disable the depth testing.
glDisable(GL_DEPTH_TEST);
don''t forget to enable it before the next drawing of the 3D scene

1/ do you want to enlight the text, or don''t you want to ?
If you''re going to disable depth testing when drawing the hud, make sure you draw it AFTER everything else or it''ll appear behind the scene, not in front.
First..
thx for all the hints.

And .. as I read all this I noticed I did nearly everything
wrong

Prosper:
no I didn''t set materials.. but nehe didn''t either !?
I converted the code from lesson 13 and put it into my HUD
class. From the tut itself I didn''t really understand what the
functions did with the font, because wglUseFontBitmaps is supposed to create a set of Bitmaps, but nehe sets the color
of those Bitmaps to other values. For me Bitmaps have a defined color...

I disabled light1, too, so now I only disable the Lighting, thx

feagle814:
is the width/height of the screen always 2?? or then -1 to 1 on the x/y axis?

vincoof: I want the whole HUD not to be effected by lighting.
The Font/text the panels I create and everything.

Dobbs: thx

Well.. open questions are:
1.)do I need to set a Material?
I set none, and very few light is reflected by the letter''s Surfaces. They are visible, but very dark.
2.) Is the screen always -1 to 1? on position (0,0,0) ?

Thx for any additional advice,
GhostTask

waiting for a live after death
waiting for a life after death
1/ If you disable all lighting, there is no need to set any material. Materials were invented to fit to lighting model. Material makes nonsense without lighting.

When the lighting is disabled, use glColor3f (for RGB) or glColor4f (for RGBA if you want some blending) to set the colours.

With the technique NeHe described in his tutorial #13, all the characters will hve the same color (unless you draw characters one after the other and call glColor between).

2/ it depends on how you define the projection matrix. It''s up to you to decide what''s better in your application.

Prosper described a method where the coordinates of the vertices will be projected on the same screen coordinates. Say, a call to glVertex2i(x, y) will represent the screen coordinate (x, y).

The other method is to fix the coordinates between -1 and +1. In Prosper lines of code, replace the call to gluOrtho2D by :
gluOrtho2D(-1, +1, -1, +1);
The coordinates of the vertices will not be relative to the screen, they will be relative to the field of view.
Say, a call to glVertex2f(0, 0) will represent the center of the window, and acall to glVertex2f(1, 0) will represent the right border.

Discussing the two methods
I will discuss the two above methods, and I''ll use the "x" passed as argument to glVertex2 to discuss about coordinates.

Prosper method :

The bad point is, you need to compute new coordinates to send to glVertex2 if the window resizes. If you want a vertex to be at the right border of the screen, you have to get the screen width and set x=screen_width.

The good point is, you can perfectly align your polygons to the screen pixels. If you want a polygon to start 10pixels right to the left border, just set x to 10 and you''ll have what you want.

The other method I described :

The thing is, you have to forget about thinking in pixels. Think about window "percentage".

The bad point is that it''s not possible to explain coordinates in pixels unless you compute something like:
x=2*the_x_pixel_coord_I_want/screen_width-1
which will set x to -1 if the_x_pixel_coord_I_want=0, and will set x to +1 if the_x_pixel_coord_I_want=screen_width

The good point is that you don''t have to worry about the screen dimensions. glVertex2f(0, 0) will place your vertex in the center of the window whatever the window size is.

Another bad point is that you have to be careful about square objects (at least, with most functions). Say, a polygon whose coordinates go from glVertex(0,0) to glVertex(0.5,0.5) is not necessarily a square !
Thx Vincoof,
I will take it on at the weekend
and experiment a bit with all
that I have learned. There are
older Posts where another way of
displaying Text on a GL DC is described, so...
I will have really much to do

bye for now,
GhostTask

waiting for a live after death
waiting for a life after death

This topic is closed to new replies.

Advertisement