Jump to content
  • Advertisement

Archived

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

mickey

help in putting a bitmap

This topic is 6173 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

hi! please help i''m stuck for a week now figuring out how to load and show a bitmap to the screen. please mention step by step including the functions that i''ll be using. thanks!

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
please mention libray/API u r using.. (eg: DirectX, OpenGL, etc..)

(always anonymous)

Share this post


Link to post
Share on other sites
okey this is what i did,

// somewhere in the winmain(HISNTANCE hInstance......):
HBITMAP bmp;
bmp = LoadBitmap(hInstance, "xxxxxx.bmp");
//in window procedure:
HDC hdc;
//in the WM_PAINT:
GetDC(&hdc);
SelectObject(hdc, bmp);
GetObject(bmp, sizeof(BITMAP), &bmp);
BitBlt(hdc, 100, 100, 300, 300, hdc, 0, 0, SRCCOPY);

there! can''t get to show it on my screen

Share this post


Link to post
Share on other sites
You aren''t using directx here. You''re attempting to use GDI, which is windows'' internal graphics interface. Its very slow compared to directx. What you want to do is set up directx, and texture a quad with your bitmap. If you look in the directx sdk docs, there are tutorials with code on exactly how to do this.
Good luck.

"You are too useless. And now I must beat you." - English subtitle in a Honk Kong Movie.

Share this post


Link to post
Share on other sites
lunarss is right, there''s no DX in your code. However, if you want to try GDI before tackling DX (which might be a good idea), read about BitBlt in the manual. The problem is that you''re trying to BitBlt a DC to itself (using the same argument for hdcDest and hdcSrc). You need to create an off-screen DC, select the bitmap into that, and blit it to your window''s DC.

Try something like this for the WM_PAINT handler:

HDC hTempDC = CreateCompatibleDC(NULL); // Create an off-screen DC
HBITMAP hOldBmp = (HBITMAP)SelectObject(hTempDC, bmp); // Select the bitmap
BitBlt(hDC, 100, 100, 300, 300, hTempDC, 0, 0, SRCCOPY); //Blit
SelectObject(hTempDC, hOldBmp); // Restore the off-screen DC
DeleteDC(hTempDC); // Delete the off-screen DC

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi! actually i was using DX i just omitted the stuffs like

if (lpDDSPrimary->GetDC(&hdc) == DD_OK) { etc.,

to simplify things, actually i know basically how it is done, i just can''t figure it out how to blit my "own" bitmaps. maybe it has something to do with the resource tab?? coz what i do is,
right-click on resource folder on the workspace manager, click on add files to folder and chose one of my bitmap say for example xxxx.bmp, then on my code whereas the line:

hBitmap = LoadBitmap (hInstance, "xxxx.bmp");

i put on the 2nd parameter the filename of my bitmap, is that wrong? actually i already tried copy and paste from someone else code already like for example:

hBitmap = LoadBitmap (hInstance, TEXT ("Bricks")) ;

and i just replaced that 2nd parameter with my bitmap''s filename and there it is, doesn''t work!

p.s. my bmp file also resides on the same directory.

Share this post


Link to post
Share on other sites
Sorry, I don''t get it. Do you load the bitmap from disk or from a resource?

Check the manual on handling errors from LoadBitmap(). The error code will probably tell you something about what''s wrong.

Share this post


Link to post
Share on other sites
i think that''s my problem Ulf O, what i did is, i inserted a bmp file in my workspace and i used that bmp filename on the second parameter of the LoadBitmap() function i mean just try mention anything it might help me solve my problem, thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
plz help! i really can''t figure it out! okey i want to load my bitmap from a resource file. this is what''s inside my .rc file:

// resource.rc
IDB_BITMAP1 BITMAP DISCARDABLE "bitmap1.bmp"

// then in my WM_CREATE, i did this
HBITMAP hbitmap = LoadBitmap(hInstance, IDB_BITMAP1);
// which returns error indicating cannot convert char to int something like that,

// so i changed it to
HBITMAP hbitmap = LoadBitmap(hInstance, "bitmap1.bmp");
GetObject (hBitmap, sizeof (BITMAP), &bitmap) ; // do i have to use this?
// then it works no error, but still it doesn''t blit my bitmap! Please tell me what''s wrong with it, already been through with a lot of books and all of them offers almost the same style on blitting a bitmap why can''t i make mine work! thanks!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!