24bit pixel plotting
Im reading the book "Tricks of the Windows Game Programming Gurus." I just now read over plotting pixels in 16bit, 24bit, 32bit colors. I know how to do them now but I dont exactly understand how 24 bit is working(although I do know how...but I hate not understanding how its doing it). Heres the code the book shows...
When it plots the three different colors is it just ploting them very close to each other to where it mixes the colors or what? I was also wandering why [pixel_addr] has to be blue, [pixel_addr+1] has to be green, [pixel_addr+2] has to be red.
inline void Plot_Pixel_24(int x, int y,
int red, int green, int blue,
UCHAR *video_buffer, int lpitch)
// this function plots a pixel in 24-bit color mode
// assuming that the caller already locked the surface
// and is sending a pointer and byte pitch to it
// in byte or 8-bit math the proper address is: 3*x + y*lpitch
// this is the address of the low order byte which is the Blue channel
// since the data is in RGB order
DWORD pixel_addr = (x+x+x) + y*lpitch;
// write the data, first blue
video_buffer[pixel_addr] = blue;
// now red
video_buffer[pixel_addr+1] = green;
// finally green
video_buffer[pixel_addr+2] = red;
} // end Plot_Pixel_24
video_buffer is a pointer to surface and lpitch is a pointer to the direct draw surface description lpitch.
because 24 bit color takes three bytes, each byte holds a color, they are almost always ordered (R)ed,(G)reen,(B)lue, or RGB.