Hi,
I solved the following problem:
http://forums.codeguru.com/showthrea...ight=animation
but now i have lost that code. I dont know how to do it. Somebody plz guide me how to do animation using double buffering code.
Zulfi.
Printable View
Hi,
I solved the following problem:
http://forums.codeguru.com/showthrea...ight=animation
but now i have lost that code. I dont know how to do it. Somebody plz guide me how to do animation using double buffering code.
Zulfi.
You create two bitmaps of the same size and bitdepth
one holds the active/visible frame
one holds the new frame you're working on
your OnPaint only blits the invalidated rect from the visible bitmap to the screen.
When your new frame is finished, you flip the pointers/handles to the 2 bitmaps so the "new frame" becomes the visible frame, and the previously visible frame now becomes the new frame bitmap you'll be working on.
Invalidate the entire screen, OnPaint will do the rest
Repeat above 3 steps until whatever end condition is reached.
Hi,
Thanks for your guidance. Sorry I am following the previous approach given in the link which says:
I have added WM_ERASEBKGND. It has removed the flickering but the black color is there as mentioned in that post and the grey color window is also created which slowly engulfs the entire screen.Quote:
To get rid of the flickering, handle WM_ERASEBKGND and just return TRUE in it.
To get rid of the black, you need to paint the entire memory DC in the color you want before starting to paint your road etc. You can use FillRect for this.
I dont know how to paint the entire memory DC???
Kindly guide me what should i do.
Zulfi.
Hi,
I have modified my OnDraw but still i cant solve the problem. Somebody plz guide me.
I have attached the output of program. Somebody plz guide me.Code:void CAnimationCarView::OnDraw(CDC* pDC)
{
CAnimationCarDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CBitmap XMap,*pOldMap;
CRect rc;
GetClientRect(&rc);
//pDC->DPtoLP( rc );
CBrush brBackground( RGB( 255, 255, 100 ) );
//pDC->FillRect( rc, &brBackground );*/
XMap.CreateCompatibleBitmap(pDC,rc.Width(), rc.Height());
CDC WorkDC;
CDC *MyDC=&WorkDC;
MyDC->CreateCompatibleDC(pDC);
MyDC->FillRect(rc, &brBackground);
pOldMap=MyDC->SelectObject(&XMap);
road(MyDC);
mountain(MyDC);
stationary_car(MyDC);
pDC->BitBlt(0, 0, rc.Width(), rc.Height(), MyDC, 0, 0, SRCCOPY);
MyDC->SelectObject(pOldMap);
XMap.DeleteObject();
MyDC->DeleteDC();
}
Zulfi.
You should use the codes like the following:
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap bmpMem;
bmpMem.CreateCompatibleBitmap(pDC, rectClient.Width(), rectClient.Height());
CBitmap* pBmpOld = dc.SelectObject(&bmpMem);
int oldBkMode = dc.SetBkMode(TRANSPARENT);
COLORREF oldTextColor = dc.SetTextColor(m_crInActiveTabText);
// Do your filling here.
// dc.FillRect(..);
dc.SetBkMode(oldBkMode);
pDC->BitBlt(rectClient.left, rectClient.top,rectClient.Width(), rectClient.Height(),&dc, 0, 0, SRCCOPY);
dc.SelectObject(pBmpOld);
bmpMem.DeleteObject();
If the problem is still exist, I think you should check the InvalidateRect method that you used for your animating.
Best Regards
Jackie Zhang
(E-XD++ MFC Visualization Library at: code-home.com)
Hi,
Thanks for your response. I am getting syntax error at the following line:
The error is:Code:COLORREF oldTextColor = dc.SetTextColor(m_crInActiveTabText);
What value should be assigned to it??Quote:
D:\Zulfi\VC6\CGAM LAB\AnimationCar\AnimationCarView.cpp(250) : error C2065: 'm_crInActiveTabText' : undeclared identifier
Plz guide me.
Zulfi.
Hi,
Some body plz help me with this problem. I have now ported it to VS 2008.
Zulfi.
See http://msdn.microsoft.com/en-us/libr...=vs.90%29.aspx
The parameter for SetTextColor() is of type COLORREF and specifies the colour of the text as an RGB colour value. If the compiler is complaining that 'm_crInActiveTabText' is an undeclared identifer, then you need to determine what colour the text here is required to be set and use that value.
Hi,
Thanks for your response. He has used SetTextColor:
I dont have an text in my code. I cant figure out what should i be using instead of this. Plz guide me.Code:COLORREF oldTextColor = dc.SetTextColor(m_crInActiveTabText);
Zulfi.
If you do not draw any text then you can comment this line out. Or just remove it.
Hi,
Thanks for your guidance. I have made changes based upon my understanding of Andytim's hints:
However I dont have a one line code for filling. There are actually functions and not rectangle and intead they are polygons so i have called these functionsCode:CRect rectClient;
GetClientRect(&rectClient);
CDC WorkDC;
WorkDC.CreateCompatibleDC(pDC);
CBitmap bmpMem;
bmpMem.CreateCompatibleBitmap(pDC, rectClient.Width(), rectClient.Height());
CBitmap* pBmpOld = WorkDC.SelectObject(&bmpMem);
int oldBkMode = WorkDC.SetBkMode(TRANSPARENT);
road(&WorkDC);
mountain(&WorkDC);
stationary_car(&WorkDC);
WorkDC.SetBkMode(oldBkMode);
pDC->BitBlt(rectClient.left, rectClient.top,rectClient.Width(), rectClient.Height(),&WorkDC, 0, 0, SRCCOPY);
WorkDC.SelectObject(pBmpOld);
bmpMem.DeleteObject();
Code:road(&WorkDC);
mountain(&WorkDC);
stationary_car(&WorkDC);
instead of:
Despite of these changes my program output is exactly same as it was before (output attached). I am still getting the grey window which covers my actual output and i dont want this.Code:
// Do your filling here.
// dc.FillRect(..);
Plz solve this problem. Thanks for your time and guidance.
Zulfi.
Hi,
Thanks. I have got solution for my problem:
http://social.msdn.microsoft.com/For...orum=vcgeneral
It was same as suggested by Mr. andytim but i was not able to find out that i was doing the double buffereing inside the stationary_car method also.
My altered code (i.e ::OnDraw(...) and stationary_car(...) method) is now:
Rest of the functions are same. I am also no more using floodfill in stationary_car(....)Code:void CAnimationCarView::OnDraw(CDC* pDC)
{
CAnimationCarDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect rectClient;
GetClientRect(&rectClient);
CDC WorkDC;
WorkDC.CreateCompatibleDC(pDC);
CBitmap bmpMem;
bmpMem.CreateCompatibleBitmap(pDC, rectClient.Width(), rectClient.Height());
CBitmap* pBmpOld = WorkDC.SelectObject(&bmpMem);
int oldBkMode = WorkDC.SetBkMode(TRANSPARENT);
land(&WorkDC);
road(&WorkDC);
mountain(&WorkDC);
stationary_car(&WorkDC);
WorkDC.SetBkMode(oldBkMode);
pDC->BitBlt(rectClient.left, rectClient.top,rectClient.Width(), rectClient.Height(),&WorkDC, 0, 0, SRCCOPY);
WorkDC.SelectObject(pBmpOld);
bmpMem.DeleteObject();
}
}
void CAnimationCarView::stationary_car(CDC* MyDC)
{
CPoint poly5[8]={CPoint(i,402),CPoint(j,402),CPoint(j,415),CPoint(k,415), CPoint(j, 402), CPoint(j, 415), CPoint(k, 415), CPoint(i, 402) };
//CPoint poly6[8]={CPoint(n,415),CPoint(o,428),CPoint(l,415),CPoint(m,428), CPoint(l, 415), CPoint(n, 415), CPoint(o, 428), CPoint(m, 428) };
//not making a proper rectangle as with lines
pOldPen=NULL;
pOldBrush= NULL;
pOldBrush=NULL;
pOldBrush=MyDC->SelectObject(&brGrey);
MyDC->Polygon(poly5, 4);
//line(i,402,j,402);
Line(n,415,o,428,MyDC);
//line(l,415,m,428);
Line(l,415,m,428,MyDC);
//line(l,415,n,415);
Line(l,415,n,415,MyDC);
//line(o,428,m,428);
Line(o,428,m,428,MyDC);
pOldBrush=NULL;
pOldBrush=MyDC->SelectObject(&brGrey);
CPen penBlack(PS_SOLID, 5, RGB(0,0,0));//Black color
pOldPen=NULL;
pOldPen=MyDC->SelectObject(&penBlack);
MyDC->MoveTo(r,434);
MyDC->AngleArc(q,434,5,0,360);
//pDC->FloodFill(q,434,RGB(0,0,0));
//circle(r,434,5);
pOldPen=NULL;
pOldPen=MyDC->SelectObject(&penBlack);
MyDC->AngleArc(r,434,5,0,360);
}
Zulfi.
Please edit your post replacing the Quote tags with the Code ones!
Otherwise your code is unreadable!
Hi,
Thanks again for everybody's cooperation.
Zulfi.