linux - 使用 OpenGL 和 Freeglut 在 Linux 中显示 RGB 窗口

标签 linux opengl ubuntu-10.04 freeglut

我想创建一个覆盖整个桌面屏幕的窗口,显示颜色为 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

glut examples

nehe's legacy tutorials

What is the nicest way to close GLUT

void glutLeaveMainLoop ( void );

关于linux - 使用 OpenGL 和 Freeglut 在 Linux 中显示 RGB 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34449916/

相关文章:

c - Linux/bash 中程序返回值的有效范围是多少?

Ubuntu Console.ReadLine 上的 Monodevelop 不起作用

linux - 如何多次提取带有 or 条件的 HTML 标记之间的文本

linux - Linux 中的快速、半准确排序

c - 顶点数组未被绘制

c++ - 如何从 GL_RGB 转换为 AVFrame

c - 为什么我运行这个 C 代码时 CPU 核心使用率有一个开关?

xml - Sed 替换保留前导空格

linux - 如何使用完整路径从 bash 运行 resque 启动脚本

c++ - OpenGL 3.3 着色器统一变量不起作用