chewbapoclypse chewbapoclypse - 1 year ago 92
Java Question

Android Changing OpenGL Coordinate System

Ok so I found this thread, which is what I believe I need to do. However, I am not using

isn't a part of the

What I want to do is change the coordinate system's range from [-1, 1] to [0,1].
This is the normal system.

Normal Coord System

I would like to change it so that it is this.(Below)

enter image description here

The center of the screen is 0.5f, 0.5f, bottom left is 0f,0f, etc. It is only 2D.

private final String vertexShaderCode =
"uniform mat4 uMVPMatrix;" +
"attribute vec4 aPosition;" +
"attribute vec2 aTexCoordinate;" +
"varying vec2 vTexCoordinate;" +
"void main() {" +
" gl_Position = uMVPMatrix * aPosition;" +
" vTexCoordinate = aTexCoordinate;" +

Answer Source

The Ortho is still a way to go but you need to use a matrix. So in your shader you would use a matrix as a uniform which then multiplies the input position.

In general there is no way at all you can change the coordinate system. The openGL works with normalized coordinates so no matter what you do you will always have a 0 in the center of the buffer and borders are [-1, 1] from left to right and bottom to top and the same goes for depth when using depth buffer.

So what the orthographical matrix does is scale your input coordinates to the openGL internal coordinate system and this is the procedure that even ES1 does but the difference is that the matrices are already generated for you and all the coordinates are multiplied for you in the fixed pipeline.