Sign in to follow this  
nathanpc

OpenGL Screen Coordinates and (0,0) Position

Recommended Posts

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)?

Share this post


Link to post
Share on other sites
All matrix operations are removed in ES2, but the idea is the same - send your own projection matrix.

As to integer positions, use glVertexAttribIPointer (note the I).

Share this post


Link to post
Share on other sites
[quote name='wolfscaptain' timestamp='1344375199' post='4967155']
As to integer positions, use glVertexAttribIPointer (note the I).
[/quote]

I'm not sure I've ever heard of glVertexAttribIPointer...

Use glVertexAttribPointer with the [i]type[/i] 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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this