Click to See Complete Forum and Search --> : 32-Bit RGB problem with DirectX


ajoebs03
June 19th, 2006, 09:41 PM
Im having problem drawing a 32-bit rgb on a directdraw surface. Can anyone paste a code snippet for drawing 32-bit rgb on a ddraw surface? Pls include the creation and initialization of the surface as well as the surface description...ive been into this for 3 days already, i been doing my best,i cant solve it, need some help. thanks a lot.. Im using VC++ 6. This is my code:

LPDIRECTDRAW lpDD;
DDSURFACEDESC ddsd;
LPDIRECTDRAWSURFACE lpDDSFront;
LPDIRECTDRAWCLIPPER lpClipper;
LPDIRECTDRAWSURFACE lpDDSBack;

DirectDrawCreate( NULL, &lpDD, NULL );
lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL );

memset( &ddsd, 0, sizeof(ddsd) );
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_CAPS ;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

lpDD->CreateSurface( &ddsd, &lpDDSFront, NULL );//Primary surface

lpDD->CreateClipper( 0, &lpClipper, NULL );
lpClipper->SetHWnd( 0, hwnd ); //hwnd is the cwnd that will contain the //ddraw surface
lpDDSFront->SetClipper( lpClipper );

memset( &ddsd, 0, sizeof(ddsd) );
ddsd.dwSize = sizeof( ddsd );
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY ;
ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
ddsd.ddpfPixelFormat.dwRGBBitCount = 32;
ddsd.ddpfPixelFormat.dwRBitMask = 0xff0000;
ddsd.ddpfPixelFormat.dwGBitMask = 0xff00;
ddsd.ddpfPixelFormat.dwBBitMask = 0xff;
ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0;
ddsd.dwWidth = 800;
ddsd.dwHeight = 600;

lpDD->CreateSurface( &ddsd, &lpDDSBack, NULL);//Back buffer

//Surface have been created, now im trying to draw

int lpitch = 0;
unsigned short *lpscreen = NULL;
int sz;
FILE *file;

file = fopen("C:\\Sunset.bmp", "rb");

sz = 800 * 600 * 4;
BYTE *bitmap_data = NULL;

bitmap_data = (BYTE*)malloc(sz);
fread(bitmap_data, 1, sz, file);
surface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
lpitch = (int)ddsd.lPitch >> 1;

lpscreen = (unsigned short*)ddsd.lpSurface;

BYTE *ptrBitmap = (BYTE*)bitmap_data;
memcpy(lpscreen,(unsigned short*)ptrBitmap,800*600*4);
surface->Unlock(NULL);

/*I was able to draw the image but the color is not correct..looks liek there's too much blue and no red.. Did i do the right way of setting up the surfaces and the surfacedesc?.. if you have another way tosolve this, pls post.. thank you.
*/

philkr
June 20th, 2006, 06:00 AM
Looks like you got the wrong bitmask. Try this:

ddsd.ddpfPixelFormat.dwRBitMask = 0xFF000000;
ddsd.ddpfPixelFormat.dwGBitMask = 0x00FF0000;
ddsd.ddpfPixelFormat.dwBBitMask = 0x0000FF00;

ajoebs03
June 20th, 2006, 06:47 AM
Thanks for your reply, but I tried this bitmask, the surface could not be created with it...not allowed