Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: matrix calculations dont work

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2013
    Posts
    3

    matrix calculations dont work

    Hi,
    I'm came over a problem which I can't figure out. I want to move the camera position but nothing happens. I looked over some code examples but I still have no idea whats going wrong. Could somebody give me a hint? =/
    Thanks. =)
    Code :
    void MainWindow::display()
    {
        glUseProgram(program);
     
        //setup model matrix
        glm::mat4 model = glm::mat4(1.0f);
        model *= glm::mat4(1.0f);
     
        //setup view matrix
        glm::mat4 view = glm::mat4(1.0f);
        view *= glm::lookAt(glm::vec3(0.0f, 0.0f, 10.0f),  //eye
                            glm::vec3(0.0f, 0.0f, 0.0f),   //center
                            glm::vec3(0.0f, 1.0f, 0.0f));  //up-vector
     
        //setup projection matrix - [fovy, aspect, zNear, zFar]
        glm::mat4 projection = glm::mat4(1.0f);
        projection *= glm::perspective(45.0f, 1.0f, 0.1f, 20.0f);
     
        //calculate matrix
        glm::mat4 vertrexTransform = projection * view * model;
     
        //send our matrices to the shader
        glUniformMatrix4fv(glGetUniformLocation(program, uniform_mvp), 1, GL_FALSE, glm::value_ptr(vertrexTransform));
     
        glClearColor(0.0, 0.0, 0.0, 1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glEnableVertexAttribArray(verticesLocation);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
        glDrawArrays(GL_TRIANGLES, 0, 3);
        glDisableVertexAttribArray(verticesLocation);
        glutSwapBuffers();
    }

    GLSL:
    Code :
    #version 330
    in vec3 vertices;
    uniform mat4 ModelViewProjectionMatrix;
    void main(void)
    {
        gl_Position = ModelViewProjectionMatrix * vec4(vertices, 1.0);
    }

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2013
    Posts
    3
    nobody? =/

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,224
    Are you checking for GL errors?

    Have you dumped the value of the matrix you're populating the uniform with to verify that it looks reasonable?

    If you're stumped, cook a short stand-alone GLUT test program and post it. Usually in the process of doing that, you'll discover your bug.

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2013
    Posts
    3
    There are no error. In my code I am checking if the shader and program are correctly and if I there was some problems with getting my attribute. But everything seems correct.

    I started with that tutorial 1 from wikibooks ( http://en.wikibooks.org/wiki/OpenGL_...L_Introduction ). So I went back to that code and modified it with the glm code. And surprisingly everything works fine. But I really can't find any difference in my display method.

    If you look you can see that the display methode in mainwindow.cpp is not very different from the method in tutorial01.cpp.
    I only wanted to split some parts for a better overview =/

    mainwindow.cpp
    http://pastebin.com/Gj5dS3mC
    shaderutilities.cpp
    http://pastebin.com/v6KPvCmq

    Works fine.
    tutorial01.cpp
    http://pastebin.com/XLk3DWqg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •