Question

I am trying to implement a simple shader program and render a set of vertices and a strange error occur:

enter image description here

Is this something regarding the depth buffer? I think I had a similar problem before.

Inside my draw method:

// Parameters: GLdouble* vertices, int num_vertices;
Gluint vboId;
glGenBuffers(1,&vboId);
glBindBuffer(GL_ARRAY_BUFFER,vboId);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLdouble) * num_vertices * 3, vertices, GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER,vboId);
glVertexPointer(3,GL_DOUBLE,0,NULL);
glEnableClientState(GL_VERTEX_ARRAY);

glUseProgram(shaderProgramId);
glDrawArrays(GL_TRIANGLES,0,num_vertices);



// Shader program

// Vertex
void main(void) {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

// Fragment
void main(void) {
gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
Was it helpful?

Solution

I was drawing without indice and the model needed indices. As @Bart said in comments.

To fix this issue, I call:

glDrawElements(GL_TRIANGLES,num_indices * 3, GL_UNSIGNED_INT, indices);

instead of:

glDrawArrays(GL_TRIANGLES,0,num_vertices);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top