# Drawing a textured triangle with CPU instead of GPU

I understand the benefits of GPU rendering and such, but for a certain limited application I need to render textured triangles purely using CPU.

I've built a 3D engine capable of object handling, transform, projection, culling and the likes ... now all I need is a little code snippet that draws a single textured triangle onto a bitmap... any language accepted!

• Inputs: Texture bitmap, Triangle U/V/W coords, Triangle X/Y screen coords

• Output: The textured triangle drawn at the given screen coords

I've currently been using a platform function to draw triangles to screen, but I'm looking to handle it myself to speeden up the process.

-
Actually, if you want to do 3D you need to draw to 3D coordinates in order to transform the texture properly, same texture coordinates and screen coordinates does not equal the same rendering if the triangles are supposed to be oriented differently in space. – aaaaaaaaaaaa Nov 13 '11 at 8:01
Your question is also a bit broad, have you got problems with the maths? Or why can't you write this yourself? Also, what quality do you aim at? We could do anything from nearest pixel centre to integral sampling. – aaaaaaaaaaaa Nov 13 '11 at 8:07
@eBusiness - Correct. I have the X/Y/Z of the screen coordinates and also the U/V/T of the the texture coordinates. Maths? I'm not a math expert, although I can manage moderately complex things such as vectors and planes. I'm looking at something quite fast, performance first, some sampling would be useful but not necessary. Nearest pixel should be great for starts so I can check the performance. – Jarvis Nov 13 '11 at 10:56
I'm not sure if it's possible to write a faster implementation of `drawTriangle` in Actionscript, as the platform function is most likely a "native" implementation. I might be wrong though. Maybe have a look how other 3D engines like Away3D do it? – bummzack Nov 13 '11 at 11:28
@Nicol - I don't have the time or the expertise to invent my own textured triangle renderer. I'm not asking for a full scanline renderer, just a simple function to rasterize a single triangle. This isn't generic behaviour, review my other questions if you think I'm an idiot who simply steals the work of someone else's sweat. – Jarvis Nov 15 '11 at 12:35