OpengL动画问题
本程序基于mfc对话框的在opengl中画几何字体,用到了glut包的函数,但是在onTimer中旋转字体时发现没有看到旋转的字体(动画只是一闪而过)。请大家帮忙修改下。谢谢。
OnCreate函数:
添加的代码:
// TODO: Add your specialized creation code here
UINT_PTR TimeToDraw = this->SetTimer(1,500,NULL);
OnTimer函数:
void CDrawTextOGLDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (nIDEvent==1)
{
if (Rotate_Angle<360.0)
{
Rotate_Angle+=0.05;
}
else
Rotate_Angle = 0.0;
Invalidate(FALSE);
}
CDialog::OnTimer(nIDEvent);
}
OnPaint函数:
添加了:this->output(-0.7,0.0,0.0,"Hello World!");
Output函数:
void CDrawTextOGLDlg::output(GLfloat x, GLfloat y, GLfloat z, char *text)
{
char *p;
//make glClearColor function called before glClear
//glClearColor(0.0,1.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
glLineWidth(7.0);
glRotatef(Rotate_Angle,0.0,0.0,1.0);
glTranslatef(x, y, z);
glScalef(.002,.002,.002);
glPushMatrix();
glColor4f(1.0f,0.0f,0.0f,1.0f);
for (p = text; *p; p++)
glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);
glPopMatrix();
SwapBuffers(m_hdc);
}