【发布时间】:2021-09-12 03:08:24
【问题描述】:
我遇到了一个问题,在我认为是 glutMainLoop 的一次迭代之后,渲染的三角形会消失。
我在 linux 上运行这个。
// g++ main.cpp -lglut -lGL -o main
#include <stdlib.h>
#include <iostream>
#include <GL/freeglut.h>
#include <GL/gl.h>
void keyboard(unsigned char key, int x, int y) {
// 27 is ascii for the escape key
if (key == 27) {
std::cout << "Closed because user hit escape key." << std::endl;
glutDestroyWindow(glutGetWindow());
}
}
void draw_triangle() {
glClearColor(0.4, 0.4, 0.4, 0.4);
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_TRIANGLES);
glVertex3f(-0.7, 0.7, 0);
glVertex3f( 0.7, 0.7, 0);
glVertex3f( 0 , -1, 0);
glEnd();
glFlush();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("");
glutKeyboardFunc(keyboard);
glutDisplayFunc(draw_triangle);
glutMainLoop();
}
【问题讨论】:
标签: c++ linux opengl glut freeglut