Skip to main content
gamedev.net
🔒 Locked

Bitmap errors

Started by demonrealms Jul 21, 2003 at 1:20 AM 4 replies 600+ views
Original Post
demonrealms
demonrealms
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 Blit8x8
The 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
demonrealms
demonrealms
Hey, I don''t think you know what the damn mistake word is, but please look it up in the dictionary before bitting my head off. It''s 2:35 am. You think I''m wide awake? Now where''s the missing underscore?
KrazeIke
KrazeIke
Again, reading your other posts, I have to agree. Get a C++ book. Read it. You can''t define one function right in the middle of another one.
RaphaelMun
RaphaelMun
Sorry, didn''t know you made a new post. The problem is that you declared your function within the brackets of the WinMain () function and that is indeed "illegal" in C++ terms. What you should do is prototype it before the WinMain () function like this:

void Blit8x8(int x, int y, UCHAR *video_buffer, UCHAR *bitmap);

and then define the function later in the file after the WinMain () brackets are closed. Good luck dude.
demonrealms
demonrealms
Ah, I see my error now. You have to relize that Andre Lamothe Doesn''t really tell you where to put things until the end where he puts it all into one. Well, I just wanted to learn the Blits functions ahead of time so I''m not compltely lost when it comes to the end. Thanks for your help,
demonrealms

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.