gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Help! MD2 loader, NOT WORKING :(

#128555 - kalus - Sat May 12, 2007 6:16 pm

ok, i started porting an MD2 tutorial i found on net, and seems ok so far, other than when drawing, all the vertices are so messed up it looks like a really spikey cube! Below is a link to the project RAR'ed up, its basically the lesson07 nehe example, but modified ;) if anyone could help with this, would be awesome, especially as i'm so close!

Last edited by kalus on Sun May 13, 2007 11:03 am; edited 1 time in total

#128556 - simonjhall - Sat May 12, 2007 6:21 pm

Sounds like the size of the vertices has overflowed... If I remember correctly, vertices normally go in a 4.12 fixed-point format, so if your vertices are bigger that 16 units you'll overflow and it'll draw crap!

So, try scaling down the geometry before drawing it.
_________________
Big thanks to everyone who donated for Quake2

#128558 - kalus - Sat May 12, 2007 6:29 pm

holy cow batman, the guys a genius! As a quick test I scaled the vertices by 10 at draw time, and it worked! Cheers dude. Got a few more things to fix, looks like the normals are inverted for some reason, and then just gotta add proper texturing and anims, and we're away. GBAX here i come!

#128564 - Rajveer - Sat May 12, 2007 6:51 pm

The problem with the normals could also be overflowing in some cases. Where a component of a floating point normal is 1 or -1, this should be changed to something like 0.999 or -0.999 due to the way the DS handles it. This goes for other formats too I think (i.e. not only floating point).

#128571 - kalus - Sat May 12, 2007 10:17 pm

luckily didnt seem to be the normals, turns out it was rendering the triangles the wrong way round, all fixed now. Just texturing left! The UV coords seem pretty messed up, but for a lazy Saturdays work, i thing untextured animated md2 loading isnt too bad an accomplishment :)

#128580 - simonjhall - Sun May 13, 2007 12:24 am

Haha, we'll done - I'm glad it's drawing mostly-correctly for you now.
It took me DAYS to figure out why my stuff was coming out broken like that. I even wrote a dummy software-renderer to test it and still couldn't figure it out!

The other stupid thing with textures and texture co-ordinates is that that the hardware expects texture co-ords to not go from 0.0-1.0 but from 0-the width of the texture in texels.
_________________
Big thanks to everyone who donated for Quake2

#128601 - kalus - Sun May 13, 2007 11:04 am

how does the md2 supply the UV coords, is it in 0 - 1 range? that could explain it...

EDIT: never mind! it was the texture, it was RGB instead of indexed. Its all working now! Cheers for everything! Heres it working:

http://files-upload.com/224259/md2techtest.rar.html