Followers 0

# OpenGL What makes OpenGL right handed?

## 63 posts in this topic

Quote:
 :(
Hehe :)

The image at the top of that page shows the view frustum in view space. The coordinate system as shown is right-handed, but that's just by convention; you could just as easily set it up to be left-handed (e.g. by building your own projection matrix and uploading it via glLoadMatrix(), or by performing the transform yourself in a shader).

After the division by w, the geometry is in normalized device coordinates, which are described here. Note that it says that the 'near clip plane will map to -1' and 'the far clip plane will map to 1'. In other words, normalized device coordinates are left-handed in OpenGL.

See also here, in the section titled 'The Projection Transform and Perspective Division'. The second diagram in that section shows the canonical view volume. Note the arrangement of the axes (left-handed). It also states that NDC are left-handed in the next paragraph.

As for clip space, unless I'm missing something very obvious, it is also left-handed. z values are clipped to the range -w (near) to w (far), which after division by w is transformed to the range [-1, 1].

So in short, I don't see anything there that indicates that clip space is right-handed in OpenGL.
0

##### Share on other sites
Quote:
 Original post by jykSo in short, I don't see anything there that indicates that clip space is right-handed in OpenGL.

Here's a test for you jyk - try running your right handed OpenGL/Direct3D engine through PIX and see what your post vertex shader values are. I'm willing to bet that they are represented in this space by a left handed system. If we could somehow use PIX with OpenGL, then I would guess they would be represented by a right handed system. It's precisely this space that I'm *guessing* makes DirectX/OpenGL left/right handed.

I've just tried this using two Direct3D right handed engines and both are left handed when I look at the vertex shader output.

Thoughts?
0

##### Share on other sites
Quote:
 Here's a test for you jyk - try running your right handed OpenGL/Direct3D engine through PIX and see what your post vertex shader values are. I'm willing to bet that they are represented in this space by a left handed system. If we could somehow use PIX with OpenGL, then I would guess they would be represented by a right handed system. It's precisely this space that I'm *guessing* makes DirectX/OpenGL left/right handed.I've just tried this using two Direct3D right handed engines and both are left handed when I look at the vertex shader output.Thoughts?
Honestly, I don't think that idea makes any sense. I haven't busted out PIX yet, but I will if I have to (I'm committed to this thread now - this is going to get resolved one way or another ;).

First, let me ask you this. Do you agree that normalized device coordinates are left-handed in OpenGL? For what it's worth, I've provided a couple of links to substantiate it, and I think it would probably be useful to establish this as a 'fact', at least for the purpose of this discussion.

I think we can also agree that prior to being transformed in the vertex shader, geometry is in whatever space we want it to be (left-handed, right-handed, etc.).

So that leaves what I understand to be called 'homogenous clip space'; the space that geometry is in *after* transformation by the vertex shader and *before* division by w. This is the space that you're arguing is somehow left-handed in Direct3D, but right-handed in OpenGL. Assuming we agree about NDC, this would mean that along with the division by w, coordinates are somehow transformed from a RH system to a LH system between clip space and NDC space. How does this happen exactly?

There are several lines of argument that could be pursued here, so I'll just choose a couple. First, I'll refer you again to the second diagram on this page. The NDCS shown there is left-handed, as we've established. Note how the axes are labeled: x'/w', y'/w', and z'/w'. In other words, normalized device coordinates are simply the 'projection' of homogenous clip coordinates into 3-d space. So how would it be exactly that this projection would also effect a change of handedness?

To make this a little more concrete, let's work through an example. Consider a right-handed perspective projection transform with a field of view of 90 degrees, a square aspect ratio, and near and far values of 1 and 2, respectively. The matrix generated by gluPerspective() for this transform is:
1 0  0  00 1  0  00 0 -3 -4 0 0 -1  0
Now consider the two points:
A = [0 0 -1 1]TB = [0 0 -2 1]T
Since the system is right-handed and the modelview transform is identity, these points lie directly in front of the viewer, with B farther away than A. Ok so far?

Now, we apply the projection transform to yield homogenous clip coordinates:
[1 0  0  0][ 0]   [ 0][0 1  0  0][ 0] = [ 0][0 0 -3 -4][-1]   [-1][0 0 -1  0][ 1]   [ 1][1 0  0  0][ 0]   [ 0][0 1  0  0][ 0] = [ 0][0 0 -3 -4][-2]   [ 2][0 0 -1  0][ 1]   [ 2]
We already know that B is farther from the viewer than A, and we can see here that if we examine the values z/w, Bz is farther along the positive z axis than is Az. Of course these are just the values of the corresponding normalized device coordinates, so it's no surprise that the results would appear to be in a left-handed coordinate system.

Anyway, I guess my question for you would be, what in the above example indicates that clip coordinates are in a right-handed space? What should I be looking for exactly?

Disclaimer time. There are folks around here who know everything there is to know about the 3-d graphics pipeline (both Direct3D and OpenGL). I'm not one of them, so I can't claim 100% certainty or authority on this matter. There have certainly been times that I really thought I understood something and then found out I was wrong, and who knows - maybe this'll be one of those times. Maybe there's a 'magical right-handed fairy' hiding in the OpenGL pipeline somewhere that I just happen to be blissfully unaware of :)

I don't think that's the case though. I can understand the confusion, but I really think that you (and others) have just heard 'OpenGL is right-handed' so many times that you're determined to find 'right-handedness' where there is none :)

I could trot out some more references and examples, but I think what might be useful at this point would be for you to explain why you think clip space is right-handed in OpenGL. What's the evidence? Can you find any references that state this? How do you reconcile it with the example shown above? And what does it even mean for a homogenous space to be right-handed, or for the space in which the homogenous coordinates reside to have a different handedness than the space in which their 3-d projections reside?

[Ouch - that was a long post :-|]
0

SOLD!
0

##### Share on other sites

Anyway, I dug around in the specifications a little in the hopes of perhaps putting this to rest. We'll start with this section of the 1.1 spec, item 15.

Item 15 is very clear. Among other things, it states that 'OpenGL does not force left- or right-handedness on any of its coordinate systems'.

It then goes on to give an example of a typical setup, where the view and projection transforms are right-handed, no mirroring or reflection is performed, and near < far for the depth range. It then states that given this setup, the eye coordinate system is right-handed and the clip, normalized device, and window coordinate systems are left-handed [emphasis added]. To repeat, assuming a typical setup, the clip coordinate system is left-handed according to the 1.1 spec.

Now, I don't think any of that has changed since 1.1, but just to be sure, I checked the 4.0 spec as well.

In 'Corollaries', item 7, it states that 'OpenGL does not force left- or right-handedness on any of its coordinate systems'. This is of course the same as the corresponding entry in the 1.1 spec, except that the example has been removed (presumably because it refers to functionality that has been deprecated).

Although the example (in which it is explicitly stated that clip space is left-handed) has been removed, I don't see anything in the section on clipping (2.20) to suggest that anything has changed as far as clipping is concerned.

It seems to me that we can conclude that:

1. The OpenGL API is not 'right-handed', nor is it 'left-handed'. As far as the developer is concerned, it has no inherent handedness.

2. Assuming a typical setup, clip space is left-handed.

So, I hope that settles it :) We'll see though...
0

##### Share on other sites
Quote:
 Original post by jyk1. The OpenGL API is not 'right-handed', nor is it 'left-handed'. As far as the developer is concerned, it has no inherent handedness.

What a surprise... [rolleyes]

Quote:
 Original post by jyk2. Assuming a typical setup, clip space is left-handed.

OpenGL clip space is a totally symmetric cube. As such, it doesn't have any inherent handedness by itself. As you quoted, it's apparent handedness is entirely dependent on whatever data you feed it with, and however you use this data afterwards.
0

##### Share on other sites
Quote:
 What a surprise...
Yeah, I know - I was just trying to convince the holdouts :)
0

##### Share on other sites
Quote:
 Original post by jykAnyway, I guess my question for you would be, what in the above example indicates that clip coordinates are in a right-handed space? What should I be looking for exactly?

Thanks for the great example jyk. Going through your calculations, it's clear that this confirms what you found regarding OpenGL clip space being left handed. The -1 (3,2) entry in the projection matrix is what turns the right handed system into a left handed one.

To me, this thread has been a great help in simplifying OpenGL/Direct3D interoperability. To me, the only fundamental difference between the two is the z-axis of NDC space going from [-1,1] in OGL and [0,1] in D3D, and an engine that uses both renderers only has to take this difference into consideration.
0

##### Share on other sites
Quote:
 To me, the only fundamental difference between the two is the z-axis of NDC space going from [-1,1] in OGL and [0,1] in D3D, and an engine that uses both renderers only has to take this difference into consideration.
Yup, exactly - that's pretty much the only thing that differs (mathematically) between my OpenGL and D3D renderers as well.
0

##### Share on other sites
Quote:
Original post by GaryNas
Quote:
 Original post by jykAnyway, I guess my question for you would be, what in the above example indicates that clip coordinates are in a right-handed space? What should I be looking for exactly?

Thanks for the great example jyk. Going through your calculations, it's clear that this confirms what you found regarding OpenGL clip space being left handed. The -1 (3,2) entry in the projection matrix is what turns the right handed system into a left handed one.

To me, this thread has been a great help in simplifying OpenGL/Direct3D interoperability. To me, the only fundamental difference between the two is the z-axis of NDC space going from [-1,1] in OGL and [0,1] in D3D, and an engine that uses both renderers only has to take this difference into consideration.

How would you take that into consideration? Is your projection matrix slightly different between OpenGL and Direct3D?
0

##### Share on other sites
Ha - the thread is back! :)
Quote:
 Is your projection matrix slightly different between OpenGL and Direct3D?
Yup, that's exactly right. The projection matrices (both the right-handed and left-handed versions) are the same for the two APIs except for a couple of elements that are computed differently due to the differing canonical view volumes.
0

##### Share on other sites
Opengl fixed pipeline is dead, now all is made on vertex/fragment programs, also Directx, right handed or left handed depends on your projection matrix ONLY, you could use the same in both APIs.
0

##### Share on other sites
Quote:
 Opengl fixed pipeline is dead, now all is made on vertex/fragment programs, also Directx, right handed or left handed depends on your projection matrix ONLY, you could use the same in both APIs.
Well, yes, that was kind of the whole point of the thread :)
0

##### Share on other sites
Could we drop a nuke on this thread?
0

## Create an account

Register a new account

Followers 0

• ### Similar Content

• So it's been a while since I took a break from my whole creating a planet in DX11. Last time around I got stuck on fixing a nice LOD.
A week back or so I got help to find this:
https://github.com/sp4cerat/Planet-LOD
In general this is what I'm trying to recreate in DX11, he that made that planet LOD uses OpenGL but that is a minor issue and something I can solve. But I have a question regarding the code
He gets the position using this row
vec4d pos = b.var.vec4d["position"]; Which is then used further down when he sends the variable "center" into the drawing function:
if (pos.len() < 1) pos.norm(); world::draw(vec3d(pos.x, pos.y, pos.z));
Inside the draw function this happens:
draw_recursive(p3[0], p3[1], p3[2], center); Basically the 3 vertices of the triangle and the center of details that he sent as a parameter earlier: vec3d(pos.x, pos.y, pos.z)
Now onto my real question, he does vec3d edge_center[3] = { (p1 + p2) / 2, (p2 + p3) / 2, (p3 + p1) / 2 }; to get the edge center of each edge, nothing weird there.
But this is used later on with:
vec3d d = center + edge_center[i]; edge_test[i] = d.len() > ratio_size; edge_test is then used to evaluate if there should be a triangle drawn or if it should be split up into 3 new triangles instead. Why is it working for him? shouldn't it be like center - edge_center or something like that? Why adding them togheter? I asume here that the center is the center of details for the LOD. the position of the camera if stood on the ground of the planet and not up int he air like it is now.

Full code can be seen here:
https://github.com/sp4cerat/Planet-LOD/blob/master/src.simple/Main.cpp
If anyone would like to take a look and try to help me understand this code I would love this person. I'm running out of ideas on how to solve this in my own head, most likely twisted it one time to many up in my head
Toastmastern

• I googled around but are unable to find source code or details of implementation.
What keywords should I search for this topic?
Things I would like to know:
A. How to ensure that partially covered pixels are rasterized?
Apparently by expanding each triangle by 1 pixel or so, rasterization problem is almost solved.
But it will result in an unindexable triangle list without tons of overlaps. Will it incur a large performance penalty?
How to ensure proper synchronizations in GLSL?
GLSL seems to only allow int32 atomics on image.
C. Is there some simple ways to estimate coverage on-the-fly?
In case I am to draw 2D shapes onto an exisitng target:
1. A multi-pass whatever-buffer seems overkill.
2. Multisampling could cost a lot memory though all I need is better coverage.
Besides, I have to blit twice, if draw target is not multisampled.

• By mapra99
Hello

I am working on a recent project and I have been learning how to code in C# using OpenGL libraries for some graphics. I have achieved some quite interesting things using TAO Framework writing in Console Applications, creating a GLUT Window. But my problem now is that I need to incorporate the Graphics in a Windows Form so I can relate the objects that I render with some .NET Controls.

To deal with this problem, I have seen in some forums that it's better to use OpenTK instead of TAO Framework, so I can use the glControl that OpenTK libraries offer. However, I haven't found complete articles, tutorials or source codes that help using the glControl or that may insert me into de OpenTK functions. Would somebody please share in this forum some links or files where I can find good documentation about this topic? Or may I use another library different of OpenTK?

Thanks!

• Hello, I have been working on SH Irradiance map rendering, and I have been using a GLSL pixel shader to render SH irradiance to 2D irradiance maps for my static objects. I already have it working with 9 3D textures so far for the first 9 SH functions.
In my GLSL shader, I have to send in 9 SH Coefficient 3D Texures that use RGBA8 as a pixel format. RGB being used for the coefficients for red, green, and blue, and the A for checking if the voxel is in use (for the 3D texture solidification shader to prevent bleeding).
My problem is, I want to knock this number of textures down to something like 4 or 5. Getting even lower would be a godsend. This is because I eventually plan on adding more SH Coefficient 3D Textures for other parts of the game map (such as inside rooms, as opposed to the outside), to circumvent irradiance probe bleeding between rooms separated by walls. I don't want to reach the 32 texture limit too soon. Also, I figure that it would be a LOT faster.
Is there a way I could, say, store 2 sets of SH Coefficients for 2 SH functions inside a texture with RGBA16 pixels? If so, how would I extract them from inside GLSL? Let me know if you have any suggestions ^^.
• By KarimIO
EDIT: I thought this was restricted to Attribute-Created GL contexts, but it isn't, so I rewrote the post.
Hey guys, whenever I call SwapBuffers(hDC), I get a crash, and I get a "Too many posts were made to a semaphore." from Windows as I call SwapBuffers. What could be the cause of this?
Update: No crash occurs if I don't draw, just clear and swap.
static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format 32, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 24, // 24Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; if (!(hDC = GetDC(windowHandle))) return false; unsigned int PixelFormat; if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) return false; if (!SetPixelFormat(hDC, PixelFormat, &pfd)) return false; hRC = wglCreateContext(hDC); if (!hRC) { std::cout << "wglCreateContext Failed!\n"; return false; } if (wglMakeCurrent(hDC, hRC) == NULL) { std::cout << "Make Context Current Second Failed!\n"; return false; } ... // OGL Buffer Initialization glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glBindVertexArray(vao); glUseProgram(myprogram); glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, (void *)indexStart); SwapBuffers(GetDC(window_handle));

• 19
• 14
• 23
• 11
• 28