Original Post
this is the code for my menu class which is still under development. my DD7 surfaces are global and put inside a .pch file which is included in the menu.cpp file. the background variable has a surface in it that will hold the image
typedef struct MENU_OBJ_TYP
{
int x,y; // location
int width,height; // width & height
LPDIRECTDRAWSURFACE7 image; // surface to store BMP
} MENU_OBJ, *MENU_OBJ_PTR;
class Menu
{
private:
BITMAP_FILE bitmap;
MENU_OBJ background;
int Create_Menu_Object(MENU_OBJ_PTR obj, int x, int y, int width, int height);
void Load_Menu_Object(MENU_OBJ_PTR obj, BITMAP_FILE_PTR bit);
void Draw_Menu_Object(MENU_OBJ_PTR obj);
public:
Menu();
~Menu();
void Draw_Menu();
BOOL Load_Menu();
BOOL Unload_Menu();
};
i dont get any errors when i compile and run so i know that i set up the DD stuff correctly. however when i try blitting the background to the back buffer it doesnt show up on the screen?
I know im probably making some kind of C++ error but i just dont see it. Here is the menu.cpp code:
void Menu::Draw_Menu()
{
Draw_Menu_Object(&background);
}
BOOL Menu::Load_Menu()
{
Load_Bitmap_File(&bitmap, "menubk.bmp");
if(!Create_Background(&background,0, 0, 640, 480))
return FALSE;
Load_Background(&background,&bitmap);
Unload_Bitmap_File(&bitmap);
return TRUE;
}
BOOL Menu::Unload_Menu()
{
return TRUE;
}
int Menu::Create_Menu_Object(MENU_OBJ_PTR obj, int x, int y, int width, int height)
{
DDSURFACEDESC2 ddsd; // description of a surface
background.x = x;
background.y = y;
background.image = NULL;
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.dwWidth = background.width = width;
ddsd.dwHeight = background.height = height;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
// create surface for the menu title
if(lpdd->CreateSurface(&ddsd,&(obj->image),NULL))
{
return(0);
}
DDCOLORKEY col_key;
col_key.dwColorSpaceLowValue = 0;
col_key.dwColorSpaceHighValue = 0;
(obj->image)->SetColorKey(DDCKEY_SRCBLT, &col_key);
return(1);
}
void Menu::Load_Menu_Object(MENU_OBJ_PTR obj, BITMAP_FILE_PTR bit)
{
DDSURFACEDESC2 ddsd;
UCHAR *primary_buffer;
ZeroMemory(&ddsd,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
(obj->image)->Lock(NULL,&ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,NULL);
primary_buffer = (UCHAR*)ddsd.lpSurface;
for(int y=0;ybitmapinfoheader.biHeight;y++)
{
memcpy(&primary_buffer[y*ddsd.lPitch],
&bit->buffer[y*bit->bitmapinfoheader.biWidth],
bit->bitmapinfoheader.biWidth);
}
(obj->image)->Unlock(NULL);
}
void Menu::Draw_Menu_Object(MENU_OBJ_PTR obj)
{
RECT source_rect, dest_rect;
source_rect.top = source_rect.left = 0;
source_rect.right = obj->width-1;
source_rect.bottom = obj->height-1;
dest_rect.left = obj->x;
dest_rect.top = obj->y;
dest_rect.right = obj->width-1;
dest_rect.bottom = obj->height-1;
lpddsback->Blt(&dest_rect,(obj>image),&source_rect,DDBLT_WAIT | DDBLT_KEYSRC,NULL);
}
i have also tried doing it without passing background as a pointer but get the same results. Constructive comments welcome.
Thanks in advance.