Archived

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

Chocoboko

OpenGL Coordinates in OpenGL

Recommended Posts

I am new to OpenGL and a certain part is confusing me. I am used to plotting images to a screen based on their x and y coordinates. OpenGL seems to be different. It seems to plot images based on a single digit number. Someone told me I could use the basic coordinate system with the glOrtho function, yet it doesn't seem to work for me. I plot "glVertex2f(.5, .5); glVertex2f(.5, 1); glVertex2f(1, 1); glVertex2f(1, .5);" and the sqaure shows up at the right end of the screen, which is way more than .5 or 1 pixel. Can someone explain OpenGL's plotting system or show me how to manipulate OpenGL to use the coordinate system? If possible, can you point me to some sample source codes that deal with this issue. Thank you. [edited by - Chocoboko on September 2, 2002 11:20:54 PM]

Share this post


Link to post
Share on other sites
Hi,the answer to your question is not so simple,but here it is.The problem is the coordinate system OpenGL uses.Check your Resize function and you will see that code:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

That tells OpenGL that the current matrix mode is GL_PROJECTION and you can modify the projection matrix.By then calling glLoadIdentiy you tell OpenGL to equal the projection matrix with the identity matrix(the projection matrix is now clear).After that you can use one of the OpenGL functions to set a new projection matrix or do that yourself(ex3mly hard).There are 2 types of projection states:the orthographic and the perspective.The first one is set with glOrtho and the second with gluPerspective or with glFrustum.
If you are using glOrtho to set your projection matrix,OpenGL uses the same coordinate system as Windows.Here is a quick example with orhographic projection:

RECT rcClientRect;

GetClientRect(g_hWnd,&rcClientRect);

glColor3f(0.0f,1.0f,0.0f);
glRecti(0,0,rcClientRect.right,rcClientRect.bottom);

This will draw a green quad that covers all of your client area.

If you are using perspective projection you will use the Cartesian(don''t know if the name is right) coordinate system.It looks something like that:



|
|
|O(0,0)
------------|------------
|
|
|

Yeah,that''s look very familiar from the math lessons with that nasty,ugly teacher.The point O is in the center of your screen until you change the modelview matrix.So here is a example with perspective projection:

glTranslatef(0.0f,0.0f,-5.0f);

glRecti(-1,-1,1,1);

This will draw a rect at the center of your screen.Well that''s all.If you have questions write on Mihail121@Yahoo.co.uk

The pain is coming...this sommer!!!

Share this post


Link to post
Share on other sites