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

Game Programming Genesis Part V : Palettes and Pixels in DirectDraw

Started by Myopic Rhino Feb 18, 2001 at 12:28 AM 2 replies 1.7k views
Bleakcabal
Bleakcabal
While I am able to make his 16bpp pixel plotting work, when I try to use his technique for 32 bpp the color is right but the pixels are not at the right place ( in 800x600 I put a pixel at 400-300 and it is near the lower left corner ).

Here is the code I am using :

if (scr_bpp == 32)
{
UINT *video_buffer;

memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
lpddsback->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
video_buffer = (UINT *)ddsd.lpSurface;

video_buffer[x + (y*ddsd.lPitch >> 1)] = (UINT)RGB_32BIT(red, green, blue);

lpddsback->Unlock(ddsd.lpSurface);
}

if (scr_bpp == 16)
{
USHORT *video_buffer;

memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
lpddsback->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
video_buffer = (USHORT *)ddsd.lpSurface;

if (nPixelFormat == 16)
video_buffer[y * (ddsd.lPitch>>1) + x] = (USHORT)RGB_16BIT565(red, green, blue);
else
video_buffer[y * (ddsd.lPitch>>1) + x] = (USHORT)RGB_16BIT555(red, green, blue);

lpddsback->Unlock(ddsd.lpSurface);
}


WHO DO THEY
THINK THEY'RE
FOOLING : YOU ?





[edited by - bleakcabal on June 19, 2002 11:41:35 AM]
WHO DO THEYTHINK THEY'REFOOLING : YOU ?
Alimonster
Alimonster
Check yer pitch. It should be >> 2, not 1, in 32bit. This is because the pitch is given in bytes. When you want 16 bit each pixel takes up two bytes, so you >> 1 (divide by two). In 32 bit each pixel takes up 4 bytes, so you must >> 2 (divide by four).

[edited by - Alimonster on June 20, 2002 9:39:53 AM]
AndreiVictor
AndreiVictor
Hi I have just read this part of the tutorial and I'm wondering what's the proper setting for creating a color table for 256 and 16bits? As much as possible, I want it to grasp the whole set of colors. In Tricks of the Windows Game Programming Gurus 2nd ed. by Andre LaMothe, what he did there was to make a random function mod 256 for RGB and the first and last entries to be black and white, which I find not a good way because there are chances in random to have the exactly the same as some other entries and the color arrangement would be chaotic. So, anyone here has a good formula/way to make a good color table?

By the way, I made 16bits, and 32bits bitmap file containing all the possible colors I like? Is it possible to load these bitmaps and get their palettes so I can use them? How?
c",)

Topic Locked

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

Sign in to reply to this topic.