我只是想制作一个程序来显示一个带有一个框的窗口,但是当我运行该程序时,我可能只能在 5 次运行中获得一次窗口显示。每次执行命令行时都会给出适当的响应,并且我会在屏幕底部的 gnome 面板上看到窗口的标题,但窗口本身大部分时间都是不可见的。
我完全不知道原因可能出在哪里,我想开始寻找。有什么建议吗?
我使用 gcc main.c -lglut 编译和运行:
#include <stdio.h>
#include <GL/freeglut.h>
void keyb(unsigned char key, int x, int y);
//Window identifier
static int win;
main(int argc, char **argv){
//Initialization
glutInit(&argc, argv);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
win = glutCreateWindow("Test Window");
//Callback
glutKeyboardFunc(keyb);
//OpenGL
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
//Enter main loop
glutMainLoop();
return 0;
}
void keyb(unsigned char key, int x, int y){
printf("Pressed key %c on coordinates %d, %d\n", key, x, y);
if(key == 'q'){
printf("Got q, so qutting\n");
glutDestroyWindow(win);
exit(0);
}
}