🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

help loading a bitmap

Started by
2 comments, last by GameDev.net 24 years, 7 months ago
The call to CreateSurface is failing? What HRESULT value does it return?
-ns
-ns-
Advertisement
Why don't you just use the normal bitmap loading function that comes with the DX7 SDK?
ok! guys this a new big problem..
when not!
anyway I'm trying to load a bitmap with LoadImage but always it gives me the same problem with the memory when I try to create a surface. here's the code:
LPDIRECTDRAWSURFACE4 CargaBitmap(LPCTSTR file, int dw,int dh)
{
HBITMAP hbitmap;
BITMAP bitmap;
DDSURFACEDESC2 superf;
IDirectDrawSurface4* superficie;

//carga el bitmap
hbitmap = (HBITMAP) LoadImage(NULL,file,
IMAGE_BITMAP,//PUEDE SER UN CURSOR O UN ICONO
dw,dh,
LR_LOADFROMFILE | LR_CREATEDIBSECTION);//FLAGS PARA COMO CARGAR EL BITMAP
// coje el tamaño del bitmap
GetObject(hbitmap,sizeof(bitmap),&bitmap);
//crea una superficie para este bitmap
ZeroMemory(&superf,sizeof(superf));
superf.dwSize = sizeof(superf);
superf.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
superf.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
superf.dwWidth = bitmap.bmWidth;
superf.dwHeight = bitmap.bmHeight;
if(lpdd4->CreateSurface(&superf,&superficie,NULL)!=DD_OK)
return NULL;


CopiaBitmap(superficie,hbitmap,0,0,0,0);
DeleteObject(hbitmap);
return superficie;

}

HRESULT CopiaBitmap(LPDIRECTDRAWSURFACE4 superficie,HBITMAP hbitmap, int x, int y, int dx, int dy)
{
HDC hdcimagen;
HDC hdcsuperf;
BITMAP bitmap;
DDSURFACEDESC2 superf;
HRESULT hresult;
if (hbitmap == NULL | | superficie == NULL)
return E_FAIL;

superficie->Restore();
hdcimagen = CreateCompatibleDC(NULL);
if (!hdcimagen)
OutputDebugString("no pudo crear compatible\n");
SelectObject(hdcimagen,hbitmap);
GetObject(hbitmap,sizeof(bitmap),&bitmap);
dx = dx == 0 ? bitmap.bmWidth : dx;
dy = dy == 0 ? bitmap.bmHeight : dy;

superf.dwSize = sizeof(superf);
superf.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
superficie->GetSurfaceDesc(&superf);

if ((hresult = superficie->GetDC(&hdcsuperf)) == DD_OK)
{
StretchBlt(hdcsuperf,0,0,superf.dwWidth,superf.dwHeight,hdcimagen,x,y,dx,dy,SRCCOPY);
superficie->ReleaseDC(hdcsuperf);
}
DeleteDC(hdcimagen);
return hresult;
}

sorry for the long code, the problem is always in the CreateSurface funtion.
I appreciate the way you guys help me in the past and will appreciate any help now

thanks
_José

What error is it that you get? General Protection Fault, Compiler error, or something else?

This topic is closed to new replies.

Advertisement