Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        3年前关闭。
                                                                                            
                
        
我似乎无法理解以下代码。明天我将带我的实验室外部设备,如果有人可以解释该代码,将对您有很大帮助。请在下面着重介绍圆函数。如果可能的话,看这段代码有什么问题,我看不到输出(仅白屏)。

    #include<GL/glut.h>
    #include<stdio.h>
    #define PI 3.14

    void circle()
    {
     glClear(GL_COLOR_BUFFER_BIT);

     float i;
        float X=350,Y=630;
        float Radius=5;

      float DEG2RAD=2*PI/180;

       glColor3f(0,0,0);

      glBegin(GL_LINE_LOOP);

      for(i=0;i<360;i++)

    {

        float DEGINRAD=i*DEG2RAD;

        glVertex3f(X+cos(DEGINRAD)*Radius,Y+sin(DEGINRAD)*Radius,0);



    }

    glEnd();

glFlush();
}

void myinit()
{
 glClearColor(1.0,1.0,1.0,1.0);
 glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluOrtho2D(0,499,0,499);

}
void main(int argc,char **argv)
{
 glutInit(&argc,argv);
 glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
 glutInitWindowSize(500,500);
 glutCreateWindow("Circle");
 glutDisplayFunc(circle);
 myinit();
 glutMainLoop();
}

最佳答案

DEG2RAD = 2 * PI / 180;

这是错误的公式,请使用以下命令:

DEG2RAD = PI / 180.0f;

要么

DEG2RAD = 2.0f * PI / 360.0f;

Y偏移不在屏幕上从该范围中选择另一个值

Y = [5 .... 495]

08-04 14:37