Screen coordinates & rendering

I just posted this over at gamedev.net:

"Can anyone tell me if it is possible in OpenGL to draw objects to the screen using screen coordinates (eg. 300x, 400y) instead of making use of glLoadIdentity() and moving to the centre of the screen all of the time? It seems to me that OpenGL is permanently stuck in camera (or clip?) space.

Also, is it possible to make use of texture perspective eg. making textures look 3D without using the API’s inbuilt rotation, translation, projection functions? AND more importantly do you need to make use of inbuilt 3D-functions of the API to do effects like reflection or other commonly documented OpenGL features"

One of the posters at gamedev.net recommended I find out about parallel projection. Is this covered in the OpenGl manual, and if not, does anyone know where I can find some information about this (or have any suggestions / useful tips)?

The aforementioned poster said that information about this topic (not using inbuilt 3D API functions) is scarce? I just want to use OpenGL as a renderer/shader, because I have a program written in Glide that I want to port.

Thanks,
Paulcoz.

[This message has been edited by paulcoz (edited 12-20-2000).]

Use screen coordinates to render in a window isn’t difficult. Do this:

Set a variable RECT cr.
then call GetClientRect(window_hwnd,&cr).
now, set the viewport:
glViewport(0,0,cr_right-cr_left,cr_bottom-cr_top).
Now use gluOrtho2D to make a orthogonal 2D projection.
Set the projection mode (glMatrixMode) and then call:
glLoadIdentity;
gluOrtho2D(0,cr_right-cr_left,cr_bottom-cr_top,0);
then set the ModelView Matrix to Identity.
And so you can just pass coordinates in 2D system like we’ll do with GDI.

marcio
hope this help

Thanks Marcio, I’ll give it a try.

I was also told that I have to flip the y and z coordinates because OpenGL has them reversed. Is that true? I am pretty sure that OpenGL’s z-axis increases towards the user, rather than into the monitor (which is the way I am used to). How do I adjust this - having the z-axis the wrong way around will affect back-face culling won’t it?

Regards,
Paulcoz.

[This message has been edited by paulcoz (edited 12-20-2000).]

You can choose, how backface culling is performend: clockwise or counter clockwise (default). And yes it’s true, that the z-coordinate increases towards the user. OGL uses a right-handed coordinate system with x to the right, y up and z towards you (in front of the screen :-)).

Marc

paulcoz, if you set the projection matrix exactly as i wrote you won’t need reverse the y coordinate (nor x coordinate) because the matrix will take care of it. Then if you will only render 2D you should call glDisable(GL_CULL_FACE). At this point you can draw objects 2D just as do with GDI (use z = 0 or call 2D vertex functions). Don’t worry about back culling because you disabled it

marcio