PDA

View Full Version : Introduction to basic projection



henne
06-13-2011, 10:25 PM
Hi all,
I'm working with OpenGL for the first time and I have some problems with projection. I read this (http://www.songho.ca/opengl/gl_transform.html) but I still don't understand how the objects are projected to the screen. My biggest problem is that I still get confused about all these different coordinates. So what are the eye coordinates, device coordinates and normalized device coordinates and what is the difference between them? So when I draw a vertex with glVertex(a, b, c). Are the parameters a, b, c eye coordinates?

In my code I used perspective projection. So I set up the projection matrix with
gluperspective(45, aspect, 0.01, 100); aspect in this case is 1060/479
So when I construct my projection matrix like this. Does the image I see correspond to the near clipping plane of the frustum?

After setting up my projection matrix I wanted to draw a single point at the upper left corner. So I used
glBegin(GL_POINTS);
glVertex(-1, 1, -0.1);
glEnd();
But this point doesn't show up. Doesn't -1,1 correspond to the upper right corner?

Please help me ;)

Dark Photon
06-14-2011, 05:39 AM
So what are the eye coordinates, device coordinates and normalized device coordinates and what is the difference between them?
You really should get a good handle on that first. As I recall, the OpenGL Programming Guide (http://www.amazon.com/OpenGL-Programming-Guide-Official-Learning/dp/0321552628/ref=sr_1_1?ie=UTF8&qid=1308051513&sr=8-1) has a very good description. You can read it here (http://glprogramming.com/red/chapter03.html).

coffeeaddict
06-14-2011, 01:34 PM
But this point doesn't show up. Doesn't -1,1 correspond to the upper right corner?

Please help me ;)

I'm just another newbie but I think you are confusing orthographic with perspective mode. I would recommend buying a copy of the OpenGL Super Bible (5th edition, not 4th) and reading the first couple of chapters.

henne
06-14-2011, 02:31 PM
Hey, I've read chapter in the OpenGL Programming Guide.

So the parameteres I give to glVertex() are the object coordinates aren't they? So if my ModelView Matrix is the identity matrix the object coordinates are equal to the eye coordinates, right?

So what I don't understand is the following:
If I wanted to draw an single point (or anything else) in the upper left corner of my screen. How do I compute these coordinates?

Alfonse Reinheart
06-14-2011, 02:43 PM
So if my ModelView Matrix is the identity matrix the object coordinates are equal to the eye coordinates, right?

Yes.


If I wanted to draw an single point (or anything else) in the upper left corner of my screen. How do I compute these coordinates?

Generally, if you want to draw things relative to the space of the window, then you want to draw them using an orthographic projection, not a perspective one. You can use glOrtho to set up a projection matrix where the eye-space coordinates are exactly equal to the window-space coordinates.

henne
06-14-2011, 09:20 PM
Yes, but I have to use a perspective projection because the API call of the camera requires a perspective projection. Otherwise I get an distorted image.
So, is there any possibility to compute the coordinates using perspective projection?

Alfonse Reinheart
06-14-2011, 09:28 PM
Yes, but I have to use a perspective projection because the API call of the camera requires a perspective projection

You don't have to do anything. You have complete control over the projection and modelview matrices; they can be exactly what you want them to be.

You can render with a perspective projection for a time, then switch to an orthographic one to do some text drawing or whatever, then back to a perspective one, then back, all within a single frame.

OpenGL does what you tell it to do; don't limit yourself by what it seems like OpenGL is allowing you to do.

henne
06-15-2011, 08:44 AM
Oooh, didn't know that. Problem solved. Thank you :)