How to apply texture map to n-point polygon using GDI+

Started by
1 comment, last by JoeJ 3 weeks, 1 day ago

I'm working on a 3d viewer, minimal support for .obj and .mtl files. I'm not using opengl or directx but writing my own routines. I'm now at the point I need to add textures to the model.

As I understand texture coords are mapped [0,1] and really just ratios. I assume I need to:

mapped_u=textcoords.u*bitmap.width 
mapped_v=textcoords.v*bitmap.height 

to get the offsets into the file. At this point I'm not sure how to use GDI+ to process the texture to the n-point polygon I need to draw it to.


Advertisement

Basically you need to calculate u,v for each pixel.
For a scanline rasterizer, you interpolate them for the left and right edges of the polygon, then you interpolate between them while drawing the scanline.

Here's a tutorial:

https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/perspective-correct-interpolation-vertex-attributes.html

Advertisement