943,954 Members | Top Members by Rank

Ad:
Jul 29th, 2008
0

DirectDraw 8-bit color algorithm

Expand Post »
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:
c++ Syntax (Toggle Plain Text)
  1. #define RGB_8BIT(r, g, b) ((r & 224) + ((g & 224) >> 3) + (b >> 6))
Here's my setPixel function:
c++ Syntax (Toggle Plain Text)
  1. VOID setPixel(INT x, INT y, BYTE color)
  2. {
  3. lpScreen[x + y * lPitch] = color;
  4. }
lpScreen is defined as an array of BYTEs.
And here is the implementation in WinMain:
c++ Syntax (Toggle Plain Text)
  1. setPixel(0, 0, RGB_8BIT(255, 0, 0));

For some reason, this comes out as a greenish-blue when it should be pure red.
Reputation Points: 128
Solved Threads: 43
Posting Whiz
death_oclock is offline Offline
389 posts
since Apr 2006
Jul 29th, 2008
0

Re: DirectDraw 8-bit color algorithm

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.
Last edited by death_oclock; Jul 29th, 2008 at 6:30 pm.
Reputation Points: 128
Solved Threads: 43
Posting Whiz
death_oclock is offline Offline
389 posts
since Apr 2006
Jul 29th, 2008
0

Re: DirectDraw 8-bit color algorithm

That'll do it. Don't forget to mark the thread solved.
Reputation Points: 18
Solved Threads: 4
Light Poster
chaosprime is offline Offline
46 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Game Development Forum Timeline: Best programing language for games
Next Thread in Game Development Forum Timeline: Web Based Tactical ORPG





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC