Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


gluLookAt() and matrix stack operations deprecated?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 26 April 2014 - 05:02 AM

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?



Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 9470

Like
4Likes
Like

Posted 26 April 2014 - 05:25 AM

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.



#3 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 26 April 2014 - 06:48 AM

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);


#4 Aks9   Members   -  Reputation: 1088

Like
0Likes
Like

Posted 26 April 2014 - 07:30 AM

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. :)

...



#5 ProtectedMode   Members   -  Reputation: 1335

Like
1Likes
Like

Posted 26 April 2014 - 08:13 AM

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)


#6 mhagain   Crossbones+   -  Reputation: 9864

Like
3Likes
Like

Posted 26 April 2014 - 08:39 AM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#7 OandO   Members   -  Reputation: 1057

Like
0Likes
Like

Posted 26 April 2014 - 09:26 AM

1) Take a look at this, you may find it helpful: http://www.gamedev.net/topic/651583-correct-glulookat-clone/



#8 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 26 April 2014 - 06:35 PM

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, 26 April 2014 - 06:41 PM.


#9 Brother Bob   Moderators   -  Reputation: 9470

Like
3Likes
Like

Posted 26 April 2014 - 07:06 PM

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.



#10 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 26 April 2014 - 07:29 PM

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? 



#11 OandO   Members   -  Reputation: 1057

Like
3Likes
Like

Posted 26 April 2014 - 08:28 PM

Model space (or object space, to give it its usual name) positions in the buffer makes perfect sense. Consider the buffer to be the object in and of itself, and the vertex shader to be instructions for viewing it. Obviously that's a very simple version and the vertex shader can do a lot more, but it's a solid starting point.


Edited by OandO, 26 April 2014 - 08:29 PM.


#12 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 26 April 2014 - 11:39 PM

I'm understanding more, thank you guys.

 

I have a couple important questions that would really help me understand these model, view, and proj matrices so i can construct them myself:

 

(i) In response to "OandO", if i provide object space data to the buffers, like a triangle for example:

float vertices1[] = {   -1.0f, 0.0f, 0.0f, 1.0f,
            1.0f, 0.0f, 0.0f, 1.0f,
            0.0f, 2.0f, 0.0f, 1.0f};

which is later sent to a VAO:

    glGenVertexArrays(3, vao);
    //
    // VAO for first triangle
    //
    glBindVertexArray(vao[0]);
    // Generate two slots for the vertex and color buffers
    glGenBuffers(2, buffers);
    // bind buffer for vertices and copy data into buffer
    glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices1), vertices1, GL_STATIC_DRAW);
    glEnableVertexAttribArray(vertexLoc);
    glVertexAttribPointer(vertexLoc, 4, GL_FLOAT, 0, 0, 0);

How would i move the triangle 5 pixels into the screen(glTranslatef(0.0,0.0,-5.0);) in non-deprecated terms? Because if i alter the "vertices1" vertices to add -5.0 in the z-component(push triangle further back), isn't that changing the vertices from object->world space?

 

(ii) Does a ModelViewProjection 4v4 matrix exist such that any vertex position data for any object sent into a VAO/VBO multiplied by this ModelViewProjection 4v4 will give you that vertex position in world space?

 

Thank you again guys.


Edited by Shawn619, 26 April 2014 - 11:57 PM.


#13 Brother Bob   Moderators   -  Reputation: 9470

Like
3Likes
Like

Posted 27 April 2014 - 03:48 AM

I'm understanding more, thank you guys.
 
I have a couple important questions that would really help me understand these model, view, and proj matrices so i can construct them myself:
 
(i) In response to "OandO", if i provide object space data to the buffers, like a triangle for example:

float vertices1[] = {   -1.0f, 0.0f, 0.0f, 1.0f,
            1.0f, 0.0f, 0.0f, 1.0f,
            0.0f, 2.0f, 0.0f, 1.0f};
which is later sent to a VAO:
    glGenVertexArrays(3, vao);
    //
    // VAO for first triangle
    //
    glBindVertexArray(vao[0]);
    // Generate two slots for the vertex and color buffers
    glGenBuffers(2, buffers);
    // bind buffer for vertices and copy data into buffer
    glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices1), vertices1, GL_STATIC_DRAW);
    glEnableVertexAttribArray(vertexLoc);
    glVertexAttribPointer(vertexLoc, 4, GL_FLOAT, 0, 0, 0);
How would i move the triangle 5 pixels into the screen(glTranslatef(0.0,0.0,-5.0);) in non-deprecated terms? Because if i alter the "vertices1" vertices to add -5.0 in the z-component(push triangle further back), isn't that changing the vertices from object->world space?

(ii) Does a ModelViewProjection 4v4 matrix exist such that any vertex position data for any object sent into a VAO/VBO multiplied by this ModelViewProjection 4v4 will give you that vertex position in world space?
 
Thank you again guys.

 

That is what has been stated above already. Create a translation matrix using the vector library you use as a replacement for OpenGL's previously built in functions, load it into the shader, and multiply your vertices by the matrix from the shader.

 

I don't have the possibility to try the code and writing from the top of my head, so take it for pseudo-code.

 

Your OpenGL code (creating the matrix and loading it to the shader):

glm::mat4 mv_matrix = glm::translate(0, 0, -5);
 
GLint mvm_location = glGetUniformLocation(your program handle, "mv_matrix");
glUniformMatrix4fv(mvm_location, mv_matrix);

 

Your shader (multiplying your own model view matrix and the vertex):

in vec3 v_coord;
uniform mat4 mv_matrix:

void main() {
     gl_Position = mv_matrix*v_coord;
}


#14 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 27 April 2014 - 04:53 AM

Thanks Brother Bob.



#15 Gooey   Members   -  Reputation: 1023

Like
0Likes
Like

Posted 30 April 2014 - 06:56 AM

glGenVertexArrays(3, vao);

Why are you creating 3 VAO's to display 1 triangle?

Your OpenGL code (creating the matrix and loading it to the shader):

glm::mat4 mv_matrix = glm::translate(0, 0, -5);

GLint mvm_location = glGetUniformLocation(your program handle, "mv_matrix");
glUniformMatrix4fv(mvm_location, mv_matrix);

glm::mat4 model(1.0f);
model = glm::translate(model, glm::vec3(0.0f, 0.0f, -5.0f));
MVP = viewProjectionMat * model;glUseProgram(program);
glUniformMatrix4fv(MVPLoc, 1, GL_FALSE, glm::value_ptr(MVP));
glUseProgram(0);
Im sure there isnt a glm::translate which doesnt take a glm::mat4 and
glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);

Edited by Gooey, 30 April 2014 - 07:22 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS