samedi 25 juin 2016
Why does my triangle not display after being transformed by glm::lookAt matrix?
I'm trying to display my triangle from different camera viewpoints. To do this, I'm using the glm::lookAt() function which creates a 4x4 matrix that you can use to transform your points. This seems to be working fine and as intended when I specify a camera position (arg1) where x, y, and z are all <= 1.0 such as view = glm::lookAt(glm::vec3(0.0, 0.0f, 1.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));.
However, if I specify a camera position such as view = glm::lookAt(glm::vec3(0.0, 0.0f, 2.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); where the camera is a little farther back it doesn't display the shape at all. Why is this the case, in all the tutorials I am following the shape still displays?
My draw code (in a loop) :
//bind buffers and stuff
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glm::mat4 view;
view = glm::lookAt(glm::vec3(2.0, 1.0f, 1.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
GLint viewLoc = glGetUniformLocation(sp, "view");
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
My vertex shader code: (Note: in a string and loaded from this string)
const char* vertexShaderData =
"#version 450 n"
"layout(location = 0) in vec3 vp;"
"layout(location = 1) in vec3 color;"
"layout (location = 2) in vec2 texCoord;n"
"out vec3 Color;"
"out vec2 TexCoords;n"
"uniform mat4 view;n"
"void main(){"
"Color=color;"
"TexCoords = texCoord;"
"gl_Position = view * vec4(vp, 1.0);"
"}";
Points data: (first 3 floats in each line are the actual verticies)
static GLfloat data[] = {
0.75f, 0.75f, 0.0f, 1.0f, 0.0f, 0.0f, 0.75f, 0.75f,
0.75f, -0.75f, 0.0f, 0.0f, 1.0f, 0.0f, 0.75f, -0.75f,
-0.75f, -0.75f, 0.0f, 0.0f, 0.0f, 1.0f, -0.75f, -0.75f,
-0.75f, 0.75f, 0.0f, 1.0f, 0.0f, 0.0f, -0.75f, 0.75f,
-0.75f, -0.75f, 0.0f, 0.0f, 1.0f, 0.0f, -0.75f, -0.75f,
0.75f, 0.75f, 0.0f, 0.0f, 0.0f, 1.0f, 0.75f, 0.75f,
};
I know everything else is working btw, shaders both are working/linked. Normal transformations with roation/translation matrices are working. Without any transformations, the shapes are being drawn correctly.
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire