Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

MFC OpenGL Invalidate Flickering

sujanaerosujanaero Posts: 12Member
Dear Friends
I am wirting an application for drawing a rectangle on the screen using opengl and mfc. So I implemented the OnPaint function, OnDraw function is also giving the same problem. It's drawing fine. I want to implement pan, zoom, and rotate functionalities. Now everytime the mouse moves I am calling Invalidate() or otherwise I can call Invalidate() in the ::OnDraw function. Pan, zoom and rotate everything is happening but its heavily flickering. I have serached a lot and tried all means like return 1 in the OnEraseBackground() functio for WM_ERASEBACKGROUND etc. But I am getting still flickering . Please help getting rid of this problem. Check the code snippet below.



void CRevolutionProjView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect RectAff;
GetClientRect(RectAff);
glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ) ;
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
glPushMatrix( ) ;
glTranslatef(trans[0], trans[1], trans[2]);
glRotatef(rot[0], 1.0f, 0.0f, 0.0f);
glRotatef(rot[1], 0.0f, 1.0f, 0.0f);
drawcube();
glPopMatrix( ) ;
glFinish( ) ;
glFlush();
SwapBuffers(hDC);
Invalidate(false);
// Do not call CView::OnPaint() for painting messages
}

void CRevolutionProjView::OnMouseMove(UINT nFlags, CPoint point)
{
newP = point;
// TODO: Add your message handler code here and/or call default
int dx = oldP.x - newP.x;
int dy = newP.y - oldP.y;
switch(STATE)
{
case PAN:
{
trans[0] -= dx/100.0f;
trans[1] -= dy/100.0f;
// Invalidate();
}
break;
case ZOOM:
{
trans[2] -= (dx+dy) / 100.0f;
// Invalidate();
}
break;
case ROTATE:
{
rot[0] += (dy * 180.0f) / 500.0f;
rot[1] -= (dx * 180.0f) / 500.0f;
#define clamp(x) x = x > 360.0f ? x-360.0f : x < -360.0f ? x+=360.0f : x
clamp(rot[0]);
clamp(rot[1]);
// Invalidate();

}
break;
}

oldP = newP;

CView::OnMouseMove(nFlags, point);
}

Sign In or Register to comment.