Re: How do I use 16-bpp surfaces?In Reply to: How do I use 16-bpp surfaces? posted by Fredrik Andersson on January 14, 1998 at 13:53:09:
: I got a problem with 16-bits-per-pixel DirectDraw surfaces.
: I will be very happy for any help I get! Thanks! I too once had trouble with the 16 bit pixel depth and had someone clue me in on my mistakes. Here is some code that I use. The LowBitPos, HighBitPos, and GetPixelFormat is modified code from the book Windows Graphics Programming by Stan Trujillo. Sorry not many comments but email me if you have any questions. // public variables LPDIRECTDRAW lpDD; // DirectDraw object LPDIRECTDRAWSURFACE lpDDSPrimary; // DirectDraw primary surface LPDIRECTDRAWSURFACE lpDDSBack; // DirectDraw back surface DDSURFACEDESC ddsd; WORD numRedBits; WORD numGreenBits; WORD numBlueBits; WORD LowBitPos( DWORD dword ) { DWORD test=1; for (WORD i=0;i>=1; } return 0; } void GetPixelFormat(void) { DDPIXELFORMAT format; ZeroMemory(&format, sizeof(format)); format.dwSize = sizeof(format); if (lpDDSPrimary->GetPixelFormat(&format) == DD_OK) { //WORD loRedBit = LowBitPos(format.dwRBitMask); //WORD hiRedBit = HighBitPos(format.dwRBitMask); //numRedBits = (hiRedBit - loRedBit + 1 ); WORD loGreenBit = LowBitPos(format.dwGBitMask); WORD hiGreenBit = HighBitPos(format.dwGBitMask); numGreenBits = (hiGreenBit - loGreenBit + 1 ); if (numGreenBits == 5) { numRedBits = 10; } else numRedBits = 11; //WORD loBlueBit = LowBitPos(format.dwBBitMask); //WORD hiBlueBit = HighBitPos(format.dwBBitMask); //numBlueBits = (hiBlueBit - loBlueBit + 1 ); } } WORD RGB16(int iRed, int iGreen, int iBlue) { WORD Color = ((iRed > 1) + X); *lpDDMemory = Color; } void LockBackBuffer(void) { HRESULT ddrval; // LOCK BACKBUFFER ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddrval = lpDDSBack->Lock(0, &ddsd, DDLOCK_WAIT, 0); } void UnlockBackBuffer(void) { // UNLOCK BACKBUFFER lpDDSBack->Unlock(&ddsd); } To use, getpixelformat then lock surface, draw pixels, unlock surface, flip or blit surface.
Discuss this article in the forums
See Also: © 1999-2011 Gamedev.net. All rights reserved. Terms of Use Privacy Policy
|