Jump to content
  • Advertisement
Sign in to follow this  
Shawn619

OpenGL gluLookAt() and matrix stack operations deprecated?

This topic is 1544 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a couple question about some opengl deprecated functionality and it's replacements:

 

1.) I'm told gluLookAt() is deprecated in 3.0. What do i use as it's replacement? Do i multiply a camera rotation matrix by the view matrix to get the new view matrix?

 

2.) My understanding was that OpenGL works with a 32 stack of 4x4 ModelView matrices. If i can't push and pop matrices anymore and vertex data is in a VAO, then there is absolutely no point in 32 stacks and it mine as well be 1 ModelView matrix?

Share this post


Link to post
Share on other sites
Advertisement

All matrix operations and everything that came with it, such as the stack, are all gone. There's not even anything called a model view matrix in OpenGL anymore. You have to manage all matrices yourself now and load them to your shaders as necessary.

Share this post


Link to post
Share on other sites

Do you have a sample program code by chance or can tell me how i could manage model, view, and proj matrix? It seems like 99% of opengl tutorial code on the web is using functionality that was deprecated years before they published the tutorial.

 

Could i get the MVP matrices like so, then send modelview[16] to the shader:

float modelview[16];
glGetFloatv(GL_MODELVIEW_MATRIX, modelview);

Share this post


Link to post
Share on other sites

I have a couple question about some opengl deprecated functionality and it's replacements:

 

1.) I'm told gluLookAt() is deprecated in 3.0. What do i use as it's replacement? Do i multiply a camera rotation matrix by the view matrix to get the new view matrix?

 

2.) My understanding was that OpenGL works with a 32 stack of 4x4 ModelView matrices. If i can't push and pop matrices anymore and vertex data is in a VAO, then there is absolutely no point in 32 stacks and it mine as well be 1 ModelView matrix?

 

1) Vast amount of legacy OpenGL functions is deprecated, not just matrix manipulation.

 

2) Vertex data is not stored in VAO, but in VBO. VAO stores client state (which attributes are enabled, offsets, etc.). A stack of model-view or projection matrices are still useful, but YOU have to implement them if you need them.

 

 

Do you have a sample program code by chance or can tell me how i could manage model, view, and proj matrix? It seems like 99% of opengl tutorial code on the web is using functionality that was deprecated years before they published the tutorial.

 

Could i get the MVP matrices like so, then send modelview[16] to the shader:

float modelview[16];
glGetFloatv(GL_MODELVIEW_MATRIX, modelview);

 

No, you cannot do that! Because functions that sets legacy model-view (top) matrix are deprecated as well. There is a plenty of modern OpenGL tutorials. Just google for them. :)

...

Share this post


Link to post
Share on other sites

You can use uniforms to pass the MVP matrix. I recommend you read a tutorial like this one on modern OpenGL. I also recommend using a math library like GLM which provides functions like lookAt except if you like writing this functionality yourself. For example:

glm::perspective(angle, ratio, near, far) * glm::lookAt(position, target, up)

Share this post


Link to post
Share on other sites

At this stage it's important to add:

 

While the functionality had been officially deprecated, that doesn't mean that it's stopped working!

 

For the most part you can continue using it and it will continue working just as before.  The exception is if you create a "core context" which only supports the non-deprecated functionality, but all drivers will by default give you a "compatibility context", which fully supports it.

 

In other words: unless you explicitly ask for it to not be available, you can continue using it.

 

This seems similar to when Microsoft announced that they weren't providing any more updates to XNA and the internet was full of whining as if XNA had suddenly stopped working.  Yayy internet.  That's not the case at all.

 

Now, it's necessary for me to temper that with a healthily-sized dose of "just because you can doesn't mean that you should" (because yayy internet again).  The old matrix stack and GLU functions were never anything more than a software matrix library, so if you want a replacement for them, the answer is simple: find and use a software matrix library (glm seems to be a popular choice).

 

But unless you need to stop using the old stuff, there's no reason to not continue using it.

 

Again - yayy internet - that doesn't mean I'm advocating it's use.  Just that I'm conscious that porting existing code from old to new (anything, not just GL) can be a very large job, and often has minimal benefit.  All new programs should just use the new stuff.

Share this post


Link to post
Share on other sites

I see, i see.

 

I have a couple last questions:

 

 

(i) Since i feed vertex position in eye space into the VAO/VBO, instead of model space vertex position through glBegin->glVertex3f->glEnd, does this mean, in my vertex shader, i no longer need to transform the received vertex from model->eye space like so:

void main() {
 
    gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
}

and i can instead do the following since im passing in eye space vertex positions to thee vertex shader?:

attribute vec4 v_coord;
attribute vec3 v_normal;
 
void main() {
 
    gl_Position = v_coord;
}

(ii) I know i have to control the MVP matrices myself, then send them to the shader. When do i change the Model matrix? Because in legacy opengl, the Model matrix was changed with every glTranslate or glRotate call.

Edited by Shawn619

Share this post


Link to post
Share on other sites

I see, i see.
 
I have a couple last questions:
 
 
(i) Since i feed vertex position in eye space into the VAO/VBO, instead of model space vertex position through glBegin->glVertex3f->glEnd, does this mean, in my vertex shader, i no longer need to transform the received vertex from model->eye space like so:

void main() {
 
    gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
}
and i can instead do the following since im passing in eye space vertex positions to thee vertex shader?:
attribute vec4 v_coord;
attribute vec3 v_normal;
 
void main() {
 
    gl_Position = v_coord;
}

If you're passing eye-space coordinates then you shouldn't do anther model-to-eye space transformation because your vertices are already in eye-space. But that also implies that you're doing your transformations manually instead of doing them in the shader. If you want to do the equivalent operations to the legacy model, you need to pass the projection and modelview matrices to your shader, pass model-space vertices, and do the transformations in there but with your own uniform variables instead of the built in gl-uniforms.

 

(ii) I know i have to control the MVP matrices myself, then send them to the shader. When do i change the Model matrix? Because in legacy opengl, the Model matrix was changed with every glTranslate or glRotate call.

You should upload the matrix to the shader program when you have composed all the necessary transformations. If you have a translation and a rotation, then combine them and load the final matrix to the shader.

Share this post


Link to post
Share on other sites

Sorry for all the questions.

 

Do i send eye-space vertex positions in the VAO/VBO? Because model-space vertex positions in the VAO/VBO wouldn't make sense, right? 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!