Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

xtrmntr

class dilema

This topic is 6674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
    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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!