我想创建一个覆盖整个桌面屏幕的窗口,显示颜色为 RGB,然后是 VIBGYOR。颜色延迟应为 1 秒。 这是我编写的代码,但输出不符合预期。谁能告诉我哪里错了?
#include<GL/freeglut.h>
#include<GL/glut.h>
#include<stdio.h>
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize(1280,1024);
glutCreateWindow("Displays");
glutFullScreen();
glClearColor (1.0, 0.0, 0.0, 0.0); //Red
glClear(GL_COLOR_BUFFER_BIT);
sleep(1);
glClearColor(0,1,0,0); //Green
glClear(GL_COLOR_BUFFER_BIT);
sleep(1);
glClearColor(0,0,1,0);
glClear(GL_COLOR_BUFFER_BIT); //Blue
sleep(1);
glClearColor(0.933, 0.510, 0.933, 0.0); //violet
glClear(GL_COLOR_BUFFER_BIT);
sleep(1);
glClearColor(0.294, 0.000, 0.510, 1); //Indigo
glClear(GL_COLOR_BUFFER_BIT);
sleep(1);
glClearColor(0,0,1,1); //Blue
glClear(GL_COLOR_BUFFER_BIT);
sleep(1);
glClearColor(0,0.502,0,1); //Green
glClear(GL_COLOR_BUFFER_BIT);
sleep(1);
glClearColor(1,1,0,1); //Yellow
glClear(GL_COLOR_BUFFER_BIT);
sleep(1);
glClearColor(1,0.647,0,1); //Orange
glClear(GL_COLOR_BUFFER_BIT);
sleep(1);
glClearColor(1,0,0,1); //Red
glClear(GL_COLOR_BUFFER_BIT);
sleep(1);
glutMainLoop();
}
谢谢。
最佳答案
您正在使用 GLUT_DOUBLE
( double buffering ) 初始化显示模式,您需要在每次完成缓冲区工作时添加 gluSwapBuffers()
并且想要显示它。
...
glClearColor(1,0,0,1); //Red
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
sleep(1);
...
Difference between single buffered(GLUT_SINGLE) and double buffered drawing(GLUT_DOUBLE)
When using GL_SINGLE, you can picture your code drawing directly to the display.
When using GL_DOUBLE, you can picture having two buffers. One of them is always visible, the other one is not
What is the nicest way to close GLUT
void glutLeaveMainLoop ( void );
关于linux - 使用 OpenGL 和 Freeglut 在 Linux 中显示 RGB 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34449916/