Try this:
Code: Select all
void PlotPixel(int x, int y, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char *addr = base + (Width*bpp*y) + (x*bpp);
*addr++ = red;
*addr++ = green;
*addr = blue;
}
Also, make sure all your variables have the values in them that you think are there! Now, most video cards actually reverse the red and blue values, so this may screw up, just a heads up! You would need to check the bit masks to see. You can adapt this to 32-bit code easily... depends on where the spare 8-bits is, just increment addr where required. 15/16 bit is a bit harder, but not much... first you must check if you are indeed in 15-bit (R5G5B5) mode, or 16-bit (R5G6B5) mode. Then you would run a function similar to this (again, red and blue may be backwards).
Code: Select all
void PlotPixel16(int x, int y, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned short *addr = base + (Width*bpp*y) + (x*bpp);
*addr = (blue>>3); //Shift right 3 to remove bottom 3 bits 8->5 bits!
*addr<<=6; //Move right 6 bits to make room for green
*addr+=(green>>2); //This removes 2 bits, 8->6
*addr<<=5; //Move this left 5 more bits for red
*addr+=(red>>3); //Again, remove bottom 3 bits
}
15 bits per pixel is almost the same, just change the <<=6 to <<=5, and the green>>2 into green>>3. Hope this helps.