PDA

View Full Version : Problem with vertices projection



enigmagame
11-04-2008, 02:31 PM
Hi,
see this image:
http://img60.imageshack.us/img60/3237/texturewq8.th.jpg (http://img60.imageshack.us/my.php?image=texturewq8.jpg)http://img60.imageshack.us/images/thpix.gif (http://g.imageshack.us/thpix.php)
The PROJECTION_MATRIX is setup with:


glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

I know each vertex position, and with a function, I project each vertex. I would know the position of each triangles vertex on image. But I obtain strange result, for example for the first two triangles (yellow), I obtain this coordinate:


0.000000 384.000000
128.000000 384.000000
0.000000 512.000000
0.000000 512.000000
128.000000 384.000000
128.000000 512.000000

Why they are inverted? And why the projected coordinate indicate the triangles on bottom? The image size is 512x512.
Thanks.

trinitrotoluene
11-04-2008, 03:23 PM
In OpenGL, the bottom left corner of the viewport is (0,0). To make it top left change the glOrtho call like this glOrtho(-1.0, 1.0, 1.0, -1.0, -1.0, 1.0);.

_NK47
11-05-2008, 05:46 AM
... or adjust the vertices bottom left. found out recently that f.e. scissor box is operating on bottom-left origin anyways so flipping is necessary in case of top-left origin.

enigmagame
11-09-2008, 08:59 AM
In OpenGL, the bottom left corner of the viewport is (0,0). To make it top left change the glOrtho call like this glOrtho(-1.0, 1.0, 1.0, -1.0, -1.0, 1.0);.
Yes, it's correct and it's works. But if in the same function I draw the texture and I generate the coordinate the results is wrong.
How can I solve?

trinitrotoluene
11-09-2008, 10:55 AM
Yes, it's correct and it's works. But if in the same function I draw the texture and I generate the coordinate the results is wrong. When you write that the result is wrong do you mean that you texture appear upside down, or you mean that the projected coordinate are wrong? For the first change your texture coord on the triangle, for the second keep your original gluOrtho parameter and take y = (viewport_height-1) - y.So [0.000000 511.000000] coordinates become [0.0 0.0]. Notice that your coordinate you give above seem strange because if the size of your viewport or image is [512 512] then the pixel coordinate for x and for y vary between [0 511]. If you count your pixel from position 1 to 512 then y = viewport_height - y.