Bitmap loading problem
I am using the bitmap loading function from Tricks of the Windows game Programming Gurus. I was loading up a 640x480 tileset and then copying that to an offscreen plain surface before calculating the x,y coordinates for the source rectangle (depending on where the actual tile i wanted to draw was)I wanted to blit.
Everything was going fine until i took a closer look at the tiles I was drawing to the screen. For some reason the program doesnt want to draw the top row of pixels or the left most column of pixels.
I decided to draw the whole tileset to the screen. On the tileset (in photoshop) I drew a line of yellow pixels down the left hand side and across the top before i ran the program.
The yellow pixels dont appear where they are supposed to. The top line of yellow pixels just vanishes and the left line of yellow pixels appears as the right most line (suggesting that the program is kind of wrapping the bitmap round -if that makes any sense)
I have spent 3 days continuously searching for a solution. I have gone over and over all the dest rect''s and source rect''s and anywhere I can think of to no avail so I have basically eliminated every possibility except for where it loads in the bitmap.
Sorry for the long post but I have tried everything I could think of before posting this question. If anyone can help or give me ideas i would really, really appreciative.
Thanks for your time
Just my thoughts take them as you will.
"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
January 06, 2001 10:48 PM
Zeke, could you perhaps post the code you are using to read in the bitmap? I don''t happen to have a copy of that book, and I know my bitmap loading works with no problem.
Though, what you described happens if I scale the bmp and then load it onto the backbuffer.
Though, what you described happens if I scale the bmp and then load it onto the backbuffer.
Thanks for the reply. Here is the code for loading a bitmap
Just my thoughts take them as you will.
"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Edited by - Zeke on January 7, 2001 7:16:15 AM
int Bitmap::Load(const char *filename){ int file_handle, // the file handle index; // looping index UCHAR *temp_buffer = NULL; // used to convert 24 bit images to 16 bit OFSTRUCT file_data; // the file data information // open the file if it exists if ((file_handle = OpenFile(filename,&file_data,OF_READ))==-1) return 0; // now load the bitmap file header _lread(file_handle, &bitmapfileheader,sizeof(BITMAPFILEHEADER)); // test if this is a bitmap file if (bitmapfileheader.bfType!=BITMAP_ID) { // close the file _lclose(file_handle); // return error return -1; } // end if // now we know this is a bitmap, so read in all the sections // first the bitmap infoheader // now load the bitmap file header _lread(file_handle, &bitmapinfoheader,sizeof(BITMAPINFOHEADER)); // now load the color palette if there is one if (bitmapinfoheader.biBitCount == 8) { _lread(file_handle, &palette,MAX_COLORS_PALETTE*sizeof(PALETTEENTRY)); // now set all the flags in the palette correctly and fix the reversed // BGR RGBQUAD data format for (index=0; index < MAX_COLORS_PALETTE; index++) { // reverse the red and green fields int temp_color = palette[index].peRed; palette[index].peRed = palette[index].peBlue; palette[index].peBlue = temp_color; // always set the flags word to this palette[index].peFlags = PC_NOCOLLAPSE; } // end for index } // end if // finally the image data itself _lseek(file_handle,-(int)(bitmapinfoheader.biSizeImage),SEEK_END); // now read in the image, if the image is 8 or 16 bit then simply read it // but if its 24 bit then read it into a temporary area and then convert // it to a 16 bit image if (bitmapinfoheader.biBitCount==8 || bitmapinfoheader.biBitCount==16 || bitmapinfoheader.biBitCount==24) { // delete the last image if there was one if (buffer) free(buffer); // allocate the memory for the image if (!(buffer = (UCHAR *)malloc(bitmapinfoheader.biSizeImage))) { // close the file _lclose(file_handle); // return error return -3; } // end if // now read it in _lread(file_handle,buffer,bitmapinfoheader.biSizeImage); } // end if else { // serious problem return -4; } // end else // close the file _lclose(file_handle); // flip the bitmap Flip(bitmapinfoheader.biWidth*(bitmapinfoheader.biBitCount/8), bitmapinfoheader.biHeight); width = bitmapinfoheader.biWidth; height = bitmapinfoheader.biHeight; // return success return 1;}
Just my thoughts take them as you will.
"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Edited by - Zeke on January 7, 2001 7:16:15 AM
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
This must the be n:th time somebody comes here whining about Andre''s bmp-loading code...did he really get everything straight?
Don''t get me the wrong way but I think you should try doing your own routine. It''s good practice, and pretty easy too. Just get the format spec. from wotsit.
[HEADER1] (known as BITMAPFILEHEADER in windows i think, look in the help)
[HEADER2] (BITMAPINFOHEADER (I think...))
[possibly a palette...]
[the bitmap data]
...which is upside down, in BGR and dword aligned. The whole dword align thing buggy me the first time I tried to write one but once i figured out what was wrong it wasn''t that bad (it took quite some time ). Let''s say you have a 98 pixels wide palettized 256 colors bitmap. Each actual row in the picture would occupy 98 * 1 bytes. But since it''s dword aligned we have to check if 98 % 4 > 0 (sizeof() dword equals 4). 98 % 4 = 2 and thus, in this case, the file has a two bytes wide pad added to it at the end/right of each row. Eh, looks like I strayed a bit from the whole subject..
"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album
Don''t get me the wrong way but I think you should try doing your own routine. It''s good practice, and pretty easy too. Just get the format spec. from wotsit.
[HEADER1] (known as BITMAPFILEHEADER in windows i think, look in the help)
[HEADER2] (BITMAPINFOHEADER (I think...))
[possibly a palette...]
[the bitmap data]
...which is upside down, in BGR and dword aligned. The whole dword align thing buggy me the first time I tried to write one but once i figured out what was wrong it wasn''t that bad (it took quite some time ). Let''s say you have a 98 pixels wide palettized 256 colors bitmap. Each actual row in the picture would occupy 98 * 1 bytes. But since it''s dword aligned we have to check if 98 % 4 > 0 (sizeof() dword equals 4). 98 % 4 = 2 and thus, in this case, the file has a two bytes wide pad added to it at the end/right of each row. Eh, looks like I strayed a bit from the whole subject..
"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album
I just dont understand what you are saying. I understand about writing the loader yourself- load in the headers, then the palette then the data but isnt this what La Mothe does anyway? If I dont understand why that code misses off the first row and column of pixels how can i avoid doing the same thing?
And the dword thing, I dont know what you are trying to say. I tried finding the modulus of tile width and 4 (48%4) but it is 0.
Im only a beginner to directX and graphics in general.
Thanks for the reply
Just my thoughts take them as you will.
"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
And the dword thing, I dont know what you are trying to say. I tried finding the modulus of tile width and 4 (48%4) but it is 0.
Im only a beginner to directX and graphics in general.
Thanks for the reply
Just my thoughts take them as you will.
"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Finally! Ive worked it out.
Thanks for the help
Just my thoughts take them as you will.
"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Thanks for the help
Just my thoughts take them as you will.
"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement