我想创建一个覆盖整个桌面屏幕的窗口,显示颜色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();
}
感谢。
答案 0 :(得分:1)
您正在使用GLUT_DOUBLE
(double buffering)初始化显示模式,每当您使用缓冲区并希望添加gluSwapBuffers()
时,您需要添加...
glClearColor(1,0,0,1); //Red
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
sleep(1);
...
显示它。
for (int index = 0; index < words.Count; index++)
{
var word = words[index];
//doStuff
}
Difference between single buffered(GLUT_SINGLE) and double buffered drawing(GLUT_DOUBLE)
使用GL_SINGLE时,您可以直接将代码绘制到显示屏上。
使用GL_DOUBLE时,您可以想象有两个缓冲区。其中一个总是可见的,另一个不是
What is the nicest way to close GLUT
void glutLeaveMainLoop(void);