Hello,
I have written a program to draw a cube using MFC and OpenGL.
I have also written few functions to rotate the cube on mouse movement using Leftbutton down etc…
Everything is working fine .
But the only problem seems to be that every time I move the mouse over the view,the whole view is redrawn again as a result there is some sort of flickering effect.
I am appending the code…please tell me what I am doing wrong…and how can i rectify it…
void CSim_4_26_02View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_lcapture=true;
m_pt=point;
SetCapture();
//CView::OnLButtonDown(nFlags, point);
}
void CSim_4_26_02View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_lcapture)
{
m_dz = float(point.y - m_pt.y);
m_dx = float(point.x - m_pt.x);
m_angy += m_dz;
m_angx += m_dx;
}
if(m_rcapture)
{
m_tz = float(point.y - m_pt1.y)/40.0f;
m_tx = float(point.x - m_pt1.x)/40.0f;
m_inx+=m_tx;
m_iny+=m_tz;
m_inz += (m_dx + m_dz)/2.f;
}
Invalidate(FALSE);
//CallView();
// CView::OnMouseMove(nFlags, point);
}
void CSim_4_26_02View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_lcapture=false;
//CView::OnLButtonUp(nFlags, point);
ReleaseCapture();
}
void CSim_4_26_02View::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_pt1=point;
m_rcapture=true;
ReleaseCapture();
//CView::OnRButtonDown(nFlags, point);
}
void CSim_4_26_02View::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_rcapture=false;
// CView::OnRButtonUp(nFlags, point);
}
int CSim_4_26_02View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
PIXELFORMATDESCRIPTOR pfd =
{
sizeof ( PIXELFORMATDESCRIPTOR ),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA,
24,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
32,
0, 0,
PFD_MAIN_PLANE,
0,
0, 0, 0
} ;
m_d = new CClientDC ( this ) ;
int pixformat = ChoosePixelFormat ( m_d -> m_hDC, &pfd ) ;
SetPixelFormat ( m_d -> m_hDC, pixformat, &pfd ) ;
DescribePixelFormat ( m_d -> m_hDC, pixformat, sizeof ( pfd ), &pfd ) ;
m_hGRC = wglCreateContext ( m_d -> m_hDC ) ;
wglMakeCurrent ( m_d -> m_hDC, m_hGRC ) ;
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
return 1;
}
Bascially I want smooth movement of the cube(on mouse move)…
Thanks,
aus