PDA

View Full Version : 2d interface in a 3d world



jbich
06-24-2005, 06:36 AM
Hey all.

Lots of people have hit on the 2d/3d thing and I've looked into all the posts, but I'm still stuck on something... perhaps it's how I'm thinking about it...

In a 3d game, I want to build a 2d interface. You can't (as per the redbook) switch at will between 2d (ortho) and 3d (perspective/frustrum) projection.
If I had a window that's 640x480, how could I draw a box that's say 200 px tall and 100 px wide using a 3d point system?

It seems clunky to use Project/Unproject to do this as it was designed for mouse coordinates, and (again as per the redbook) there are inherant problems at the conceptual level doing project/unproject calculations.

If there are no transformations in my matrices, is there a simple algorithm that I can use to calculate real world pixel information from/to 3d world points?

I did have the thought that perhaps I could make the z coord a large negative, so that the x,y coords matched real world pixels... is that a solution? Is there a better one?
Anyone know how the "pros" do it?

Also, in a normal 3d environment, is it possible to make the origin (0,0) the bottom left hand side of the screen?

Thanks so much for any insight you can provide!

j

ZbuffeR
06-24-2005, 07:27 AM
Who said you can't switch between ortho and perspective ???

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum(...) / gluPerpective(...)
[draw 3D stuff]

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0, windowWidth, 0, windowHeight);
[draw 2D stuff with pixel coordinates]

The FAQ about this :
http://www.opengl.org/resources/faq/technical/transformations.htm#tran0030

jbich
06-24-2005, 08:54 AM
(blushes)

whoops must have mis-read.

Thank you very much!

ZbuffeR
06-24-2005, 09:16 AM
hehe, no problem ;)