iDevGames Forums
Agh! glDrawElements kills my artwork - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Agh! glDrawElements kills my artwork (/thread-3700.html)



Agh! glDrawElements kills my artwork - ferum - Nov 21, 2006 02:35 PM

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?


Agh! glDrawElements kills my artwork - Fenris - Nov 21, 2006 02:50 PM

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.


Agh! glDrawElements kills my artwork - ferum - Nov 23, 2006 09:05 AM

Gah, started counting at 1 instead of 0!
stupid me.
It works now.