Skip to main content
gamedev.net
🔒 Locked

need help with loading bitmaps

Started by Gorgoth Dec 21, 2001 at 2:07 PM 2 replies 300+ views
Original Post
Gorgoth
Gorgoth
I''m some what new to direct x. I''m trying to build a class to handle UI functions, direct draw in paticular. I wrote a small function in a class to try to work out how to load a bitmap. I have compared my work with other code that loads bitmaps and they look the same. Everything compiles and all the error checking I did doesn''t show any problems, but when I run the program the screen stays blank even odder is that when I pusk escape exit the program I get the image on the screen right befor it exits and ONLY when I exit. I''m going to put the header file and the function up here. IF you know what I''m doing wrong please tell me. //header file #include #include #include "resource.h" class DSApp { private: LPDIRECTDRAW7 pDD; LPDIRECTDRAWSURFACE7 pDDPrimary; LPDIRECTDRAWSURFACE7 pDDBackbuffer; DDSURFACEDESC2 surdic; DDSCAPS2 ddscaps; WNDCLASSEX DSAppClass; HWND DSWnd; MSG msg; HINSTANCE hInstance; public: DSApp(); ~DSApp(); void CreateDSWindow(short int, short int, char); void Run(void); void ShutDown(void); void ShowBitmap(void); }; // now the function void DSApp::ShowBitmap(void) { HBITMAP daydream; BITMAP bm; HDC DCImage; HDC hdc; HRESULT mine; daydream =(HBITMAP)LoadImage(GetModuleHandle(NULL), "daydream.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);//LoadBitmap(hInstance, "daydream.bmp"); if(daydream == NULL) { MessageBox((HWND) NULL, "Error loading bitmap", "Error", MB_OK); } if(GetObject(daydream, sizeof(bm), &bm) == 0) { MessageBox((HWND) NULL, "Error getting bitmap", "Error", MB_OK); } ZeroMemory(&surdic, sizeof(surdic)); surdic.dwSize = sizeof(surdic); surdic.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; //| DDSD_WIDTH | DDSD_HEIGHT; surdic.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; surdic.dwWidth = bm.bmWidth; surdic.dwHeight = bm.bmHeight; surdic.dwBackBufferCount = 1; mine = pDD->CreateSurface(&surdic,&pDDPrimary , NULL); ZeroMemory( &ddscaps, sizeof( ddscaps ) ); ddscaps.dwCaps = DDSCAPS_BACKBUFFER; mine = pDDPrimary->GetAttachedSurface(&ddscaps, &pDDBackbuffer); DCImage = CreateCompatibleDC(NULL); if(!DCImage) { MessageBox((HWND) NULL, "Error Loading bitmap into HDC", "Error", MB_OK); } SelectObject(DCImage, daydream); if(FAILED(pDDPrimary->GetSurfaceDesc(&surdic))) { MessageBox((HWND) NULL, "Error Getting surface description", "Error", MB_OK); } if(FAILED(pDDPrimary->GetDC(&hdc))) { MessageBox((HWND) NULL, "Error getting image hdc", "Error", MB_OK); } if(BitBlt(hdc, 0, 0, surdic.dwWidth, surdic.dwHeight, DCImage, 0, 0, SRCCOPY) == FALSE) { MessageBox((HWND) NULL, "Error Bliting bitmap", "Error", MB_OK); } } I took out most of the error handleing and only showing the header and function to save space. When all else fails, nuke them.
When all else fails, nuke them.
streampark
streampark
if you are seeing the image on exit, the image must be in VidMem, you are just seeing it when the mode or whatever is being changed (accessing different areas of VidMem). Also, I don''t know if it''s a good idea to blt to the primary surface. You have created a backbuffer so blt to that and flip().

http://www.geocities.com/streampark
Gorgoth
Gorgoth


I''ve tryed the back buffer but then it just stays blank, even when I flip them. If the image is in
memory I can''t get to it for some reason.
When all else fails, nuke them.
streampark
streampark
OK, here goes...

        
daydream =(HBITMAP)LoadImage(GetModuleHandle(NULL), "daydream.bmp", IMAGE_BITMAP,
0, 0, LR_LOADFROMFILE);//LoadBitmap(hInstance, "daydream.bmp");




1. I'm not sure if GetModuleHandle(NULL) is what you want here, try using the hInstance from the WinMain() function.

2. Try LR_CREATEDIBSECTION | LR_LOADFROMFILE. It will load the bitmap independently of the current mode. The mode (color depth) will be altered with the blt() later.

       
if(FAILED(pDDPrimary->GetDC(&hdc))) {
MessageBox((HWND) NULL, "Error getting image hdc", "Error", MB_OK);
}


4. Release this DC after the BitBlt().

        
pDDPrimary->ReleaseDC(hdc);


5. Delete DCImage after the BitBlt().

  
DeleteDC(DCImage);


quote:

If the image is in memory I can't get to it for some reason.



6. I'm not sure what you mean here.


Apart from that, it looks OK. There are a few extra lines of code that aren't required tho, but I guess that's because it's all chopped up.


http://www.geocities.com/streampark



Edited by - streampark on December 22, 2001 1:45:28 AM

Topic Locked

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

Sign in to reply to this topic.