Jump to content
  • Advertisement
Sign in to follow this  
cptrnet

brush painting messed up color in gdi

This topic is 4817 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 have a graphics class I use, that has a back buffer I paint to. I have some functions that paint a rectangle and a circle. I pass in a color, it creates a brush and paints the shape, then I delete the brush, after a couple minutes everything goes white. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Probably a resource leak, or not restoring the original brush, or something along those lines. You'll need to show some code.

Share this post


Link to post
Share on other sites


//function to draw rect
void Graphics::DrawFillRect(int x, int y, int width, int height, COLORREF color) const
{
RECT r = {x, y, width, height};
HBRUSH hbrush = CreateSolidBrush(color);
FillRect(m_BackDC, &r, hbrush);
DeleteObject(hbrush);
}

//implementation
m_gfx->DrawFillRect(position.x, position.y,
position.x + WIDTH, position.y + HEIGHT,
RGB(255,255,255));

//copying the back buffer to the main DC
BitBlt(m_MainDC, 0, 0, m_ScreenWidth, m_ScreenHeight, m_BackDC, 0, 0, SRCCOPY);



Share this post


Link to post
Share on other sites
I wasn't deleting my brush for clearing the back buffer. Could that be the problem?


void Graphics::Clear(COLORREF color) const
{
RECT r = {0, 0, m_ScreenWidth, m_ScreenHeight};
HBRUSH hbrush = CreateSolidBrush(color);
FillRect(m_BackDC, &r, hbrush);

DeleteObject(hbrush); //Wasnt there before
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!