PDA

View Full Version : understanding GL_LINES

DanUK
11-21-2011, 10:42 AM
Hi,

Im having some troble figuring out why I cant seem to draw triangles with GL_LINES, I feel as though I am very close with the code below:

void DrawWireframe()
{
int i = 0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_LINES);
glColor3f(1.0, 1.0, 0.0);
//for (int i = 0; i < nbTriangles; i++)
//{
glVertex3f(vertices[triangles[i*3]*3], vertices[triangles[i*3]*3+1], vertices[triangles[i*3]*3+2]);
glVertex3f(vertices[triangles[i+1*3]*3], vertices[triangles[i+1*3]*3+1], vertices[triangles[i+1*3]*3+2]);
glVertex3f(vertices[triangles[i+2*3]*3], vertices[triangles[i+2*3]*3+1], vertices[triangles[i+2*3]*3+2]);
glVertex3f(vertices[triangles[i*3]*3], vertices[triangles[i*3]*3+1], vertices[triangles[i*3]*3+2]);
//}
glEnd();
}

Im trying to draw the wire frame of the standford bunny from its .ply format. The triangles array contains the index for the vertex of each each triangle, and vertices contains the vertexs. I've commented out the loop to try and draw one triangle, as far as I can see im drawing unique pairs for each vertices, can anyone explain to me why this is wrong and only draws 2 lines?

thanks

BionicBytes
11-21-2011, 10:48 AM
glVertex3f(vertices[triangles[i+1*3]*3],

Who knows what you have in your vertices[triangles] arrays?
Are you sure you should be indexing them in that way though...
i+1*3 --> should this be (i*3)+1