Jump to content
  • Advertisement


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


bitmap loading .....again yeah I know

This topic is 5977 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, sorry about bringing this subject up again but I really cannot figure out whats wrong with my code. I''am trying to load a bitmap onto a ddraw surface, I already tried this different ways (ddutil,functions from this board..) but nothing succeded.... :-( I am really about to give up. Ok now heres the code: The Bitmap loading function (copied from this forum): LPDIRECTDRAWSURFACE4 Graphics::GPLoadBitmap(char* szBitmap) { LPDIRECTDRAWSURFACE4 bitSurface; BITMAPINFOHEADER infoheader; DDSURFACEDESC2 surfaceDesc; WORD *bitmapData; WORD *bitmapDone; FILE *bitmapFile; BYTE red, green, blue; int padding; bitmapFile = fopen(szBitmap, "rb"); fseek(bitmapFile, sizeof(BITMAPFILEHEADER), SEEK_SET); fread(&infoheader, sizeof(BITMAPINFOHEADER), 1, bitmapFile); // get the padding at the end of the bitmap padding = 4 - ((infoheader.biWidth * 3) % 4); if(padding == 4) padding = 0; ZeroMemory(&surfaceDesc, sizeof(surfaceDesc)); surfaceDesc.dwSize = sizeof(surfaceDesc); surfaceDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; surfaceDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; surfaceDesc.dwWidth = infoheader.biWidth; surfaceDesc.dwHeight = infoheader.biHeight; lpdd->CreateSurface(&surfaceDesc, &(bitSurface), NULL); ZeroMemory(&surfaceDesc, sizeof(surfaceDesc)); surfaceDesc.dwSize = sizeof(surfaceDesc); bitSurface->Lock(NULL, &surfaceDesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); bitmapData = new WORD[infoheader.biWidth * infoheader.biHeight]; bitmapDone = (WORD *)surfaceDesc.lpSurface; for( int y=0; y=0; --y) { for( int x=0; xUnlock(NULL); fclose(bitmapFile); return(bitSurface); } // end load Bitmap Now the drawing function: bool Graphics::GPDrawBitmap(LPDIRECTDRAWSURFACE4 surface,int x,int y,int width,int height,COLORREF srckey ) { //LPDIRECTDRAWSURFACE4 tempsurface = NULL; // clear ddsd RECT dest_rect,source_rect; ZeroMemory(&ddbltfx, sizeof( ddbltfx )); // zero out struct ddbltfx.dwSize = sizeof( ddbltfx ); // set structs size ddbltfx.dwFillColor = 0; // Set the fill color // (0 equals black) lpddsback->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); source_rect.left = 0; source_rect.top = 0; source_rect.right = ddsd.dwWidth-1; source_rect.bottom = ddsd.dwHeight-1; dest_rect.left = x; dest_rect.top = y; dest_rect.right = x+width-1; dest_rect.bottom = y+height-1; if(srckey != NULL){ DDSetColorKey(surface,srckey); // function form ddutil if(FAILED(lpddsback->Blt(&dest_rect,surface,&source_rect,(DDBLT_WAIT | DDBLT_KEYSRC),NULL))) return(false); } if(FAILED(lpddsback->Blt(&dest_rect,surface,&source_rect,DDBLT_WAIT,NULL))) return(false); return(true); } Here in the game initialization Im loading the bitmap: map = Graphics::GPLoadBitmap("Grafik/level1.bmp"); and in the game main loop it should be drawn: Graphics::GPDrawBitmap(map,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,NULL); --------------------------- the code compiles just fine but the screen stays blank.... It would be very nice if someone could take the time to look trough my code ...... thanks in advance.... _amigo

Share this post

Link to post
Share on other sites
Well, I''m tired of looking at other people''s code so heres my own for loading a bitmap (built about 3 years ago when I didn''t care about making it neat looking and I''m too lazy to change it right now or take into account bmps which aren''t multiples of 4 as far as their width goes.):

class Bitmap_File
unsigned int height,width;
unsigned short bpp;
unsigned char *buffer;

Bitmap_File(const char *file)
unsigned char temp;
unsigned short temp2;
unsigned int temp3;
ifstream filen;
MessageBox( NULL, "Problem with opening file","Nova", MB_OK );
filen.read((unsigned char *)&temp3,sizeof(temp3));
unsigned int tempa=temp3;
filen.read((unsigned char *)&temp3,sizeof(temp3));
filen.read((unsigned char *)&temp3,sizeof(temp3));
filen.read((unsigned char *)&temp2,sizeof(temp2));
buffer=new unsigned char[height*width*3];
unsigned char *temi=new unsigned char[height*width*3];
int x=(width*height*3)-1;
for(int y=0;y{
delete temi;

delete buffer;

You should be able to copy it to the surface from there.

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!