Skip to main content
1 of 4
Dani
  • 443
  • 4
  • 12

If you are making a 2D style game, you can use, for example a 320x480 screen coordinates in your code, and then, in your vertex shader, you need to transform them into OpenGL ES coordinates.

I recommend you to use a MVP matrix, for all your vertex operations, but for a naive implementation of an orthographic 2D projection, you can do it manually as follows:

#version 100

attribute vec3 position;

void main(void)
{
  gl_Position = vec4(position.x * 2.0 / 320.0 - 1.0,
                     position.y * -2.0 / 480.0 + 1.0,
                     position.z, 
                     1.0);
}

This puts the screen coordinates origin at the top-left corner. And transform your coordinates from 320 x 480. From here, replace the 320 and 480 values as you need.

The orthographic projection matrix is shown here: http://gamedev.stackexchange.com/a/4312/3020

Dani
  • 443
  • 4
  • 12