Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL 3.2 trouble setting up matrices
    primarykey
    data
    text
    <p>I am using GLM to manage my matrices, but I am running in to some problems that make no sense to me. When I set the projection matrix to anything other than an identity matrix, I can't see the square I am trying to draw. If it is an identity it will work. Something similiar happens with my view matrix. If I try and translate past -1 or +1 the square will dissapear, otherwise it seems to have no effects.</p> <p>There are no OpenGL errors, GLSL linker/compiler errors, and glGetUniformLocation returns a valid location. Also the shader program is correctly being used.</p> <p>Also I have tested the shader to see if it is getting the correct values passed to each of the matrices (by changing the color of the square if the value is correct).</p> <p>Here's how I set up the projection matrix:</p> <pre><code>projectionMatrix = glm::perspective(60.0f, (float)windowWidth / (float)windowHeight, 0.1f, 100.0f); </code></pre> <p>And here's my draw function:</p> <pre><code>void OpenGLContext::render(void) { glViewport(0, 0, windowWidth, windowHeight); // Set the viewport size to fill the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Clear required buffers //Set up matrices viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -5.0f)); modelMatrix = glm::scale(glm::mat4(1.0f), glm::vec3(.5f)); shader-&gt;bind(); int projectionMatrixLocation = glGetUniformLocation(shader-&gt;id(), "projectionMatrix"); int viewMatrixLocation = glGetUniformLocation(shader-&gt;id(), "viewMatrix"); int modelMatrixLocation = glGetUniformLocation(shader-&gt;id(), "modelMatrix"); glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, &amp;projectionMatrix[0][0]); glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &amp;viewMatrix[0][0]); glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &amp;modelMatrix[0][0]); glBindVertexArray(vaoID[0]); glDrawArrays(GL_TRIANGLES, 0, 6); glBindVertexArray(0); shader-&gt;unbind(); SwapBuffers(hdc); </code></pre> <p>} </p> <p>Here's the shader.vert</p> <pre><code>#version 150 core uniform mat4 projectionMatrix; uniform mat4 viewMatrix; uniform mat4 modelMatrix; in vec3 in_Position; in vec3 in_Color; out vec3 pass_Color; void main(void) { gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(in_Position, 1.0); pass_Color = in_Color; } </code></pre> <p>Here's shader.frag</p> <pre><code>#version 150 core uniform mat4 projectionMatrix; uniform mat4 viewMatrix; uniform mat4 modelMatrix; in vec3 pass_Color; out vec4 out_Color; void main(void) { out_Color = vec4(pass_Color, 1.0); } </code></pre> <p>Sorry forgot about what i'm drawing:</p> <pre><code>void OpenGLContext::createSquare(void) { float* vertices = new float[18]; vertices[0] = -0.5; vertices[1] = -0.5; vertices[2] = 0.0; // Bottom left corner vertices[3] = -0.5; vertices[4] = 0.5; vertices[5] = 0.0; // Top left corner vertices[6] = 0.5; vertices[7] = 0.5; vertices[8] = 0.0; // Top Right corner vertices[9] = 0.5; vertices[10] = -0.5; vertices[11] = 0.0; // Bottom right corner vertices[12] = -0.5; vertices[13] = -0.5; vertices[14] = 0.0; // Bottom left corner vertices[15] = 0.5; vertices[16] = 0.5; vertices[17] = 0.0; // Top Right corner glGenVertexArrays(1, &amp;vaoID[0]); glBindVertexArray(vaoID[0]); glGenBuffers(1, vboID); glBindBuffer(GL_ARRAY_BUFFER, vboID[0]); glBufferData(GL_ARRAY_BUFFER, 18 * sizeof(GLfloat), vertices, GL_STATIC_DRAW); glVertexAttribPointer((GLuint) 0, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); // Disable our Vertex Array Object glBindVertexArray(0); delete [] vertices; } </code></pre> <p>Setting my matrices like this results in nothing being drawn on the screen. Like I said if I set the projection and view matrices to an identity it will work. The scaling on the modelMatrix seems to always work as well.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload