Skip to main content
GameDev.net gamedev.net
🔒 Locked

class dilema

Started by xtrmntr Sep 2, 2000 at 8:50 PM 1 replies 550+ views
Original Post
xtrmntr
xtrmntr
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.
Zipster
Zipster
    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);

}


Sorry I can''t help, but I have some line-saving suggestions. First:
(obj->image)->Lock(NULL,&ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,NULL);

primary_buffer = (UCHAR*)ddsd.lpSurface;


IDirectDrawSurface7->Lock automatically returns a pointer to the buffer anyhow, so all you really need is this:
primary_buffer = (UCHAR*)(obj->image)->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL); 


This way you can also eliminate the DDSURFACEDESC2 structure and its initialization.
xtrmntr
xtrmntr
thanks for the advice Zipster. So anybody have any other ideas?

Topic Locked

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

Sign in to reply to this topic.