Perraco
Perraco

Reputation: 17380

Change Opengl ES 2.0 coordinate Origin

in Opengl ES 2.0, is there a simple way to change the bottom left origin to be instead the Top Left when drawing? Thanks

Upvotes: 1

Views: 473

Answers (2)

Vasaka
Vasaka

Reputation: 2022

You could use simple vertex shader, adding some logic to make tex top-right corner to be in proper position.

attribute vec4 position;
varying vec2 texCoord;

void main()
{
    texCoord = position.xy * vec2(1.0, -1.0);
    gl_Position = position;
}

and pixel shader just taking those texCoord and passing to sampler.

varying vec2 texCoord;
uniform sampler2D sampler;

void main(void)
{
    gl_FragColor = texture2D(sampler, texCoord);
}

Upvotes: 2

datenwolf
datenwolf

Reputation: 162327

For regular drawing operations by applying an appropriate projection matrix, or flipping the Y coordinate in the vertex shader. You didn't specify what projection you use and didn't post code, so that's the answer I can give you.

Upvotes: 1

Related Questions