Skip to main content
GameDev.net gamedev.net
🔒 Locked

16bit blting causing problems

Started by 2DamnFunky May 21, 2003 at 12:48 PM 2 replies 350+ views
Original Post
2DamnFunky
2DamnFunky
Im making a game that runs windowed mode and so has to be able to run under 16 and 32 bit modes. At the moment i am simply creating a surface and filling it in with a colour (55, 7, 7) and then displaying it to the screen. I choose the colour from the Photoshops pallette and so know what to expect from the values inputted above. All is fine in 32 bit mode but in 16bit mode the colour displayed is not the correct colour. After "printscreen"ing the displayed colour and re-examining it within photoshop i see that the colour values are totally different. Ive checked that my video card runs in 565 16bit mode so the defined macro below should be correct. Here is the relevant code. //Macros #define RGB_32BIT(r, g, b) ((r << 16) | (g << 8) | (b)) #define RGB_16BIT565(r, g, b) ((r << 11) | (g << 5) | (b)) //Function to take 3 colour components and then combine them according to current bitdepth of display and fill surface with the combined colour. void SurfaceFillColour(LPDIRECTDRAWSURFACE7 lpDDSSurface, char red, char green, char blue) { DDBLTFX fx; //fx structure to hold fill colour DDPIXELFORMAT ddpf; //clear out structures ZeroMemory(&ddpf, sizeof( ddpf )); ZeroMemory(&fx, sizeof ( fx)); //initialise the sizes ddpf.dwSize = sizeof( ddpf ); fx.dwSize = sizeof(fx); //detect the bitdepth of the given surface //Get the bit-depth of the surface, so we fill in different //bit-depths correctly lpDDSSurface->GetPixelFormat(&ddpf); //combine colours depending on bitdepth of given surface switch (ddpf.dwRGBBitCount) { case 16: //if its 16bit 565mode per pixel fx.dwFillColor = RGB_16BIT565(red, green, blue); break; case 32: //if its 32bit per pixel fx.dwFillColor = RGB_32BIT(red, green, blue); break; default : throw "This game only supports bitdepths of 16 and 32. Please change accordingly under Windows Display Settings (Right click on desktop)"; } //and apply fill procedure lpDDSSurface->Blt(NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &fx); } //Game Code //-------------------- //prepare the work surface by filling it with color key color SurfaceFillColour(G.lpDDSFrontEndOptionsWorkSurface, 55, 7, 7); etc etc Yes..i am still using direct x 7 but will be upgrading to dx9. But i think the issue is with the bitshifting for 16bit as it works fine for 32bit. Anyone spot any obvious mistakes???
Dreamforger
Dreamforger
sure do some spotting :-)
ridddle me this: if you do this ((g << 5) | b) - what happens to the top three bits of b? Right they get overwritten by the lowest bits of g.

Your problem is that you''re trieing to fit three 8 bit values into 16 bits without loss. Shouldn''t work, not even in DX9 :-)

So what you do is ensure that the r,g,b values fit into their 5,6,5 bit slots:

#define RGB_16BIT565(r, g, b) (((r>>3) << 11) | ((g>>2) << 5) | (b>>3))

So you just loose the least significant bits of each component


Oh and congratulations: you are one of the few people who at least know which part of their code is faulty. Thats much closer to fixing your own bugs than most people are!


Enjoy

---------------------------
I may be getting older, but I refuse to grow up
I may be getting older, but I refuse to grow up
2DamnFunky
2DamnFunky
Thank you so much for the speedy reply.... you do not know how long ive been racking my brain trying to figure out exactly what was causing this problem. I knew it had to be the bitshifting but id seen this macro everywhere. The problem was this macro is probably meant to be used when a user types numbers directly into the macro rather than passing 8bit integers to it.

Thanks again. My game is actually nearly finished. Im doing a rewrite of PacMAn and its looking pretty cool. Ill send you a message when its done and ready for download off this site.

Cheers

2DamnFunky
MattS423
MattS423
Um....you give the color value to the blitter in DWORD form...full 32 bits..

Just use RGB_32BIT and you''ll be fine.
Programmers of the world, UNTIE!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.