76
Programming / Re: 3D rendering (software)
« on: May 02, 2010, 09:28:41 AM »
I've written a textured triangle function before. All you need to make sense of is interpolation, scaling textures onto arbitrary-sized surfaces. If you can do this with rectangles (such as sprites), then you can do it with triangles.
For a sprite (psuedo code):
If you can make sense of that, then you can apply the same thing to a triangle algorithm. Though it's a little more complicated, because a triangle as varying lengths of width, so as you move down the triangle you have to recalculate a new horizontal scale for each line of the triangle you draw. Once you get that going then it's not too hard to work out the other quirks.
For a sprite (psuedo code):
Code: [Select]
scalex = renderW / spriteW: scaley = renderH / spriteH
FOR y = 0 TO renderH-1
FOR x = 0 TO renderW-1
PSET (x, y), sprite(x*scalex, y*scaleY)
NEXT x
NEXT y
If you can make sense of that, then you can apply the same thing to a triangle algorithm. Though it's a little more complicated, because a triangle as varying lengths of width, so as you move down the triangle you have to recalculate a new horizontal scale for each line of the triangle you draw. Once you get that going then it's not too hard to work out the other quirks.