PDA

View Full Version : strange problem in drawing my models right



Swe
03-12-2003, 04:09 PM
Hi Gurus,
I encounter a problem on drawing my OpenGL models smoothly in VC++ with MFC applications..
I have read alot of references and examples and am pretty sure that my OpenGL settings are all correct. NOTE, the buffers are clear and my models are drawn ONCE per frame... however, there's a ghost view of the previous frames appear on my current frame.. In the other words, what i see is that the models are drawn twice and the geometries of them are slightly apart while i do the navigation.. Can anyone help me out...
Thanks a million!!!!


The following is the sample codes

CView::KeyDown
{
// one of the case that i update my drawings
if (leftArrowKey)
myposition.x+=1.0

InvalidateRect(NULL);
}
CView::OnPaint()
{
CPaintDC dc(this); // device context for painting
RenderScene()
}


CView::RenderScene()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT|GL_ACCUM_BUFFER_BIT|GL_STENCIL _BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(-m_ClipSize,m_ClipSize,-m_ClipSize,m_ClipSize,1.0, 5000.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(.....);

glDrawBuffer(GL_BACK);

glPushMatrix()
// THis is where i draw my models
glLoadIdentity();
glTranslatef(myposition.x, myposition.y, myposition.z);
DrawModels();
glPopMatrix();
SwapBuffer(hdc);
}

Korval
03-12-2003, 05:40 PM
1) Try getting rid of the glDrawBuffer(GL_BACK) call. I've never used it, and I've never had this problem.

2) Check your glError string just after your glClear call. It may be that you are failing your clear because you are specifying bits (accum?) that you didn't allocate in your pixel format. You probably don't want an accumulation buffer anyway.

3) You really should have that glLoadIdentity() call after your "// THis is where i draw my models". By calling this, you're taking away the camera matrix. That is, your model's position does not change based on the camera matrix anymore.