c - OpenGL程序不会停止接受输入并且不显示输出

标签 c opengl output infinite-loop

        //Program to implement Basic Incremental Algorithm
        //Working on ubuntu
      #include <GL/glut.h>
      #include<stdlib.h>
      #include <stdio.h>

       GLfloat x0,x1,y0,y1; //Input variables taken as global 
       int flag=1;   //variable for display1()
       void init(void)
        {
             glClearColor(0.0,0.0,0.0,0.0);
             glMatrixMode(GL_PROJECTION);
             glLoadIdentity();
             gluOrtho2D(0.0,500.0,0.0,500.0);
        }
        void PutPixel(GLfloat x,GLfloat y)
        {
             glBegin(GL_POINTS);
             glVertex2f(x,y);      //To display pixels on-screen
             glEnd();
             glFlush();
        }
        void display1(void)
        {
             if (flag==1)   
             {
                   glClear(GL_COLOR_BUFFER_BIT);
                    glColor3f(0.7,1.0,1.0);
                    GLfloat m,c,y;
                    GLfloat i;                   //BIA algorithm
                    m=(y1-y0)/((float)(x1-x0));
                    c=y1-m*x1;
                    for (i=x0; i<=x1; i+=0.01)
                     {
                          y=c+m*i;
                          PutPixel(i,y);
                      }
                    flag++;
              }
         }
         void Input()
         {
            printf("Enter the co-ods\n");
            scanf("%f %f",&x0,&y0);
            scanf("%f %f",&x1,&y1);
         }
         int main(int argc, char **argv)
           {
             Input();
             glutInit(&argc,argv);
             glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
             glutInitWindowSize(500,500);
             glutInitWindowPosition(100,100);
             glutCreateWindow("BIA");
             init();
             glutDisplayFunc(display1);
             glutMainLoop();
             return 0;
            }

我在开始时将flag初始化为全局变量并将其设置为1。flag用于display1()以确保它只执行一次。这只是我试图确保显示输出的一种方法。 任何人都可以,请帮忙!

为什么程序不停止接受输入?

最佳答案

它正在工作。我仍然不确定对其进行了哪些编辑或更改。但它正在工作!它正在显示一些输出

关于c - OpenGL程序不会停止接受输入并且不显示输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26817887/

相关文章:

OpenGL - 将阴影立方体贴图投影到场景上

java - Hadoop 不产生任何输出

c++ - 调用另一个函数的函数会给出错误的输出 C++?

c - 在 C 中 float 和加倍

清理 argv 程序

OpenGL - 采样器阵列限制?

java - FilterOutputStream 的使用

python - Ctypes 找不到我加载的 dll 的 dll 依赖项

c - 在实际打开文件之前验证文件路径

c++ - 如何绕三角形的顶点旋转?