Agh! glDrawElements kills my artwork

Member
Posts: 185
Joined: 2005.02
Post: #1
I have been using a very inefficient way of supplying verteces. I won't go into too much detail, but the general idea was arrays of "vertex" structs with x and y members and "triangle" structs with a, b and c members that acted as indices. Then when I went to draw the triangles I retrieved the appropriate verteces according to the triangle struct I was dealing with. (Yeah, told ya it was ineffiecient, the game is simple enough that I still got 210 fps though Rasp)
I decided to switch over to drawing all of my geometry with glDrawElements. I switched my vertex representation to just scanning them in sequencially as with the triangles. Suddenly my little space ship has gone from looking like this:
[Image: before.jpg]

To this:
[Image: After.jpg]

And I haven't a clue why. None of the data files have been changed, and I have verified that the data is being read in correctly. Here is my draw function:
Code:
void drawOBJ(ObjBase target)
{
    glColorPointer(3, GL_FLOAT, 0, target.color); /*Yes, color and verteces are arrays*/
    glVertexPointer(2, GL_FLOAT, 0, target.verteces);
    
    glDrawElements(GL_TRIANGLES, (target.numberOfTriangles * 3), GL_UNSIGNED_INT, target.triangles); /*as is triangles*/
    
    return;    
}

Any ideas as to what is going on?
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #2
If you look at the mangled red triangles, you can quite easily see that the vertex/triangle indices are off by one. For instance, the left triangle seens to grab its first or lats vertex from the body of the space ship, while the right triangle seems to grab its first from the last of the left-most. Smile I would go over the target.triangles again and make really sure that you're not missing something there.
Quote this message in a reply
Member
Posts: 185
Joined: 2005.02
Post: #3
Gah, started counting at 1 instead of 0!
stupid me.
It works now.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  glDrawElements and Face indices Ashford 8 13,009 Nov 11, 2009 03:03 PM
Last Post: Ashford
  glDrawElements question Falcor 20 11,884 Feb 2, 2006 02:50 PM
Last Post: akb825
  glDrawElements() some questions .. NYGhost 2 2,885 Nov 15, 2004 06:15 PM
Last Post: NYGhost
  glDrawElements question Jake 9 4,542 Jun 24, 2004 08:13 PM
Last Post: Jake
  glDrawElements vs. glDrawArrays - The numbers are in! inio 22 20,457 Jul 19, 2003 10:00 AM
Last Post: Josh