Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flicker Free

Status
Not open for further replies.

SteveD73

Programmer
Jan 5, 2001
109
GB
Hi

I am attempting to create a simple program to bounce a ball around the screen. I have got the ball moving around the screen but with flicker.

My OnDraw function looks like this:

void CBallAnimView::OnDraw(CDC* pDC)
{
CBallAnimDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

// remove the old ball
pDC->FillSolidRect(x, y, r, r, RGB(255, 255, 255));

// calculate the position of the new ball
x = pDoc->m_ball.pPosition.x;
y = pDoc->m_ball.pPosition.y;
r = pDoc->m_ball.nRadius * 2;

// draw the new ball
pDC->BitBlt(x, y, r, r, &pDoc->m_ball.pBallDC, 0, 0, SRCCOPY);
}

I have a timer which is calling InvalidateRect(...). The rectangle passed to InvalidateRect includes the old ball so it can be removed and the new ball so it can be drawn.

Does anyone have any ideas on how to remove the flicker?

Thank you.
 
DirectX is the best way to go.

The flicker is from not being able to time the redraw with the return scan on the monitor, and the redraw being slow, and not having a double buffer to work with.

I think it is possible to do it with MFC, but for animation, windowed or fullscreen, DirectX (or OpenGL) is best.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top