Screen coordinates

Started by
3 comments, last by NIm 16 years, 2 months ago
Is there a way to make openGl draw relative to the screen? or should I just remember where the nearest clipping plane is and glTranslate to it? I figure it'd be lot faster if opengl did this natively.
Advertisement
What do you mean by 'screen coordinates'? Like in pixels? If so, your best option is to use an orthographic projection matrix. Don't worry about the speed with that too much, it's pretty fast.
I'm talking about a set of coordinates attached to the screen, as opposed to world coodinates, which are attached to the arbitrary point you've chosen as your origin, also opposed to model coordinates, like when you use glTranslate() and glRotate to move the origin to the position and rotation of your model.

Don't care what units it in: I can convert easily. I'm talking about drawing on the camera, like a heads up display or something. Will I be able to use glOrtho() for my HUD, and glPerspective() for drawing the world?

I realize that I can remember where the camera is positioned and draw the hud directly in front of it, but it seems like it would be more efficient to draw quads and stuff on the 2d space that is the screen, because then you don't have any of the maths involved in transforming them to what boils down to a position on the screen, rather than a position in space.

In less precise, less clever, and more clear words: How do I make a HUD to show information to the player?

Also: What's the best way to write text?
Well, there are some ways.

You see, you can simple paste an image in the framebuffer (or blend it in ect.). Look up these functions:
glDrawBuffer();glDrawPixels();

I'd use this for a HUD.

If you still want to use screen coordinates for, for instance bitmaps, you might want something like this:
glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(some arguments i cant remmeber from the top of my head);glMatrixMode(GL_MODELVIEW);glLoadIdentity();//and now you are working in 2d!//remember to set GL to 3d once you get back to drawing the scene

Here is a link for drawing text (which requires the 2d code metioned above):
http://www.glprogramming.com/red/chapter08.html#name1

Does this answer your question?

Edit: I am also relatively new to opengl, there might be mistakes in here
Thanks, that's what I'm looking for. Rating++

This topic is closed to new replies.

Advertisement