# OpenGL Details about perspective projection

This topic is 3931 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to know the details of OpenGL projection and clipping. All I know so far is that in order to make a perspective projection, one divides the vertex with the z-coordinate. But OpenGL has a projection matrix, what is this used for? Where in the process is the vertex divided by the z-coordinate? Any good resources on the entire process? (I just know OpenGL does some projection with a matrix which transforms the vertices into something called clip space, and after that I have no idea what happens).

##### Share on other sites
The details are not too complex... I guess a quick search on a good search engine with Google will give you better results.

But basically, all the transformations together maps a 3D position to a position on the screen. In other words they map the world objects onto the screen.

Here's a quick and simple explanation:

First, you have a "viewport" transform which will map a projected scene to the screen. It will map the "default" pixel positions to the ones defined by the screen or surface you render to.

Next, is the projection transform, this one maps 3D position to a 2D position which I called the "default" pixel position in the previous step. This is usually mapped to [-1, 1] horizontally and vertically (if I'm not mistaken) or something similar.

If you are in DirectX, here you'd have the view transform which corresponds to the "camera".

After that, you have the model/world transform which "moves" the objects in the scene from the origin (0,0,0) to the position, rotation and scaling it should be. In OpenGL the model transform also contains the view transform that corresponds to the camera.

All these transforms can be seen one way or the other depending on what you are working with.

Another way to see that, in OpenGL, instead of moving a camera, you are moving the entire scene. So all the objects are moved so the camera is looking in the direction -Z (or Z, I'm never sure what OpenGL is). Now from that, the projection transform projects the points on a coordinate system that goes from [-1, 1] horizontally and vertically and the remaining step is to map those to the area you are rendering to.

Projection transform can be perspective or orthogonal, perspective is the /z you were talking about.

I'm not sure about what OpenGL does but clip space is probably just the space all polygons that are not inside the area rendered are clipped.

If you need help, just say so... I'll try to find more informations on that. The OpenGL book (the "red book" I think) is probably a good reference for that.

JFF

##### Share on other sites
Actually, there's not really a division by z, it's a division by w ( the 4. homogenous coordinate). You have to use the projection matrix to 'move' the scaled and biased z component to w for the perspective effect. The division always happens right after the vertices are processed by the projection matrix (or your vertex shader). All the 3 remaining coordinates are then in the [-1,1] range, and this is where clipping and primitive assembly happens (at least theoretically, drivers and GPUs are of course free to use early-outs).

HTH

##### Share on other sites
I found World to Screen Projection Transformation after a quick search on Google. That explains the process I mentioned in my previous post.

The "division by Z" happens when you are projecting (perspective projection) the 3D coordinate on the 2D plane. See 3D projection on Wikipedia for more details.

JFF

##### Share on other sites
Thanks guys, I understand it much better now when I see that you move the z-coordinate to the w and divide by w after projection. I didnt know the vertices were diveded by w before :)

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5

• 11
• 11
• 21
• 10
• 33
• ### Forum Statistics

• Total Topics
633438
• Total Posts
3011882
• ### Who's Online (See full list)

There are no registered users currently online

×