I am using DirectDraw to make a game and I am running it in 8-bit color mode. What I am having a problem with is making a macro to convert RGB values into a single 8-bit color.
Here is the macro:

#define RGB_8BIT(r, g, b) ((r & 224) + ((g & 224) >> 3) + (b >> 6))

Here's my setPixel function:

VOID setPixel(INT x, INT y, BYTE color)
	lpScreen[x + y * lPitch] = color;

lpScreen is defined as an array of BYTEs.
And here is the implementation in WinMain:

setPixel(0, 0, RGB_8BIT(255, 0, 0));

For some reason, this comes out as a greenish-blue when it should be pure red.

Recommended Answers

All 2 Replies

Ooops, I just found out that 8-bit mode has to be palletized, so the macro is actually coming up with an arbitrary index to a color in the default pallet.

That'll do it. Don't forget to mark the thread solved. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.