Color key problem! =O - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Color key problem! =O

hfanthfant Posts: 7Member
Hey everyone, I've been working on my first game(2D) for awhile now and things are coming along very nicely! Im quite proud of myself =)
I seem to have one major bug tho, when I try to blit images I can't seem to blit the color black! =(

Here is the function used to create the surface:

LPDIRECTDRAWSURFACE7 DDraw_Create_Surface(int width,
int height,
int mem_flags,
USHORT color_key_value)
{
// this function creates an offscreen plain surface

DDSURFACEDESC2 ddsd; // working description
LPDIRECTDRAWSURFACE7 lpdds; // temporary surface

// set to access caps, width, and height
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;

// set dimensions of the new bitmap surface
ddsd.dwWidth = width;
ddsd.dwHeight = height;

// set surface to offscreen plain
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | mem_flags;

// create the surface
if (FAILED(lpdd->CreateSurface(&ddsd,&lpdds,NULL)))
return(NULL);

// set color_key_value to 250 to test to see if color 0 will blit
color_key_value = 250;
DDCOLORKEY color_key; // used to set color key
color_key.dwColorSpaceLowValue = color_key_value;
color_key.dwColorSpaceHighValue = color_key_value;

// now set the color key for source blitting
lpdds->SetColorKey(DDCKEY_SRCBLT, &color_key);

// return surface
return(lpdds);
} // end DDraw_Create_Surface





I've set the color to be transparent as 250, simply for testing purposes. However, even after attaching the ColorKey to the surface, the color black will still not blit! I am sad.

Also, here's the call to the blitter:

// blt to destination surface
if (FAILED(dest->Blt(&dest_rect, bob->images[bob->curr_frame],
&source_rect,(DDBLT_WAIT | DDBLT_KEYSRC),
NULL)))
return(0);

Where dest is a back surface. Bob is a Blitter OBject and holds the bitmap I am blitting. Compliments of Andre Lamothe. The primary and back surface are then flipped using:

// blit the entire back surface to the primary
if (FAILED(lpddsprimary->Blt(&dest_rect, lpddsback,NULL,DDBLT_WAIT,NULL)))
return(0);



Where dest_rect is the primary surface. (Its a windowed app so I have to find the coordinated to blit to first)



Any help would be appreciated! My mind is exploding...
Thanks,
Alex


Comments

  • MT2002MT2002 Posts: 1,444Member
    : Hey everyone, I've been working on my first game(2D) for awhile now and things are coming along very nicely! Im quite proud of myself =)
    : I seem to have one major bug tho, when I try to blit images I can't seem to blit the color black! =(
    :
    : Here is the function used to create the surface:
    :
    : LPDIRECTDRAWSURFACE7 DDraw_Create_Surface(int width,
    : int height,
    : int mem_flags,
    : USHORT color_key_value)
    : {
    : // this function creates an offscreen plain surface
    :
    : DDSURFACEDESC2 ddsd; // working description
    : LPDIRECTDRAWSURFACE7 lpdds; // temporary surface
    :
    : // set to access caps, width, and height
    : memset(&ddsd,0,sizeof(ddsd));
    : ddsd.dwSize = sizeof(ddsd);
    : ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
    :
    : // set dimensions of the new bitmap surface
    : ddsd.dwWidth = width;
    : ddsd.dwHeight = height;
    :
    : // set surface to offscreen plain
    : ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | mem_flags;
    :
    : // create the surface
    : if (FAILED(lpdd->CreateSurface(&ddsd,&lpdds,NULL)))
    : return(NULL);
    :
    : // set color_key_value to 250 to test to see if color 0 will blit

    [blue]
    What bpp is the video mode? In DirectDraw, you have
    to set the currect bit format of the color you dont
    want blitted as the color key.
    [/blue]
    : color_key_value = 250;


    : DDCOLORKEY color_key; // used to set color key
    : color_key.dwColorSpaceLowValue = color_key_value;
    : color_key.dwColorSpaceHighValue = color_key_value;
    :
    : // now set the color key for source blitting
    : lpdds->SetColorKey(DDCKEY_SRCBLT, &color_key);
    :
    : // return surface
    : return(lpdds);
    : } // end DDraw_Create_Surface
    :
    :
    :
    :
    :
    : I've set the color to be transparent as 250, simply for testing purposes. However, even after attaching the ColorKey to the surface, the color black will still not blit! I am sad.
    :
    : Also, here's the call to the blitter:
    :
    : // blt to destination surface
    : if (FAILED(dest->Blt(&dest_rect, bob->images[bob->curr_frame],
    : &source_rect,(DDBLT_WAIT | DDBLT_KEYSRC),
    : NULL)))
    : return(0);
    [blue]
    Just a hint...There are [b]much[/b] easier ways to
    handle frame animation then loading them into arrays.
    (As Lamothe does) Just my opinion.
    [/blue]

    : Where dest is a back surface. Bob is a Blitter OBject and holds the bitmap I am blitting. Compliments of Andre Lamothe. The primary and back surface are then flipped using:
    :
    : // blit the entire back surface to the primary
    : if (FAILED(lpddsprimary->Blt(&dest_rect, lpddsback,NULL,DDBLT_WAIT,NULL)))
    : return(0);
    :
    :
    :
    : Where dest_rect is the primary surface. (Its a windowed app so I have to find the coordinated to blit to first)
    :
    :
    :
    : Any help would be appreciated! My mind is exploding...
    : Thanks,
    : Alex
    :
    :
    :

Sign In or Register to comment.