I'm going insane trying to work out why I unable to draw a triangle using VAO and indexing. I have a bunch of redundant vertexes so that i can switch my index array up to test the drawing.
std::vector<glm::vec3> vertices;
//bot left
vertices.push_back(glm::vec3(-0.75,0.9,1)); //0
vertices.push_back(glm::vec3(-0.5, 0.9, 1)); //1
vertices.push_back(glm::vec3(-0.25, 0.9, 1)); //2
vertices.push_back(glm::vec3(-0.0, 0.9, 1)); //3
//mid right
vertices.push_back(glm::vec3(0.75, 0, 1)); //4
vertices.push_back(glm::vec3(0.5, 0, 1)); //5
vertices.push_back(glm::vec3(0.25, 0, 1)); //6
vertices.push_back(glm::vec3(0.0, 0, 1)); //7
//top left
vertices.push_back(glm::vec3(-0.75, -0.9, 1)); //8
vertices.push_back(glm::vec3(-0.5, -0.9, 1)); //9
vertices.push_back(glm::vec3(-0.25, -0.9, 1)); //10
vertices.push_back(glm::vec3(-0.0, -0.9, -1)); //11
The indices are simple:
GLuint indices[] = {0,5,11};
Here is how I am initialising everything:
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vbo);
glGenBuffers(1, &ivbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
&vertices[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,sizeof(glm::vec3), (void*)0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ivbo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
I am rendering with:
glUseProgram(program);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0, 0.0, 0.0, 1.0);//clear red
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, (void*)0);
glutSwapBuffers();
Vertex shader is simple as they come:
#version 430 core
layout(location = 0) in vec3 in_position;
void main(void)
{
gl_Position = vec4(in_position, 1);
}
Same with the fragment shader
#version 430 core
out vec4 color;
void main(void)
{
color = vec4(0.0, 1.0, 0.0, 1.0);
}
EDIT: Switching the z coordinate in the vertices to a negative value fixes the problem. What is going on?
sizeof(GLuint)*indiciesSize
\$\endgroup\$