Confusion about the world matrix in GL.

Started by
8 comments, last by EngineCoder 13 years, 6 months ago
I have got used to the mechanism in Direcrx, where there is a world matrix.

But in gl there is only the modelview and project.

So what if I want to implement the basic pixel lighting in the shader, and all the vertex should be first translated into the world space(the approach I took in DX), and then use the blinn phone to calculate the color of each pixel.

But now in GL, there is no world matrix...How do I do this? directly compute the light in the view space??(I assume after applying modelview transform we are in the view space right?)

Pls help me, I'm a tyro..
Advertisement
In opengl 3+ there isn't any set matrix. You pass whatever you want to the shaders. You can split it up into seperate projection*camera*model matrices, or combine them to save compute time in the shaders.
You just upload the matricies you want to the shader as a glUniform.

Quote:Original post by KulSeran
In opengl 3+ there isn't any set matrix. You pass whatever you want to the shaders. You can split it up into seperate projection*camera*model matrices, or combine them to save compute time in the shaders.
You just upload the matricies you want to the shader as a glUniform.


I know with the shader I can make whatever I want.

But I dont have any matrix library. And it bothers me to write one.

Is there any matrix library availale???

And, what do u mean by the "gl 3+ dont have any set matrix"?
Do u mean there is no glMatrixMode() func anymore??

And I'm confused about the gl version too.
My vedio card driver support the gl 3.3.
Does that mean I'm already using gl 3.3??Or do I need to do something special?

I do use the matrix set function in my code though, does that mean my version is not 3.3??
Also, I've read that the matrix in GL is quiet different from that in DX...

The GL matrix is the transpose of that in DX if I'm not mistaken...How do I solve this??
First, I'd take a look here here. That guy is doing a decent job introducing OpenGL 3.x.

Quote:
But I dont have any matrix library. And it bothers me to write one.

OpenGL doesn't have a matrix library like DirectX does.

Quote:
And, what do u mean by the "gl 3+ dont have any set matrix"?
Do u mean there is no glMatrixMode() func anymore??

OpenGL 3.2 Quick Reference Card
All the glMatrixMode, glLoadMatrix, etc. functions are depricated and won't work in OpenGL 3.x code.

Quote:
Does that mean I'm already using gl 3.3??Or do I need to do something special?

Getting started. Mostly you just need the right graphics drivers installed. If your compiler didn't come with an up-to-date OpenGL header file, you may have to download one (links to useful stuff on that page).

Quote:
I do use the matrix set function in my code though, does that mean my version is not 3.3??

What type of OpenGL context did you make? You can make backwards compatable contexts or pure OpenGl 3.x contexts. (again, on that getting started page to see the difference).

Quote:
Also, I've read that the matrix in GL is quiet different from that in DX...
The GL matrix is the transpose of that in DX if I'm not mistaken...How do I solve this??

They are layed out in memory in exactly the same way. In OpenGL your transforms in your shaders should look like:
new_vertex = perspective * view * model * old_vertex;
Quote:I know with the shader I can make whatever I want.

But I dont have any matrix library. And it bothers me to write one.

Is there any matrix library availale???
Not sure what language you're using, but there are plenty of free math libraries available. You can find a list here (look under 'Mathematics').
Quote:And, what do u mean by the "gl 3+ dont have any set matrix"?
Do u mean there is no glMatrixMode() func anymore??
I'm not sure which version it was (or will be) actually removed in, but yes, the matrix stack is deprecated.
Quote:Also, I've read that the matrix in GL is quiet different from that in DX...

The GL matrix is the transpose of that in DX if I'm not mistaken...How do I solve this??
They're not very different.

I don't know all the details of GLSL, and I suppose it might be possible that you'd have to transpose your matrices at some point, depending (I'm really not sure about that though).

When using the fixed-function pipeline though, it's actually not necessary to transpose matrices between DX and OpenGL. Sometimes when people talk about transposing matrices between one API and the other, they're just referring to notation (in that OpenGL documentation and examples typically are written using column-vector notation, and the DirectX math library uses row-vector notation.)

However, matrices are actually laid out in memory the same way for both APIs (again, assuming we're talking about the fixed-function pipeline), so no transposition is necessary when going back and forth.

The only other intrinsic difference I can think of right now is that D3D and OpenGL use different conventions for the z clipping range of the canonical view volume, which means that projection matrices are generally set up a little differently between the two APIs. Other than that though, you should be able to use the same matrices with both APIs (again, with the possibility that you may have to transpose your matrices at some point, but I haven't done enough work with GLSL to comment on that directly).
Quote:Original post by shiqiu1105
But I dont have any matrix library. And it bothers me to write one.

Is there any matrix library availale???


GLM is a decent matrix library, though sparse on documentation.
Thanks for the elaboration...

What about the newly released "gl3.h" though?
Does it have anything to do with using gl 3.3??

And I've also noticed that the function in gl 3.3 has changed..

glVertex() --> Vertex()

Does it mean I have to rewrite my code??

And I've been used to use CG as my shading language, is it compatible with gl 3.3???
This site has a great OpenGL 3.x - 4 tutorial. At the moment the tutorial covers setting up a window, shaders and the matices.
I guess the next tutorial will cover VBO's and so on.
Quote:Original post by shiqiu1105
Thanks for the elaboration...

What about the newly released "gl3.h" though?
Does it have anything to do with using gl 3.3??

And I've also noticed that the function in gl 3.3 has changed..

glVertex() --> Vertex()

Does it mean I have to rewrite my code??

And I've been used to use CG as my shading language, is it compatible with gl 3.3???


OpenGL 3.3 core profile doesn't have glVertex(). Also, the OpenGL spec doesn't put "gl" in front of function names, so when the spec says Vertex() it's really glVertex().
My iOS 3D action/hacking game: http://itunes.apple....73873?ls=1&mt=8
Blog

This topic is closed to new replies.

Advertisement