Archived

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

arwez

bitmap function quitting on me!

Recommended Posts

arwez    122
When I use my CreateSurfaceFromBitmap function it kicks me out of directdraw right away. If I remove the function it waits for me to hit esc then quits. Can you check my function, I can’t find anything wrong with it. Don’t tell me that the image is not in the directory because I have it put there! THX
    
//////////////////////////////////////////////////////////////////////////////////////////

GLOBAL
LPDIRECTDRAWSURFACE4 character;
//////////////////////////////////////////////////////////////////////////////////////////


int CreateOffscreenSurface(LPDIRECTDRAWSURFACE4 offscreen,											int width,											int height,											int mem_flags)
//Creates an offscreen surface

{
memset(&surfdesc,0,sizeof(surfdesc));
surfdesc.dwSize=sizeof(surfdesc);
surfdesc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
surfdesc.dwWidth = width;
surfdesc.dwHeight = height;
surfdesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | mem_flags;
if(FAILED(ddraw4obj->CreateSurface(&surfdesc, &offscreen, NULL)))
  return(0);

color_key.dwColorSpaceLowValue = 0;
color_key.dwColorSpaceHighValue = 0;

offscreen->SetColorKey(DDCKEY_SRCBLT, &color_key);

return(1);
}
//////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////


int CreateSurfaceFromBitmap(LPDIRECTDRAWSURFACE4 bitmapoffscreen, 
						LPCTSTR file, 
						int width, 
						int height,
						int mem_flags)
{

HBITMAP   bitmaphandle;
BITMAP    bitmap;
HDC	      hdcbitmap;
HDC       hdcsurface;

bitmaphandle = (HBITMAP)LoadImage(NULL, file, IMAGE_BITMAP, width, height, LR_LOADFROMFILE);
GetObject(bitmaphandle,sizeof(bitmap),&bitmap);

CreateOffscreenSurface(bitmapoffscreen, bitmap.bmWidth, bitmap.bmHeight, mem_flags);
hdcbitmap = CreateCompatibleDC(NULL);
SelectObject(hdcbitmap,bitmaphandle);
bitmapoffscreen->GetDC(&hdcsurface);

StretchBlt(hdcsurface,0,0,width,height,hdcbitmap,0,0,width,height,SRCCOPY);
bitmapoffscreen->ReleaseDC(hdcsurface);
DeleteDC(hdcbitmap);
DeleteObject(bitmaphandle);

return(1);
}
//////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////


int Game_Init(void *parms = NULL, int num_parms = 0)
{
InitDirectDraw(800,600,16);
CreateSurfaceFromBitmap(character,"sprite3.bmp",40,40,NULL);
charrect.left = 0;
charrect.top = 0;
charrect.right = 40;
charrect.bottom = 40;

return(1);
} // end Game_Init

//////////////////////////////////////////////////////////////////////////////////////////

    

Share this post


Link to post
Share on other sites
arwez    122
well when I run the debugger it freezes in a blank screen, but I debugged it myself and found out it kicks me out in the createoffscreen surface function.

Share this post


Link to post
Share on other sites
SGreth    218
Cool, now what kind of flags are you passing into CreateOffscreenSurface in the mem_flags variable? Your CreateSurface is bombing and you need to find out why. If this doesn''t work then trying to blit that surface will boot you out of your app...
~S''Greth

Share this post


Link to post
Share on other sites
arwez    122
the memflags is set on 0 for video memory. I looked at
ddutil and gamedev''s bitmap tutorial, I don''t see anything
wrong at all. But when I paste ddutil''s createsurfacefrombitmap
, it works!

Share this post


Link to post
Share on other sites
SGreth    218
Hrmm, I don''t have my code with me (I''m at work..hehe) but I''ll leave a note for myself and I''ll post up some of my code tonight if nobody gets this post before then. I should post it up by 8 eastern time. Hopefully you''ll get it figured out before then though =P
Also...have you checked the return value for Create Surface, I know it''s kind of a pain in the ass to make up a giant switch statement, but it''s handy once you have it written. You might want to just write a method like it to verrify some of the return values.
~S''Greth

Share this post


Link to post
Share on other sites
SGreth    218
I checked my code and everything looks the same, so your best bet is to definately check the return valude from CreateSurface and see what the error is it''s giving you. It returns an HRESULT that you can write a switch statement on to see what the message was. Sorry I couldn''t help any more,
~S''Greth

Share this post


Link to post
Share on other sites