In this program if i draw my scene using the version below which calls a function DrawBox, and Drawbox calls Drawpixel to actually create the scene it runs really slow, compared to if i remove the commetns and take out the call to DrawBox and just use Drawpixel directly, which then runs nice and fast. Is there a known reason for this?
To clarify, the slow version is as seen below, if i remove the comments to recreates my original version and delete call to Drawbox it runs fast.
Code:
for(mainDwn = 0; mainDwn < dwnMax; mainDwn++) //draw the map
{
for(mainAcr = 0; mainAcr < acrMax; mainAcr++)
{
if(mapnode[mainDwn][mainAcr].Walkstate)
{ cR = 128; cG = 128; cB = 255; }
else
{ cR = 0; cG = 0; cB = 255; }
if(mapnode[mainDwn][mainAcr].STnode)
{ cR = 255; cG = 128; cB = 0; }
if(mapnode[mainDwn][mainAcr].TGnode)
{ cR = 0; cG = 255; cB = 128; }
/* for(countY = 0; countY < 14; countY++)
{
for(countX = 0; countX < 14; countX++)
{
DrawPixel(screen,boxAcr, boxDwn,cR,cG,cB);
boxAcr++;
}
boxAcr -= 14;
boxDwn++;
} */
DrawBox(screen, mainDwn, mainAcr, cR,cG,cB);
// boxDwn -=14;
//boxAcr += 15;
}
// boxAcr = 0;
// boxDwn += 15;
}
here is the Drawbox function for reference also >
Code:
void DrawBox(SDL_Surface *screen, int cY, int cX, int cR, int cG, int cB)
{
int X_start_ref = cX * Boxsize;
int boxY = cY * Boxsize;
int boxX = cX * Boxsize;
int maxboxY = boxY + Boxsize;
int maxboxX = boxX+ Boxsize;
while(boxY < maxboxY-1)
{
while(boxX < maxboxX-1)
{
DrawPixel(screen,boxX, boxY,cR,cG,cB);
boxX++;
}
boxX = X_start_ref;
boxY++;
}
SDL_Flip(screen);
}