Advertisement Jump to content


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


Why doesn't colour show up?

This topic is 5367 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''m having trouble using colour pens and brushes in wy win32 app. What it does is it a draws a maze to the screen, and also a path from start to finish overtop. I allow the user to toggle the path on and off, which means I want to draw the maze and the path separately. So I have multiple HDC''s: a primary one, used by my main Draw function, one of the maze, and one for the path. The maze and path also each have their own HBITMAPs. So, the maze and path also each have their own functions, which are called whenever they need to be, that draw the appropriate things onto their respective HDC''s, and then the main draw function uses BitBlt to copy the image onto the primary HDC as necessary. inside my maze drawing function I have something like this: (note that mazeDC, mazeBMP, bmpWidth and bmpHeight are all declared elsewhere; this compiles fine) mazeDC = CreateCompatibleDC(GetDC(hwnd)); mazeBMP = CreateCompatibleBitmap(mazeDC, bmpWidth, bmpHeight); SelectObject(mazeDC, mazeBMP); Then I fill the whole thing with white and do the drawing I need to, yadda yadda... The path drawing function is the exact same In the main drawing function, I create a PAINTSTRUCT, and initialize the primary HDC using BeginPaint(), use BitBlt to blit mazeDC and pathDC onto a specified region on primaryDC, and call EndPaint(). Everything shows up, except that the path is supposed to be yellow and it shows up black, and I have some green and red boxes that are supposed to be drawn with the path layer, and they show up as textured greys. I think the problem is that when I call CreateCompatibleBitmap, it gives me a monochrome bitmap instead of a colour one. I read something in MSDN about creading monochrome vs. colour bitmaps, but I didn''t quite understand what it was saying. Does anybody know where my problem is? (Sorry for the long post, but I tend to explain things in a long-winded way) - Reid

Share this post

Link to post
Share on other sites
Aghhh I finally figured it out!
I had to say

mazeBMP = CreateCompatibleBitmap(GetDC(hwnd), bmpWidth, bmpHeight);

instead of

mazeBMP = CreateCompatibleBitmap(mazeDC, bmpWidth, bmpHeight);

I assumed that when you "created a compatible DC," it made it so any bitmap you create for it would be in the same colour format, but I think I realize now that, since CreateCompatibleDC returns a DC with a 1x1, monochrome bitmap, when you create a bitmap compatible to THAT, it will also be monochrome.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!