PDA

View Full Version : Adds unwanted vertex at origin



Ploppz
12-04-2015, 08:27 AM
Solved: I should be rendering 5 indices, not 10.

I'm trying to draw a pentagon using TRIANGLE_FAN. I switched to LINE_LOOP for better illustration.

This is the exact contents of std::vector<float> triangle_buffer;:
130
0
40.1722
-123.637
-105.172
-76.4121
-105.172
76.4121
40.1722
123.637

However, the results are unexpected: the first vertex is always at origin, before the other 5 vertices in the buffer:
2195

Here's the code for uploading this buffer:


glUseProgram(pos2_program);
// Upload triangles
// triangles_vbo = uploadVertices(triangle_buffer.data(), triangle_buffer.size() * sizeof(float));
glGenBuffers(1,&triangles_vbo);
glBindBuffer(GL_ARRAY_BUFFER, triangles_vbo);
glBufferData(GL_ARRAY_BUFFER, triangle_buffer.size() * sizeof(float), triangle_buffer.data(), GL_STATIC_DRAW);

I draw like this:

glBindBuffer(GL_ARRAY_BUFFER, triangles_vbo);
glDrawArrays(GL_LINE_LOOP, 0, 10);

I really don't understand what can be wrong..