Designing GUI in OpenGL

Started by
12 comments, last by Metus 22 years, 5 months ago
I''m about to design a GUI in my OpenGL Game and now I''m wondering if I''m o use glOrtho or not.
Ethereal
Advertisement
I think that''s what I would use.
quote:Original post by Metus
I''m about to design a GUI in OpenGL


designing anything comes from designer''s head and
it doesn''t relate to rc api in any mean.
You use ortho for anything 2D (as in, not suspended in the 3rd dimension).

[Resist Windows XP''s Invasive Production Activation Technology!]
You could also use glPerspective, just set all the Z coordinates to 0.0f.
quote:Original post by Terran Marine
You could also use glPerspective, just set all the Z coordinates to 0.0f.

You could use a constant Z, but there are two problems.

Firstly, it''s harder to design an interface in that way. You can''t just say, I want this to be five pixels to the right of the screen''s edge, because it''s tricky (but not impossible) to figure out where that is.

Secondly, it just wouldn''t look right - the UI would be squished at the corners of the screen. The amount of squish depends upon how far away the surface is. To produce no squish, you''d have to place the plane at infinity, but in practice you can get a convincing effect with it nearer.

You should use glOrtho because it''s easier, and because it''s technically correct.

Signatures? We don''t need no steenking signatures!
CoV
When it comes to GUI, gluUnProject and bitmap fonts are your friends, unless I don''t know what you''re talking about
What exactly doesn Unprojecting do?
gluUnproject converts mouse coordinates to world coordinates its useful if you want to find if a button drawn in openGL is clicked or something similar.
"To err is human, to really mess up requires a computer"
I agree with Mayrel that trying to draw a GUI using a perspective projection is a bit pointless, and fraught with problems (think z-fighting and distortion).

The absolute best way to do 2D and GUI stuff (and probably the way OpenGL was designed to accomplish this), is to set an orthographic projection, disable depth testing, and simply draw back-to-front.

The extra-super-that''s-fantastic bonus you get when using OpenGL this way is that you can make the GUI totally resolution independent... just work with internal dimensions... e.g. assume an 800 x 600 (logical units) display area, and let OpenGL handle converting it to the actual resolution.


BTW Masonium, I would argue that bitmap fonts have been sent by Satan to rape and pillage and suck the life out of your otherwise fast app... but that''s just my opinion

I prefer to use texture-mapped fonts (quads with textures on them), as they are generally quicker.

This topic is closed to new replies.

Advertisement