View Full Version : ReadPixel in Perspective

12-12-2006, 01:32 AM
First, sorry about my english, but i hope you will understand me.

I need the correct mathematical Calculation about the ammout of Pixel. When i transform a plain with -z, then the ammount of pixel decrease. Okay. I understand this. But how calculate OpenGL the ammount of Pixel for the correct perspective. When i start with different x-y coordinates, then it will be different, than i start in x=y=0. The Calculation must depend with x and y Startccordinates.

Please help me. I have to know this.

Thank you for your help.

12-12-2006, 03:44 AM
The most detailed answer to this is in the OpenGL 2.1 spec starting at chapter 2.11 Coordinate Transformation.
Spec is here: http://www.opengl.org/registry/doc/glspec21.20061201.pdf
It's all linear algebra. You basically need to know 4x4 matrix multiplications, matrix * vector calculations, and some clipping calculations for that.

If you just need to know the windows coordinates from input vertex data without caring too much about the mathematical background, lucky you ;) , there is a utility function that calculates that for you: gluProject.
Check your compiler's manual what parameters that needs.

(Your question should have gone to the beginner's forum.)

12-12-2006, 06:18 AM
There is also GL_FEEDBACK mode in OpenGL. Just "draw" any shape in feedback mode, and then you can get information about all vertices that made it to the screen and all that were added during clipping. Just extract minimum and maximum values from the buffer, and you have the rectangular region.
This is more less what gluProject does, but for large number of points it can be faster (but doesn't have to be, since this functionality can be emulated by driver).