Agh! glDrawElements kills my artwork
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
)
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]](http://i4.photobucket.com/albums/y134/ferumFierfek/before.jpg)
To this:
![[Image: After.jpg]](http://i4.photobucket.com/albums/y134/ferumFierfek/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:
Any ideas as to what is going on?
)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]](http://i4.photobucket.com/albums/y134/ferumFierfek/before.jpg)
To this:
![[Image: After.jpg]](http://i4.photobucket.com/albums/y134/ferumFierfek/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?
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.
I would go over the target.triangles again and make really sure that you're not missing something there.
I would go over the target.triangles again and make really sure that you're not missing something there.
Gah, started counting at 1 instead of 0!
stupid me.
It works now.
stupid me.
It works now.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| glDrawElements and Face indices | Ashford | 8 | 8,015 |
Nov 11, 2009 03:03 PM Last Post: Ashford |
|
| glDrawElements question | Falcor | 20 | 10,053 |
Feb 2, 2006 02:50 PM Last Post: akb825 |
|
| glDrawElements() some questions .. | NYGhost | 2 | 2,550 |
Nov 15, 2004 06:15 PM Last Post: NYGhost |
|
| glDrawElements question | Jake | 9 | 3,965 |
Jun 24, 2004 08:13 PM Last Post: Jake |
|
| glDrawElements vs. glDrawArrays - The numbers are in! | inio | 22 | 17,007 |
Jul 19, 2003 10:00 AM Last Post: Josh |
|

