gluLookAt() and matrix stack operations deprecated?

Started by
13 comments, last by Gooey 9 years, 11 months ago

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.

Advertisement

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.

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

Thanks Brother Bob.

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

This topic is closed to new replies.

Advertisement