PDA

View Full Version : matrix calculations dont work



crumbly
02-22-2013, 01:28 PM
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. =)

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:

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

crumbly
02-23-2013, 08:32 AM
nobody? =/

Dark Photon
02-23-2013, 04:55 PM
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.

crumbly
02-24-2013, 10:58 AM
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_Programming/Modern_OpenGL_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