• ### Announcements

#### Archived

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

# To bitmap or not to bitmap

## Recommended Posts

Ive been trying to get my bitmap on the screen for quite some time. To show me how Ive relied on LaMothe''s "Tricks of the Windows Game Programming Gurus", but because of one of us it has been to no avail. Ive been using his code and tried to follow his examples but I cant get it to work so Ive come here to ask for some advice. I can get my bitmap on the screen using ddutil.cpp, which I found out how to use in an article on this site, but in the book he says these functions are slow since theyre windows functions. Should I try writing my own stuff with the book as guidance, which Ive avoided doing due to my undying trust in things written by pros, does someone know of way to get the stuff to work, or should I do something else? Ive read about other complaints involving his source code, but I already got a replacement cd that had no changes. Thanks for reading, Im just venting my anger

##### Share on other sites
hey,
I know for sure that his bitmap loading function will work. Make sure your bitmap''s dimensions are powers of two. Ex 64x64,
32x32....etc. You will have to change some things to get his code to work with other dimensions.

hope that helps,
skitzo_smurf

##### Share on other sites
Hey skitzo, thanks for replying. Ive been trying for a while and I just cant get it, I load the bitmap, but I cant get it on the back buffer, could you help me out a little? Thanks

##### Share on other sites
Its a 32 x 32 bitmap, I made it with Paint Shop Pro, it works fine with ddutil functions

##### Share on other sites
i''ll email you some code. I would post it here, but I dont wanna pollute the board with a super long reply.

skitzo_smurf

##### Share on other sites
I have also experienced that in LaMothe''s "Tricks of the Windows Game Programming Gurus" book, that his code that goes along w/the bitmap section cannot read bitmaps in of odd number width''s. If you use a bitmap w/certain width deminsions, the program will crash. if you use others it works fine. I have began to write my own BMP loader which (theroreticlly) should be better. I would suggested the same thing.

Hope this helped somehow

l8rz

##### Share on other sites
Or if you''re lazy (like me ) you can have Windows do the job for you, with the assumption your using Windows of course.

  bool CSurface::LoadBitmap(const char* szfilename, IDirectDrawSurface7* lpdds){ bool b_reload = (lpdds) ? true:false; BITMAPINFO* lpbi; void* lpbits; cifstream inp; BITMAPFILEHEADER bmfh; if(inp.open(szfilename)) return true; inp.read(&bmfh, sizeof(BITMAPFILEHEADER)); if(bmfh.bfType != BITMAP_ID) { return true; } lpbi = (BITMAPINFO*)(new char[bmfh.bfOffBits - sizeof(BITMAPFILEHEADER)]); inp.read(lpbi, bmfh.bfOffBits - sizeof(BITMAPFILEHEADER)); lpbits = (void*)(new char[bmfh.bfSize - bmfh.bfOffBits]); inp.read(lpbits, bmfh.bfSize - bmfh.bfOffBits); if(!b_reload) // CreateSurface here... else if(lpbi->bmiHeader.biHeight != (signed)req_h || lpbi->bmiHeader.biWidth != (signed)req_w) { Release(); CreateSurface(lpbi->bmiHeader.biWidth, lpbi->bmiHeader.biHeight, texture); } HDC hdc; lpdds->GetDC(&hdc); StretchDIBits(hdc, 0, 0, lpbi->bmiHeader.biWidth, lpbi->bmiHeader.biHeight, 0, 0, lpbi->bmiHeader.biWidth, lpbi->bmiHeader.biHeight, lpbits, lpbi, DIB_RGB_COLORS, SRCCOPY); lpdds->ReleaseDC(hdc); delete[] lpbi; delete[] lpbits; inp.close(); return false;

"Paranoia is the belief in a hidden order behind the visible." - Anonymous

• ### Forum Statistics

• Total Topics
628291
• Total Posts
2981862

• 11
• 10
• 10
• 11
• 17