tags:

views:

184

answers:

2
A: 

Implement this algorithm.

dmnd
+1  A: 

If you can't use OpenGL (or Direct3D) then you're probably going to have to write your own rasterizer. I'm also going to point out that this is a terrible idea, and if you can use OpenGL or Direct3D then you'll save yourself an enormous amount of work, even if it's really hard to get these things to work with your app. Yes, you can use OpenGL or Direct3D to render into a texture without creating an on-screen context.

On the theoretical side, you're applying a perspective projection (look up that term) to each of the points on your square. That's each point, not just the corners but all the points between. People find the distortion acceptable if you just apply the transformation to the four points, usually, so we do that instead.

Once your 3D points are transformed into 2D points by use of a perspective transformation, you draw the polygon, copying pixels from your texture into your destination context. You'll want to loop across each pixel in the destination and calculate which source pixel ends up there. If it's only rotated about the X axis as it appears in the picture, then you'll make things a lot easier as each row in the destination corresponds to a row in the source. Wolfenstein exploited the same trick (except about the Y axis) for perspective rendering in real time on a 286, Doom did too.

If you still want to continue but don't know what I'm saying, look up one of those old books that tells you how to make your own Doom-clone. Those books have the code you're looking for. One or two is now available online, go to this wiki and look for "Black art of 3D game programming" or "Tricks of the Windows game programming gurus". One or two others might be there.

Dietrich Epp