Thread: Bitmaps

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    Bitmaps

    Hey, I was just wondering how I can load and display a bitmap... I can draw rectangles/squares/circles/ellipses/other stuff, but I'm trying to make space invaders and I'm trying to draw a bitmap of a ship instead of using a rectangle or something . I've gotten as far as "LoadImage" (so now I have a handle), but how do I actually draw the image on the screen? Do I use DrawState or BitBlt or something?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    57
    BitBlt works fine. Go to GameTutorials and read the "Displaying a Bitmap" Tutorial in the win32 section. Should work quite nicely .
    Language: C++
    Compiler: Visual C++ 6.0
    Currently Working On: Simple OpenGL aspects

  3. #3
    Unregistered
    Guest
    Ahah! That should do the trick Thanks, I didn't know it was there.

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    whoops... blocked the cookie. That was me earlier
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    Hunter2:
    Hello,have you ever tried to display 2 or more 8-bit bitmaps on the screen at the same time?that would be interesting.

    if you've done, could you tell me the problems if you meet, I've met a lots.
    (BTW,I am using DirectX)
    Last edited by SuperNewbie; 05-23-2002 at 06:05 AM.
    Don't laugh at me,I am just a SuperNewbie.

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Actually, I'm using the Win32 GDI stuff, so I actually have no clue about DX stuff. But if you look at the link farther up, there'll probably be more at that site - and BTW, I'm a SuperNewbie too, and I'm just about to try displaying 2 or more 8-bit bitmaps on the screen at the same time (as in I'm making a "Space Invaders" game).

    Good luck on you DirectX stuff though!
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #7
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Hey, I was looking at a tutorial for the bitmap stuff, and it had a function to display a bitmap where it takes a "BUFFER *pBuffer" and some other stuff... but when I looked at what it did, I thought a simple reference would have done the job just as well, and that the reference would have been easier to use... Is there any reason why I shouldn't use a ref instead?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    Sorry,I didn't quite get myself clear, can you get more detail about this reference?I think that kind of "PBuffer" is just a pointer to point the bitmap memory and draw with it.
    Don't laugh at me,I am just a SuperNewbie.

  9. #9
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Yeah, it was a pointer... but I thought that it would be easier just to use a reference, because using a reference would save the trouble of using the -> thing instead of just using dot. Is it standard or something to use a pointer instead of a reference?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Hunter2
    Yeah, it was a pointer... but I thought that it would be easier just to use a reference, because using a reference would save the trouble of using the -> thing instead of just using dot. Is it standard or something to use a pointer instead of a reference?
    In C you couldn't pass things to functions as references, it had to be pointers. So in C++ when you can pass things to functions as references some people liked the old way better and continued/continue to use the pointer way. Did this clear it up?

  11. #11
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    oh, I see.. that explains a LOT Thanks!
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  12. #12
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Hey, there's something wrong with my program... I have 3 HDC's: dcFront, dcBack, dcBitmap.

    somewhere in WinMain():

    I first select an HBITMAP into dcBitmap, then
    BitBlt dcBitmap into dcBack, then
    BitBlt dcBack into dcFront (which is the screen).

    When I run the program though, the bitmap turns out some black thing with fuzzy white dots across it... but if I just BitBlt'd dcBitmap into dcFront directly, it worked fine. dcBitmap and dcBack were both created using CreateCompatibleBitmap(dcFront). Does anybody know what's wrong? (I took most of the code out of a sample, and the sample worked fine...)
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  13. #13
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    How about trying memcpy() functions from dcbitmap to dcback?

  14. #14
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    thanks for the suggestion, but I don't think that would work, because dcBack is the offscreen buffer thingee. Everything gets drawn to that first, as if it's the screen, then it (the whole package) gets drawn to dcFront, which is the screen - that's to prevent flickering. memcpy() would just make it exactly the same as dcBitmap, which defeats the purpose of having dcBack.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  15. #15
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    Originally posted by Hunter2
    thanks for the suggestion, but I don't think that would work, because dcBack is the offscreen buffer thingee. Everything gets drawn to that first, as if it's the screen, then it (the whole package) gets drawn to dcFront, which is the screen - that's to prevent flickering. memcpy() would just make it exactly the same as dcBitmap, which defeats the purpose of having dcBack.
    I don't know where the dcBitmap is, if it's in the system memory or video memory,then my thought is that:

    1.use memcpy() to copy the whole bitmap into the offscreen,dcBack.
    2.release the memory occupied by the dcBitmap,now the dcBack has the bitmap.
    3.do anything you want(bitblt() or something like flip(),it means flip between the surfaces,dcBack and dcFront if they have the same size).

    and there won't have any flicker,at least not in my case .
    is this what you want?, or I have some other ways if it doesn't work.
    Last edited by SuperNewbie; 05-26-2002 at 06:11 AM.
    Don't laugh at me,I am just a SuperNewbie.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing bitmaps efficiently
    By scwizzo in forum Windows Programming
    Replies: 28
    Last Post: 06-30-2009, 08:25 PM
  2. DX9 Not Displaying Bitmaps
    By Sentral in forum Game Programming
    Replies: 9
    Last Post: 01-31-2006, 05:35 AM
  3. MFC: Multiple clicks shows multiple bitmaps - how?
    By BrianK in forum Windows Programming
    Replies: 0
    Last Post: 06-20-2004, 07:25 PM
  4. Loading bitmaps with createfile() +CreateDIBSection
    By Stevo in forum Windows Programming
    Replies: 7
    Last Post: 05-13-2004, 09:22 PM
  5. using standard bitmaps in the toolbar editor
    By Kibble in forum Windows Programming
    Replies: 0
    Last Post: 12-23-2002, 08:43 PM