6
votes

Say I am using an Identity Matrix for my modelViewTransformation Matrix on an OpenGL ES 2.0 program. The Co-ordinate system in this case is the canonical OpenGL co-ordinate system which extends from (-1,-1,-1) to (1,1,1).

Is this coordinate system right-handed or left-handed?

A broader question: Is there a document with OpenGL which can list all the mathematical conventions followed by the API?

4

4 Answers

7
votes

My question is, is this coordinate system right-handed or left-handed?

By default, OpenGL is always right-handed. You can observe this by the automatic normal creation. You can force a left-handed normal creation by specifying it per point but, in general, right hand rule applies all the time. See 9.150 in the OpenGL FAQ for more discussion of the right-hand-only nature of OpenGL.

... all the mathematical conventions followed by the API?

It's not clear what you're asking for. The math is basic linear algebra with a strong focus on matrix math and linear transformations.

EDIT to respond to comment question:

REMEMBER, however, that if you are using the uniform matrix calls rather than the older glRotates, etc, that you must specify whether you are using row-major or column-major matrices. In this case (from the code mentioned in the comment):

glUniformMatrix4fv(uniforms[UNIFORM_MVP], 16, GL_FALSE, mvpMatrixZRotation);

In this call, GL_FALSE is telling the call that this is a column-major matrix and, as such, the rotation that results will be the transpose of what was intended. Therefore, the rotation will be inverted, looking like a left-handed coordinate system.

Change that to GL_TRUE and all will be well.

Here is a very simple example from the OpenGL discussion board that's relevant to this specific topic.

Yet another edit to respond to the request for comment: Here is another detailed explanation of the matrix pipeline in OpenGL. Notice the GL_MODELVIEW diagram with the three axes: they illustrate the right-handed coordinate system. The above citation in the FAQ also still applies.

6
votes

ALWAYS REMEMBER!! OPENGL ONLY KNOWS NDC ,AND IT IS LEFT_HANDED!

the illusion openGL is right handed,because in fixed pipeline,the fixed function is right handed,like glOrtho(...),glFrustrum(..), all these functions have been deprecated In programmable-pipline times.

OpenGL doesn`t care what handed coordinate system you use for intermediate matrix processes. you can use axis coordinate system if you want,as long as you mirror that to NDC.

forget about Camera!

because our screen is a 2D plane.Imagine this,your viewport is a yellow rubber plane.pine those four corner to NDC. something like this: enter image description here

all vertex in NDC hit on on the yellow rubber plane along the -z axis.That`s what you see on real screen.

4
votes

The canonical view volume aka normalized device coordinates is/are left-handed. This is easy to test by passing the identity matrix and drawing 2 triangles say

float points[] = { -1,  1,  -0.5,
                   -1, -1,  -0.5,
                    1, -1,  -0.5,

                    1,  1,   0.5,
                   -1, -1,   0.5,
                    1, -1,   0.5 };

and looking at the results (with glEnable(GL_DEPTH_TEST))

So your vertex shader will look like this:

uniform mat4 mvp_mat;

// Incoming per vertex... position (fills in 1 for w if from vec3 buf)
layout (location = 0) in vec4 v_vertex;


void main(void) 
{ 
    // multiplying by identity doesn't transform the geometry
    gl_Position = mvp_mat * v_vertex;
}

or you could even test it more simply like this since the identity matrix does nothing

layout (location = 0) in vec4 v_vertex;

void main(void) 
{
    //no transformation, no confusion, just straight to OpenGL
    gl_Position = v_vertex;
}

Obviously you'll have to make the colors of the triangles different so you can see how they overlap.

Also see this post and my comment/question in it: plus.google.com/114825651948330685771/posts/AmnfvYssvSe

I don't know where all the incorrect information comes from all over the internet and even in textbooks. OpenGL is only right handed by default if you're talking about triangle winding for determining the front face (CCW by default = right handed). World space, object space and eye space don't exist to OpenGL, only to the graphics programmer. OpenGL just takes points, clips anything outside of the canonical view volume [-1, -1, -1] x [1, 1, 1] and transforms them to screenspace/window coordinates which by default is [0, w) x [0, h) x [0, 1]. If the depth test is enabled the default behavior is left-handed, looking down +z.

There are several ways to account for OpenGL's left-handedness. Most people handle it in their matrices (though they don't realize it). I think you can also change it using glDepthFunc and setting it to GL_GREATER.

http://www.opengl.org/sdk/docs/man3/xhtml/glDepthFunc.xml

Further proof that it is left handed is here http://www.opengl.org/sdk/docs/man3/xhtml/glDepthRange.xml

"After clipping and division by w, depth coordinates range from -1 to 1, corresponding to the near and far clipping planes" ie positive z goes into the screen = left-handed. You can also use DepthRange to change to right-handed behavior.

EDIT: In Response to Bob Cross's insistence that I'm wrong, here's a single source file program that shows that I'm right. https://github.com/rswinkle/opengl_reference/blob/master/src/left_handed.c

You can see the screenshot in the README https://github.com/rswinkle/opengl_reference

2
votes

Opengl ES coordinate system is indeed Right Handed System including the Canonical Volume of (-1, -1, -1) to (1,1,1). I have verified this through code.