Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does OpenGL draw things upside down?

I have yet to see anyone answer this question yet. All I see is people telling them something is upside down and then someone else tells them to flip their code. But what I'm wondering is why does OpenGL flip the Y coords? It makes no sense.

like image 478
user2101672 Avatar asked Feb 24 '13 14:02

user2101672


3 Answers

OpenGL assumes Y coordinates going from bottom to top. If your code assumes the opposite will display things upside down.

For more information Google for opengl coordinate system

like image 107
Paolo Avatar answered Oct 23 '22 21:10

Paolo


It all depends on how you setup your scene. There are many things that can cause this effect.

For instance, the camera position/orientation affects how you see the final scene.

gluLookAt(camera[0], camera[1], camera[2],  /* look from camera XYZ */ 
                  0,         0,         0,  /* look at the origin */ 
                  0,         1,         0); /* positive Y up vector */

When working with textures, specifying wrong texture coordinates can flip the drawing.

But the most common issue might be people forgetting that OpenGL defines coordinate (0, 0) to be the lower left corner of the display (with the Y going upward).

like image 42
karlphillip Avatar answered Oct 23 '22 19:10

karlphillip


OpenGL works on Cartesian coordinates. In a Cartesian coordinate system 0,0 is in the center, with positive coords extending up and to the right. Any coordinates can be mapped or transformed to whatever the programmer wishes, but this is the default. When you give texture coordinates OpenGL expects those to be Catresian coordinates, not top down coordinates. Those coordinates can be transformed by the program, but the quickest fix is to just flip the texture.

enter image description here

like image 38
BentFX Avatar answered Oct 23 '22 21:10

BentFX