Copy Screen to primary surface
I have a function called Copy_Screen, but it only copies half of my bitmap that''s loaded into memory. It''s for 16 bit.
Here it is:
int Copy_Screen(UCHAR *source_bitmap,UCHAR *dest_buffer, int lpitch, int transparent)
{
UCHAR *dest_addr, // starting address of bitmap in destination
*source_addr; // starting adddress of bitmap data in source
UCHAR pixel; // used to hold pixel value
int index,
pixel_x,
lpitch_2 = lpitch >> 1;
// compute starting destination address
dest_addr = dest_buffer;
// compute the starting source address
source_addr = source_bitmap;
// is this bitmap transparent
if (transparent)
{
// copy each line of bitmap into destination with transparency
for (index=0; index< SCREEN_HEIGHT; index++)
{
// copy the memory
for (pixel_x=0; pixel_x<SCREEN_WIDTH; pixel_x++)
{
if ((pixel = source_addr[pixel_x])!=0)
dest_addr[pixel_x] = pixel;
} // end if
// advance all the pointers
dest_addr += lpitch_2;
source_addr += SCREEN_WIDTH;
} // end for index
} // end if
else
{
// non-transparent version
// copy each line of bitmap into destination
for (index=0; index < SCREEN_HEIGHT; index++)
{
// copy the memory
memcpy(dest_addr, source_addr, SCREEN_WIDTH);
// advance all the pointers
dest_addr += lpitch_2;
source_addr += SCREEN_WIDTH;
} // end for index
}
return(1);
}
Is there anything wrong with this? There must be... Otherwise I wouldn''t be posting. =^)
Well, in 16bpp you have 2 bytes per pixel, not one as indicated by the UCHARS, try USHORTs instead... and/or double the index variable of the for loop.
Magmai Kai Holmlor
- Not For Rent
Magmai Kai Holmlor
- Not For Rent
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Now it''s asking for a cast!! How would I do this?
error C2664: ''Copy_Screen'' : cannot convert parameter 1 from ''unsigned short'' to ''unsigned short *''
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Is it something like (USHORT *) then the call to Copy_Screen?
error C2664: ''Copy_Screen'' : cannot convert parameter 1 from ''unsigned short'' to ''unsigned short *''
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Is it something like (USHORT *) then the call to Copy_Screen?
I got it to work using (USHORT *) for the first to parameters, but no the screen loads, then exits without doing anything...
Nevermind, I forgot to lock the primary surface... =^|
Heh, I''m talking to my self...
But now it copies a 1/4 of the bitmap, which is worse than the first time... Help?
Heh, I''m talking to my self...
But now it copies a 1/4 of the bitmap, which is worse than the first time... Help?
Well, your first task should have been to tell us whether it''s calling it with transparent = true or transparent = false first. And to try it with both variations. That cuts your debugging time by half, assuming that only 1 of them is bugged. As it is, we have to look through both sections when, most likely, only one of them has a problem.
My first guess is that you have no reason to be dividing pitch by two. If you are using USHORT* for dest_addr, then pitch is measured in pixels and therefore shouldn''t be halved.
My first guess is that you have no reason to be dividing pitch by two. If you are using USHORT* for dest_addr, then pitch is measured in pixels and therefore shouldn''t be halved.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement