Friday, July 15, 2016

How to use traditional pixel coordinates system in OpenGL? (with C++/SDL2)


I find the normalized, centralized coordinate system used in OpenGL weird and annoying, is there anything I can do at all to make it work like normal pixel coordinates on everything ever except OpenGL? And yes, of course I Googled it.


EDIT: I'm using OpenGL 2.1



Answer



glOrtho( 0.f, viewWidth, viewHeight, 0.f, 0.f, 1.f );


Assuming that you're starting from an identity matrix, this glOrtho() call will give you a traditional window coordinate system with 0,0 at the top left corner, such that one unit in OpenGL space corresponds exactly to one pixel in the view which contains the OpenGL-rendered image.



Man page for glOrtho.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...