Screen Coordinates and (0,0) Position
3 replies to this topic
Members - Reputation: 102
Posted 05 August 2012 - 03:47 PM
Is there anyway I can make OpenGL ES 2.0 to accept coordinates (for Vextex for example) in int meaning the pixels instead of the default float system? Also how can I set the point (0,0) to be at the top left corner of screen instead of the default one at the exact middle of the screen (to make using the pixel coordinates system easier)?
Members - Reputation: 183
Posted 08 August 2012 - 03:54 PM
As to integer positions, use glVertexAttribIPointer (note the I).
I'm not sure I've ever heard of glVertexAttribIPointer...
Use glVertexAttribPointer with the type parameter set to GL_INT
(check out spec of glVertexAttribPointer at http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml)
In your GLSL shader, you would also want to use ivec instead of vec for your attribute.
You would of course need to set up your modelview and projection matrix to map model coordinates (specified in integer x, y) to the actual pixels of the screen.
If you are using C++, I would suggest looking at GLM, OpenGL Mathematics Library. It contains direct support for all matrix operations (for matrix creation) which are deprecated in newer OpenGL versions and nonexistant in OpenGL ES (including glOrtho2D which is immensely useful), and it contains generic vector/matrix operations. It's at http://glm.g-truc.net/ and can be used directly with the OpenGL ES API. You will still have to track and upload your matrix to the GLSL shaders, but GLM would at least allow you to create these matrices.