Original Post
Hey, I''ve been having problems with this code:
void Blit8x8(int x, int y,
UCHAR *video_buffer,
UCHAR *bitmap)
{
//This function Blits the image sent in the bitmap to the
// destination surface pointer to by video_buffer
// the function assumes a 640x480x8 mode with linear pitch
//compute starting point into video_buffer
//video_buffer = video_buffer + (x + y*640)
video_buffer+= (x + (y << 9) + (y << 7));
UCHAR pixel; //used to read/write pixels
for(int index_y=0; index_y < 8; index_y++)
{
//inner loop, this is where it counts
for(index_x=0; index_x < 8; index_x++)
{
//copy pixel, test for transparent though
if(pixel = bitmap[index_x])
video_buffer[index_x] = pixel;
}//end for index_x
//advance pointers
bitmap+= 8; //next line in bitmap
video_buffer+=640;// next line in video_buffer
}//end for index_y
}//end Blit8x8The error is this --------------------Configuration: win32 - Win32 Debug-------------------- Compiling... win32.cpp C:\demonrealms\win32\win32.cpp(88) : warning C4101: ''buffer'' : unreferenced local variable C:\demonrealms\win32\win32.cpp(175) : error C2601: ''Blit8x8'' : local function definitions are illegal Error executing cl.exe. win32.obj - 1 error(s), 1 warning(s)Does anyone know what the problem is? Here I might as well give you the whole main function so you can see the error.
int Game_Main(void *parms = NULL, int num_parms = 0)
{
// this is the main loop of the game, do all your processing
// here
UCHAR *primary_buffer = NULL; // used as alias to primary surface buffer
DDRAW_INIT_STRUCT(ddbltfx);
// make sure this isn''t executed again
if (window_closed)
return(0);
// for now test if user is hitting ESC and send WM_CLOSE
if (KEYDOWN(VK_ESCAPE))
{
PostMessage(main_window_handle,WM_CLOSE,0,0);
window_closed = 1;
} // end if
// erase double buffer
memset((void *)double_buffer,0, SCREEN_WIDTH*SCREEN_HEIGHT);
// you would perform game logic...
// draw the next frame into the double buffer
// plot 5000 random pixels
for (int index=0; index < 5000; index++)
{
int x = rand()%SCREEN_WIDTH;
int y = rand()%SCREEN_HEIGHT;
UCHAR col = rand()%256;
double_buffer[x+y*SCREEN_WIDTH] = col;
} // end for index
// copy the double buffer into the primary buffer
DDRAW_INIT_STRUCT(ddsd);
// lock the primary surface
lpddsprimary->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
void Blit8x8(int x, int y,
UCHAR *video_buffer,
UCHAR *bitmap)
{
//This function Blits the image sent in the bitmap to the
// destination surface pointer to by video_buffer
// the function assumes a 640x480x8 mode with linear pitch
//compute starting point into video_buffer
//video_buffer = video_buffer + (x + y*640)
video_buffer+= (x + (y << 9) + (y << 7));
UCHAR pixel; //used to read/write pixels
for(int index_y=0; index_y < 8; index_y++)
{
//inner loop, this is where it counts
for(index_x=0; index_x < 8; index_x++)
{
//copy pixel, test for transparent though
if(pixel = bitmap[index_x])
video_buffer[index_x] = pixel;
}//end for index_x
//advance pointers
bitmap+= 8; //next line in bitmap
video_buffer+=640;// next line in video_buffer
}//end for index_y
}//end Blit8x8
// get video pointer to primary surfce
primary_buffer = (UCHAR *)ddsd.lpSurface;
// test if memory is linear
if (ddsd.lPitch == SCREEN_WIDTH)
{
// copy memory from double buffer to primary buffer
memcpy((void *)primary_buffer, (void *)double_buffer, SCREEN_WIDTH*SCREEN_HEIGHT);
} // end if
else
{ // non-linear
// make copy of source and destination addresses
UCHAR *dest_ptr = primary_buffer;
UCHAR *src_ptr = double_buffer;
// memory is non-linear, copy line by line
for (int y=0; y < SCREEN_HEIGHT; y++)
{
// copy line
memcpy((void *)dest_ptr, (void *)src_ptr, SCREEN_WIDTH);
// advance pointers to next line
dest_ptr+=ddsd.lPitch;
src_ptr +=SCREEN_WIDTH;
// note: the above code code be replaced with the simpler
// memcpy(&primary_buffer[y*ddsd.lPitch], double_buffer[y*SCREEN_WIDTH], SCREEN_WIDTH);
// but it is much slower due to the recalculation and multiplication each cycle
} // end for
} // end else
// now unlock the primary surface
if (FAILED(lpddsprimary->Unlock(NULL)))
return(0);
// wait a sec
Sleep(500);
// return success or failure or your own return code here
return(1);
} // end Game_Main
////////////////////////////////////////////////////////////
If anyone can tell me what''s wrong please do so.
Thanks in advance,
demonrealms