Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Finding colors in DirectX

This topic is 6376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been looking around and I can''t find anything on how to do this. What I''m trying to do is find out what a color is, at a certain location on a directx surface. I need something that will tell me what the color index is. I''m in 8-bit mode, but I need the same thing for 16-bit also. So I also need something that will tell me the RGB of a certain location. If anyone can tell me how it would be a great help. Thanks.

Share this post

Link to post
Share on other sites
Well there are two ways that you could do this.

The first cheap and slow one is to:
1. Use the GetDC member of the interface (Wow that sounds smart) to get a device context.
2. Use the GetPixel GDI function to get a color from a certain point on a specified device context this will be of COLORREF type which is a long 32 bit color descriptor.
3. To get RGB values use the GDI macros GetRed GetGreen and GetBlue (Not sure those are the exact names but it''s similar)
4. Now you have the RGB color, If you need the palette index just look up that value in your palette.

The second more professional way is to:
1. Lock the surface.
2. Read the format specific color from the video memory pointer.
3. For 16 bit convert the format specific color to a 32 bit color (your going to have to research color conversion for this)
3. For 8 bit this unsigned long value will be the index of the palette.

I would probably use the first method for 16 bit color and the second for palettes.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!