• Advertisement

Archived

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

I need help with bitmaps & directdraw

This topic is 6651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, the HDC and HBITMAP are just part of a way of using Windows GDI functions to help you load a bitmap from a file. Once you load the bitmap in, you can copy it to a DirectDraw surface and be done with the HDC and HBITMAP - you don't need to keep them around.

- Splat

Share this post


Link to post
Share on other sites
Advertisement
okay, how do you use hdc and hbitmap? I mean like how do you load them into memory then load them into a surface. My directx book doesn't cover hdc and hbitmap so grrr

Share this post


Link to post
Share on other sites
A couple things: First off, does your book even cover loading bitmaps? It should - if it doesn't its not very good.

Second, if you have the DirectX SDK installed, a sample file I believe called "ddutil.cpp" (never used it) contains a function DDReLoadBitmap() which handles taking a bitmap file and dumping the information correctly into a DirectDraw surface. You could either use that function or read it and learn how to do it yourself.

- Splat

Share this post


Link to post
Share on other sites
Ok, so you have DirectDraw set up and you want to load a bitmap and display it on the screen, right? It's really easy, there's only a couple of steps you need to follow:
1. Create a surface for the bitmap.
2. Load the bitmap into the surface.
3. Blit the bitmap onto the back buffer.
4. Flip the back buffer to the primary surface. (you can do this, right?)

1. and 2.
Luckily, Microsoft made a function that creates an offscreen surface and loads a bitmap into it: DDLoadBitmap(). To use this, though, you need to get the files "ddutil.cpp" and "ddutil.h" from the DirectDraw SDK. If you don't have them and want em, I can send them to you.
Now, after you've included the ddutil.h file, call DDLoadBitmap() like this:

LPDIRECTDRAWSURFACE4 lpDDSBitmap = NULL;

if ( ( lpDDSBitmap = DDLoadBitmap( lpDD, "bitmap.bmp", 0, 0) ) == NULL )
return FALSE;

Now the bitmap is loaded into lpDDSBitmap!

3.
To blit the bitmap onto the back buffer, call BltFast():

RECT rcFrom;
rcFrom.left = 0;
rcFrom.top = 0;
rcFrom.right = BITMAP_WIDTH;
rcFrom.bottom = BITMAP_HEIGHT;

if ( FAILED( lpDDSBack->BltFast( 0, 0, lpDDSBitmap, &rcFrom, DDBLTFAST_WAIT ) ) )
return FALSE;

What the DDLoadBitmap() function does is creates a HBITMAP and a DirectDraw sufrace, uses a Windows function (LoadImage()) to load the bitmap from a resource or a file into the HBITMAP, then blits the bitmap from the HBITMAP to the DirectDraw Surface using another Windows function (StretchBlt()).

If you need any more help, send me and email or post to this thread.

I would suggest that you look over the function really well before you use it so you know what it's doing...

------------------
- mallen22@concentric.net
- http://members.tripod.com/mxf_entertainment/

[This message has been edited by Matthew Allen (edited November 04, 1999).]

Share this post


Link to post
Share on other sites
Really you don't have to know or care about HBITMAPS or nearly any GDI object.

As another poster said, if you want to load bmp files, there is a function which does it for you, so you can just live in ignorant bliss =)

You can think of a DC ( a device context) as just that, the state of a particular device, like the screen you are reading this off of, or a printer.

A HBITMAP is basically a handle to a bitmap, be it a blank memory buffer, or if you get it from a DC, a copy of that contexts "output" or display.

Share this post


Link to post
Share on other sites
Okay, I understand how to initialize directdraw, and all the surfaces and flipping, but i don't really understand the whole bitmap part. I got some code from a guy and he created two HDCs and a HBITMAP and adsljkf grrr i just dont get it. Can someone explain HDC and HBITMAP and everything else there is in a process of displaying bitmaps to a surface. Do you need a HDC for every bitmap you display on the screen? grrr plz help hehe

Thanks, AcidJazz

P.S. If you wouldn't mind helping me a little one on one, just add me to your icq list, my uin is 16357086. If you have aim, my sn is AcidJazz13 Thanks again

Share this post


Link to post
Share on other sites

  • Advertisement