Agh! glDrawElements kills my artwork

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:
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*/

Any ideas as to what is going on?
Quote this message in a reply
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
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 17,179 Nov 11, 2009 03:03 PM
Last Post: Ashford
  glDrawElements question Falcor 20 14,782 Feb 2, 2006 02:50 PM
Last Post: akb825
  glDrawElements() some questions .. NYGhost 2 3,469 Nov 15, 2004 06:15 PM
Last Post: NYGhost
  glDrawElements question Jake 9 5,782 Jun 24, 2004 08:13 PM
Last Post: Jake
  glDrawElements vs. glDrawArrays - The numbers are in! inio 22 26,134 Jul 19, 2003 10:00 AM
Last Post: Josh