Posted 10 July 2001 - 08:51 AM
Howdy.. I''m working through a book that i picked up recently..
"Windows Game Programming for Dummies" By Andre LaMothe..
anywho.. in Chapter 10 it''s explain how to load fullscreen bitmaps, and the source code on the cd is supposed to demonstrate that. Now.. when you compile and run the program, (Prog10_5.cpp for anybody that has read this book) when you give it a 24bit bitmap to display, it corrupts the color scheme horribly. Almost completely green. Now when i checked the source i noticed that if the bitmap of the given file is 24bit, the program automatically converts it to 16bit. I don''t know if the bitmap was supposed to be displayed in green, but somehow i don''t think so. If you just load up the source .bmp in paint or whatever it looks fine.. so I guess what i''m asking is, can anybody help me out with the following algorithm? I think the problem is that it''s not addressing the red components of the bitmap properly but i could be way off. I understand the indexing of the loop, but the >> shift right operator has me a little confused. More than likely due to my less-than-adequate knowledge of how these colors, (8/16/32bit), are built up. any advice would be helpful.
// now convert each 24 bit RGB value into a 16 bit value
for (index=0; index < bitmap->bitmapinfoheader.biWidth*
// extract RGB components (in BGR order), note the scaling
UCHAR blue = (temp_buffer[index*3 + 0] >> 3),
green = (temp_buffer[index*3 + 1] >> 3),
red = (temp_buffer[index*3 + 2] >> 3);
// build up 16 bit color word
USHORT color = _RGB16BIT(red,green,blue);
// write color to buffer
((USHORT *)bitmap->buffer)[index] = color;
} // end for index
temp_buffer is a temporary placeholder for the 24bit bitmap, memory allocated accordingly
bitmap->buffer is the actual working bitmap structure.. I''m guessing that the r,g,b components of temp_buffer must be copied here.
_RGB16BIT is a macro designed to build up a 16 bit color
hmm.. if you could point me toward a site that could help me understand how these colors are built up, and how to index through them properly.. that would probably be the best solution, but thanks for any advice