Archived

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

ManaStone

What is wrong with this function?

Recommended Posts

I''m new to blitting and I''m trying to create a function that will load a bitmap rearranged into this format: typedef struct BITMAP_FILE_TAG { BITMAPFILEHEADER bitmapfileheader; BITMAPINFOHEADER bitmapinfoheader; PALETTEENTRY palette[256]; UCHAR *buffer; } BITMAP_FILE, *BITMAP_FILE_PTR; onto an offscreen surface.This is the code I used but It won''t work: LPDIRECTDRAWSURFACE4 Make_Bitmap_Surface(BITMAP_FILE_PTR bitmap) { DDSURFACEDESC2 ddsd; LPDIRECTDRAWSURFACE4 lpdds; memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT|DDSD_LPSURFACE; ddsd.dwWidth = bitmap->bitmapinfoheader.biWidth; ddsd.dwHeight = bitmap->bitmapinfoheader.biHeight; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; if (FAILED(lpdd4->CreateSurface(&ddsd,&lpdds,NULL))) return(NULL); UCHAR *dest_ptr; memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); lpdds->Lock(NULL,&ddsd,DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR,NULL); dest_ptr=(UCHAR*)ddsd.lpSurface; memcpy(dest_ptr,bitmap->buffer,sizeof(bitmap->buffer)); lpdds->Unlock(NULL); return (lpdds); }

Share this post


Link to post
Share on other sites
sizeof(bitmap->buffer) will be 4, the size of a char pointer.

You want to use the size of the actual bitmap, which you can get from the BITMAPINFOHEADER or BITMAPFILEHEADER structures; not sure which - have a look in MSDN.


War Worlds - A 3D Real-Time Strategy game in development.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i dont think your supposed to set the DDSD_LPSURFACE flag in the surface description when you create a surface, its completely up to the the driver to choose the best pitch for storing the surface with.

Share this post


Link to post
Share on other sites
Well, telling us it doesn''t work won''t help us help you.

I''m assuming it''s not causing an error or debug crash when you run it since you said nothing about it.

Do this first: Set a breakpoint where this function is called and step through it line by line and make sure all pointers are actually initialized, check the return values of ALL the directx functions and what they say. Also check that the values you assume are being passed are.

People will soon get tired of "guessing" at your problem, you need to provide some more feedback.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you really need to figure out which part is causing the error before anyone can help.
check the surfaces are being created ok.
make sure the bitmap is being loaded properly.
check your code to acces the surface is working, try filling it with a colour, see if that works ok.

infact just looking at the code again your not taking into acount the pitch of the surface when you copy the contents of the bitmap. you need to draw it a line at a time.. after each line you need use the pitch to set the pointer to the beginning of the next line.

Share this post


Link to post
Share on other sites
You''re doing too much hard work man. Let windows do the work for you. Use LoadImage to load the bitmap and get a handle for it. Next create your surface as the size of a bitmap. Then create a device context and select the bitmap into it. Last use the windows GDI call bitblt to copy the image from the bitmap into the surface. That should be all. If you''re still stuck check out ddutil.cpp from microsofts DirectX SDK

Share this post


Link to post
Share on other sites