Archived

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

Utwo

Blit not working (Direct Draw 4)

Recommended Posts

For some reason my call to IDirectDrawSurface4:Blt() has failed. I'm trying to load a bitmap from a resource and onto a DDraw surface, and I'm using GDI functions to do so. Here's the code snippet:
    
 // make temporary bitmap handle.

 HBITMAP hBitmap;
 HDC hdcImage; 
 HDC hdc;  
 
 // Create Surface Description.

 DDSURFACEDESC2 ddsd2; 
 // Clear DDSD memory.

 ZeroMemory(&ddsd2, sizeof(ddsd2)); 
 
 // Fill out DDSD.

 ddsd2.dwSize = sizeof(ddsd2);                            // size fo structure

 ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;    // Which fields we're specifying

 ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;           // Type of Surface

 ddsd2.dwWidth = 300;                                     // Width of Surface

 ddsd2.dwHeight = 300;                                    // Height of Surface

 
 // Create Surface

 if(FAILED(lpdd4->CreateSurface(&ddsd2, &lpddstitle, NULL)))
 {
 
  MessageBox(NULL, "Failed to create lpddstitle surface.", "Error", MB_OK);  
   
 } 
 
 // Load bitmap into Bitmap Handle.

 hBitmap = (HBITMAP)LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_UTWO)); 
 
 // Restores if memory has been freed.

 //lpddstitle->Restore(); 

  
 hdcImage = CreateCompatibleDC(NULL); 
 
 if(hdcImage == NULL)
 {
 
  MessageBox(NULL, "Failed to CreateCompatibleDC.", "Error", MB_OK);  
 
 }
 
 if(SelectObject(hdcImage, hBitmap) == NULL)
 {
 
  MessageBox(NULL, "Failed to Select Object.", "Error", MB_OK);  
   
 } 
 
 // Get DC to lpSurface.

 lpddstitle->GetDC(&hdc);
 
 // Blit loaded bitmap to surface's DC.

 if(!BitBlt(hdc, 0, 0, 300, 300, hdcImage, 0, 0, SRCCOPY))
 {
 
    MessageBox(NULL, "Failed to Blit to new DC.", "Error", MB_OK);
   
 } 
 
 // release DC's

 lpddstitle->ReleaseDC(hdc); DeleteDC(hdcImage); 
 
 // Delete temporary bitmap handle.

 DeleteObject(hBitmap);
 
 
 
 
 
 
 
 
 
 RECT source;
 RECT dest;
 
 source.left   = 0;
 source.top    = 0;
 source.right  = 300;
 source.bottom = 300;
 
 dest.left   = 250;
 dest.top    = 150;
 dest.right  = 550;
 dest.bottom = 450; 
 
 
 
lpddsprimary->Blt(&dest, lpddstitle, &source, DDBLT_WAIT, NULL);
    
As you can see, I have error checking code on every dang function call, and there are no error boxes generated at runtime. Yet, no blit is made. I just get a blank black screen. I made an attempt to grab the exact error, and it turned out to be a Generic Error. So the call to Blt is definitely the problem, but I can't see what I'm doing wrong. [edited by - utwo on May 5, 2003 3:08:13 PM]

Share this post


Link to post
Share on other sites
Might I ask why DirectDraw4 ? Almost all modern hardware supports te final version of DD which is 7.

I dont see anything wrong with you code tho, of course I''ve never used DD4. I genereally use DD7 and ddutil.cpp/.h for loading bitmaps, makes things much easier.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You''ve checked the return value everywhere but where it''s important. It''s obvious that blit is either succeeding or failing but you''re not checking the result.

If you check the result of blit you''ll find out one of two things

#1. Blit is succeeding but it''s not drawing what you expected.

or

#2. Blit is failing which is why it''s not drawing what you expected.

but don''t just do a if( FAILED ) check on this one...

HRESULT result = lpddsprimary->Blt(&dest, lpddstitle, &source, DDBLT_WAIT, NULL);

If you look up blt in the documents for directX you''ll see the possible error return values that will be stored in result should it fail and you can check against them.

Share this post


Link to post
Share on other sites
"I made an attempt to grab the exact error, and it turned out to be a Generic Error."

This is exactly what I did:

DWORD error = lpddsprimary->Blt(&dest, lpddstitle, &source, DDBLT_WAIT, NULL);

And the error, according to MSDN, was a generic error.

Share this post


Link to post
Share on other sites
That''s really strange... I have almost exactly the same code (save I use C++ Builder''s TGraphic::TBitmap object to do the actual loading) as you do and I''ve never had a problem...

Thus your code seems perfectly fine. I hate to dig up an old fossel, but you might want to revisit your original problem and try and find the actual source, as there might be a relationship, no matter how unlikely. Besides, you''re gonna be hard pressed to do much with a DirectDraw4 interface...

One more thing that I just thought of. Does DirectDraw4 actually support the "DDSURFACEDESC2" structure and corresponding surface pointer? I seem to remember that everything Pre-DirectX 7 was simply "DDSURFACEDESC" and perhaps in your case, "LPDIRECTDRAWSURFACE4". At the very least you can try the lower interface, as even if DirectDraw4 does support the new one, the old one will still work.

Share this post


Link to post
Share on other sites