Game Development Community

Rendering Code Expaination

by Chris Labombard · in Torque Game Engine · 04/21/2006 (1:41 pm) · 2 replies

Could someone please explain to me what this bit of rendering code from guiRadarCtrl does?

RectI srcRegion; 
RectI dstRegion; 
float xdone = ((float)mBounds.extent.x/(float)texture->bitmapWidth)+1;
float ydone = ((float)mBounds.extent.y/(float)texture->bitmapHeight)+1; 
	
int xshift = startPoint.x%texture->bitmapWidth; 
int yshift = startPoint.y%texture->bitmapHeight; 
for(int y = 0; y < ydone; ++y) 
for(int x = 0; x < xdone; ++x) 
{ 
	srcRegion.set(0,0,texture->bitmapWidth,texture->bitmapHeight); 
	
	dstRegion.set( ((texture->bitmapWidth*x)+offset.x)-xshift, 
    	((texture->bitmapHeight*y)+offset.y)-yshift, 
		texture->bitmapWidth, texture->bitmapHeight); 
	dglDrawBitmapStretchSR(texture,dstRegion, srcRegion, false);
}

About the author

I have been a professional game programmer for over 5 years now. I've worked on virtually every platform, dozens of games and released a few of my own games, including 2 iPhone titles and a title waiting release on Big Fish Games.


#1
04/21/2006 (4:19 pm)
Ok I'll try .. if i'm wrong in any place someone can correct me.

xdone is calculated to be a percentage of the texture width plus 1
as is ydone cept using height.

xshift is calculated to be a tiling offset.

so lets look at what we do know.

srcRegion is Always the entire texture.
dstRegion is calculated to be a region the same size as the srcRegion but with some sneaky offsets.

all of this is drawn to a buffer utilizing the region offsets.
so IMHO its a form of mipmapping with support for only mipmapping sub sections of the image.

looks like offset is a simple texture offset.
#2
04/21/2006 (5:07 pm)
Thanks but I figured it out.