Jump to content
  • Advertisement
Sign in to follow this  
BattleMetalChris

StretchBlt flickering

This topic is 2475 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 backbuffer class, objects of which I can draw to, and then have the buffer BitBlt itself to a destination HDC quite happily, with no problems.

I want to display varying levels of zoom, so I'm trying to also implement a present function which uses StretchBlt to copy a rectangle from the buffer's bitmap to a differently shaped rectangle on the destination window's HDC.

The problem I'm having that that it draws the bitmap really dark every other frame, for reasons I can't work out. This happens even if I only draw to the buffer once, when the program starts, and then blit that same bitmap every time without clearing it.

Here is how I create my Backbuffer:


BackBuffer::BackBuffer(HDC destination, int width, int height, COLORREF background)
{
m_destDC = destination; // get a handle to the device context of the window so we can draw
m_width = width;
m_height = height;
m_bufDC = CreateCompatibleDC(m_destDC); // create the buffer's own device context that is compatible with the destination's DC
m_hSurface = CreateCompatibleBitmap(m_destDC, width, height); // create a bitmap compatible with the window's DC bitmap format
m_hOldObject = (HBITMAP)SelectObject(m_bufDC, m_hSurface); // select the bitmap object, and store the old object so we can put it back when we're finished
m_background = background;

SetStretchBltMode(m_destDC, COLORONCOLOR);

clear();
}

and here is my backbuffer->present() code:


void BackBuffer::present(RECT& bufferRect, RECT& destRect, bool clearFlag)
{
StretchBlt(m_destDC, destRect.left, destRect.top, destRect.right - destRect.left, destRect.bottom - destRect.top,
m_bufDC, bufferRect.left, bufferRect.top, bufferRect.right - bufferRect.left, bufferRect.bottom - bufferRect.top, SRCERASE);
if (clearFlag) clear();
}


At the moment, I draw to the buffer once, just after it's created (just a bit of text and a coloured rectangle) and then capture WM_PAINT and present it then.

Each frame alternates with this:

stretchblt1.png


and then this:

stretchblt2.png

As you can see, on the alternate frames it is drawing, just really dark for some reason.

Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
It's amazing how taking an hour away from your code can work wonders. I came back to see if there were any replies, took one look at the thread and spotted it immediately.


In my StretchBlt statement, I had SRCERASE in there (lack of attention when letting the intellisense complete things I think). Replacing that with SRCCOPY fixed it.

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.

GameDev.net 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!