Archived

This topic is now archived and is closed to further replies.

Metus

OpenGL Designing GUI in OpenGL

Recommended Posts

I''m about to design a GUI in my OpenGL Game and now I''m wondering if I''m o use glOrtho or not.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
This topic came up on our local forum... heres the solution :

"Switch to glPerspective to draw your level then afterwards, change to glOrtho to draw the HUD, messages etc."

So you do so :

MainLoop
{
glPerspective();
DrawScene();
glOrtho();
DrawHub();
}

problem solved.....
pay us a visit : www.sagamedev.co.za

Share this post


Link to post
Share on other sites
I''ve been trying to get this to work, but everytime i try it, it either complains that ortho doesnt take 4 paramaters, or that the main drawing function doesnt take 0 paramaters.

Share this post


Link to post
Share on other sites
glOrtho doesn''t take 4 parameters... it takes 6:

left, right, bottom, top, near, and far clipping planes

gluOrtho2D takes 4 (IIRC, near and far are set to -1 and 1 respectively)

Share this post


Link to post
Share on other sites
I think a GUI in perspective mode would be pretty cool, you could have your windows going into the screen as well!

Of course, you can still get some cool effects in ortho mode, my favorite is when opening/closing new windows, you can make them rotate in, or flip in, or fade in, or zoom in, or any of a number of effects. Heh, Windows XP eat your heart out!


codeka.com - Just click it.

Share this post


Link to post
Share on other sites