Flipping Y Coordinate

Started by
2 comments, last by LowCalorieSoftDrink 19 years, 2 months ago
Is there an simple way to "flip" all the y window coordinates essentially to make the origin of the viewport the top left of the screen instead of the bottom left.
Advertisement
Are you doing this in 3d or 2d?
This is what I do for 2d, the GUI:
void oglCanvas::SetupOrthoMode(void){	// Setup projection matrix	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	// Go into ortho mode with same dimensions as the frame	// Reverse the bottom,top values so the coordinates are 	// 0,0 is upper left, not lower left.	glOrtho(0, Frame->getFrameWidth(), Frame->getFrameHeight(), 0, -1, 1);	// Go back to Model View mode	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	// Go into Scissor mode since we want to clip the windows	glEnable(GL_SCISSOR_TEST);	glScissor(0, 0, Frame->getFrameWidth(), Frame->getFrameHeight());}
- onebeer
I don't know why you would want to do that? In math 0,0 or the origin is the bottom left, this is how OpenGL is setup. Plus for 2D work doesn't it make more sense to have Y Axis move upward as a positive value instead of a negative value? If you want to still use Y axis as inverted just add or sub the screen height with a const variable to your vertex Y axis values... if you are doing 2D work.
Im doing 3d (well perspective) and i need to do it because when i render to a texture opengl creates the pixel buffer from the top left, which doesnt correspond with the way a textured quad in 2d would work (there are more complex issues than just this seemingly simple problem). The most elegant maner, considering my project, to avoid special case code would be for me to alter the y coordinates while transforming to NDC. Although I dont think opengl supplies a means to do this.

This topic is closed to new replies.

Advertisement