I've been setting up a new context for some time now. And I finally seem to get to grips with it. However, I can't render anything in my window, which is quite crippling...
I'm loading an OBJ into vectors and load that information into a couple of VBO's for texccords, vertex position, normals and a vector for indices.
I know for a fact that the code I'm using is functional under lower contexts and I just can't get it to work in the new one.
I'm thinking that it's got something to do with using my own matrices and how the shaders are set up... but I can't figure it out.
My render function:
void cOpenGLContext::renderScene(void) { glViewport(0, 0, windowWidth, windowHeight); // set the viewport to fill the entire window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // clear required buffers viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -5.0f)); // create our view matrix which will translate us back 5 units modelMatrix = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f));// create our model matrix which will halve the size of our model shader->bind(); int projectionMatrixLocation = glGetUniformLocation(shader->id(), "projectionMatrix"); // get the location of our projection matrix in the shader int viewMatrixLocation = glGetUniformLocation(shader->id(), "viewMatrix"); // get the location of our view matrix in the shader int modelMatrixLocation = glGetUniformLocation(shader->id(), "modelMatrix"); // get the location of our model matrix in the shader glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, &projectionMatrix[0][0]);// send our projection matrix to the shader glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]); // send our view matrix to the shader glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]); // send our model matrix to the shader // rest of render function here // VBO [start] // drawing glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); // vertex buffer glBindBuffer(GL_ARRAY_BUFFER, earth.vBufferObject); glVertexPointer(3, GL_FLOAT, 0, 0); // texture buffer glBindBuffer(GL_ARRAY_BUFFER, earth.tBufferObject); glTexCoordPointer(3, GL_FLOAT, 0, 0); // normal buffer glBindBuffer(GL_ARRAY_BUFFER, earth.nBufferObject); glNormalPointer(GL_FLOAT, 0, 0); // index buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, earth.iBufferObject); // draws it all glDrawElements(GL_TRIANGLES, earth.vFaces.size(), GL_UNSIGNED_INT, 0); // unbinds the buffers glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); // drawing end shader->unbind(); SwapBuffers(hdc); // swap buffers so we can see our rendering}
My shaders
// vert#version 150 corein vec3 in_Position;in vec3 in_Color;out vec3 pass_Color;uniform mat4 projectionMatrix;uniform mat4 viewMatrix;uniform mat4 modelMatrix;void main(void) { gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(in_Position, 1.0); pass_Color = in_Color;}// frag#version 150 corein vec3 pass_Color;out vec4 out_Color;void main(void) { out_Color = vec4(pass_Color, 1.0);}
Can anyone see what I'm doing wrong? I'm going blind, staring at this code.
Thanks!
Marcus