Relevant code:
VBO / Index data
struct Vertex {
GLfloat XYZW[4];
GLfloat RGBA[4];
};
//create some data for the vbo
Vertex Vertices[] =
{
{ { 0.0f, 0.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f, 1.0f } },
// Top
{ { -0.2f, 0.8f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
{ { 0.2f, 0.8f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } },
{ { 0.0f, 0.8f, 0.0f, 1.0f }, { 0.0f, 1.0f, 1.0f, 1.0f } },
{ { 0.0f, 1.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
// Bottom
{ { -0.2f, -0.8f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } },
{ { 0.2f, -0.8f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
{ { 0.0f, -0.8f, 0.0f, 1.0f }, { 0.0f, 1.0f, 1.0f, 1.0f } },
{ { 0.0f, -1.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
// Left
{ { -0.8f, -0.2f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
{ { -0.8f, 0.2f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } },
{ { -0.8f, 0.0f, 0.0f, 1.0f }, { 0.0f, 1.0f, 1.0f, 1.0f } },
{ { -1.0f, 0.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
// Right
{ { 0.8f, -0.2f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } },
{ { 0.8f, 0.2f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
{ { 0.8f, 0.0f, 0.0f, 1.0f }, { 0.0f, 1.0f, 1.0f, 1.0f } },
{ { 1.0f, 0.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } }
};
//create some indices
unsigned int Indices[] = {
// Top
0, 1, 3,
0, 3, 2,
3, 1, 4,
3, 4, 2,
// Bottom
0, 5, 7,
0, 7, 6,
7, 5, 8,
7, 8, 6,
// Left
0, 9, 11,
0, 11, 10,
11, 9, 12,
11, 12, 10,
// Right
0, 13, 15,
0, 15, 14,
15, 13, 16,
15, 16, 14
};
How I create my projection matrix
void Renderer::enableProjectionMode(ProjectionMode _mode) {
switch(_mode) {
case Perspective:
myProjectionMatrix = glm::perspective(
myViewportFOV,
(float)myViewportDimensions.x / (float)myViewportDimensions.y,
-1.0f, 100.0f);
break;
case Orthogonal:
myProjectionMatrix = glm::ortho(
-myViewportDimensions.x / 2, myViewportDimensions.x / 2,
myViewportDimensions.y / 2, -myViewportDimensions.y / 2,
-1.0f, 1.0f);
break;
}
myProjectionMode = _mode;
}
How I update the matrices in the shaders
myProgram->bind();
myProgram->setUniformMatrix4fv("ProjectionMatrix", 1, false, &myProjectionMatrix[0][0]); //these are all just simple wrappers, they do the same thing as the underlying GL calls
myProgram->setUniformMatrix4fv("ModelMatrix", 1, false, &myModelMatrix[0][0]);
myProgram->setUniformMatrix4fv("ViewMatrix", 1, false, &myViewMatrix[0][0]);
I can post the shaders if it really is necessary, but they're unbelievably simple. You could probably guess the contents
Am I missing something in the above that's causing the projection matrix to not be created correctly? I've been looking for hours and can't find a single thing.