本程序基于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);
}

解决方案 »

  1.   

    感觉opengl编程在不同的机器上总是有不同的效果  你这个问题我感觉首先得用双缓存技术把ontimer方法下产生的屏幕闪烁现象除去 你再试试
      

  2.   

    应该是坐标不对, 
    被你移动过(x,y,z),然后再绕Z轴旋转一下后已经超出显示范围(此旋转是按照世界坐标轴来旋转, 你是否应该先重置一下,绕本地坐标轴来旋转?)
      

  3.   

    多谢zhucde,是坐标问题,搞定了,下面是正确的代码: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,1.0,0.0); glPushMatrix(); 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(); glPopMatrix();

    SwapBuffers(m_hdc);
    }