Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: understanding GL_LINES

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2011
    Posts
    1

    understanding GL_LINES

    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:

    Code :
    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

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: understanding GL_LINES

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •