About me

Vladimir Nabokov

Books
Programming
Biochemistry
Aim | Communicate

Search
 


 

 

   
Letters from Terra - Life in water warmed by sunlight
 
 

     
 
 

     
An older version of my 3D engine, minus the texture mapping. Click for more Screenshots
 
 
     

I know this is all a little heavy, so I'll demonstrate what I mean. If a polygon (I'll make it rectangular for simplicity, and sanity's, sake) is considered, and the coordinates the represent the texture at the two extremes of the scanline are known, then with a routine that is capable of plotting this scanline using colours taken from the texture, in transition from the starting coordinate to the finishing coordinate, then an accurate texture map can be generated.

Diagram depicting the general method for polygon drawing, and the tracing of a horizonta; scanline as a path accross the texture.

In this diagram, a polygon (in this case a trapezium) is to be drawn with the tetxure shown on the right. The routine draws the polygon by scanning horizontal lines, as shown. To texture map one of the horizontal lines, if the starting and finishing coordinates on the texture are known (represented by the large green dots on the texture), then as the scanline is processed the point of reference or sampling on the texture must move along the line between the starting and finishing coords on the texture, as shown by the red line and orange arrow. The routine scans along the horixontal line on the real poly, and simultaneously increments its counters on the red line on the texture, taking the source for the colours to be drawn and plotting them on the screen. The result is an accurate texture map on the scanline on the finished poly, successfully implemented. So how could such a routine be made? Well, to right something that carries this off in Pascal is remarkably simple; especially if you use the FPU to aloow you to use very accurate quotients. However, even if you use pure, optimised pascal code the routine is far too slow to even approach being practically useful, especially on my machine. Evidently, then, the final working model must be scripted in assembler, and well written at that, to allow anything constructive to occur. Nevertheless, if you're doing this for the first time, I'd advise you to script a working (but slow) version in Pascal first, and convert it to assembler at your leisure. The crux of the matter is to create a routine with two variables, containing the coords of the sampling point in the texture; lets call them SamX and SamY. To initialise, these are set to the starting coords, as fed to the routine by the master, polygon drawing procedure.

Back to previous page | Next Page

 
 
Letters from Terra | Updated 15th December 2004 | By Jonathan Ayling