Hello. I'm trying to incorporate VBOs and shaders into my OpenGL application but when I run it, all I get is a black screen. The shader program gets linked fine, and using glGetProgramiv() everything seems to be fine -- shaders attached, uniforms active, etc. I also checked for OpenGL erros and it was absent of errors. I also know that my projection matrix is set up correctly, I`ve used it before. I can't seem to figure out what the problem is. I would appreciate greatly if someone could look at my shaders and the code to create the VBO. Thanks.
Vertex Shader
#version 130
uniform mat4 projectionMatrix;
uniform mat4 modelviewMatrix;
in vec4 in_vertex;
void main() {
gl_Position = projectionMatrix * modelviewMatrix * in_vertex;
}
Fragment Shader (yes I realize gl_FragColor is deprecated)
#version 130
void main() {
gl_FragColor = vec4(0.8, 0.0, 0.6, 1.0);
}
VBO Setup
void drawTriangle() {
const unsigned int numVertices = 3;
const unsigned int numIndices = 3;
//Vertex Data
Vertex vertices[numVertices];
vertices[0].pos = Vector3(0.0, 32.0, -128.0);
vertices[1].pos = Vector3(-32.0, -32.0, -128.0);
vertices[2].pos = Vector3(32.0, -32.0, -128.0);
//Index Data
unsigned int indices[numIndices];
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
//Create VAO
unsigned int vaoID = 0;
glGenVertexArrays(1, &vaoID);
glBindVertexArray(vaoID);
//Create a VBO to hold the vertex data
unsigned int vboID = 0;
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, numVertices * sizeof(Vertex), vertices, GL_STATIC_DRAW);
//Setup attributes
//vertex is 3 doubles for pos, 3 doubles for norm, 2 doubles for tex, 4 doubles for col
glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, sizeof(Vertex), (void*)0);
glVertexAttribPointer(1, 3, GL_DOUBLE, GL_FALSE, sizeof(Vertex), (void*)24);
glVertexAttribPointer(2, 2, GL_DOUBLE, GL_FALSE, sizeof(Vertex), (void*)48);
glVertexAttribPointer(3, 4, GL_DOUBLE, GL_FALSE, sizeof(Vertex), (void*)64);
glEnableVertexAttribArray(0);
//glEnableVertexAttribArray(1);
//glEnableVertexAttribArray(2);
//glEnableVertexAttribArray(3);
//Create a VBO to hold the index data
unsigned int vboIndicesID = 0;
glGenBuffers(1, &vboIndicesID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices * sizeof(unsigned int), indices, GL_STATIC_DRAW);
//Unbind the VAO
glBindVertexArray(0);
//Draw
glBindVertexArray(vaoID);
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, (void*)0);
}