GLUT只是呈现空白的白色屏幕? [英] GLUT is just rendering a blank white screen?

查看:148
本文介绍了GLUT只是呈现空白的白色屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码,没有任何错误,这是什么问题?

Here is the code, there aren't any errors, what is wrong with it?

我编译它,打开命令提示符,窗口打开,窗口全是白色,我将其重新着色为灰色..,它也没有绘制我的形状,所以出了什么问题?

I compile it, the command prompt opens, the window opens, the window is all white, I recolored it to grey.., and it also does not draw my shape, so what is the problem?

    #ifdef __APPLE__
    #include <GLUT/glut.h>
    #else
    #include <GL/glut.h>
    #endif

    #include <stdlib.h>



    void ProcessSpecialKeys(int key, int x, int y){

        switch(key){

           case GLUT_KEY_RIGHT:


    exit(0);



           case GLUT_KEY_LEFT:

    exit(0);

           case GLUT_KEY_UP:
    exit(0);

           case GLUT_KEY_DOWN:

    exit(0);
           default:

    exit(0);

        }




        }



    void renderScene(void) {
    glClearColor(0.3f, 0.3f, 0.3f, 0.3f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


        glutSwapBuffers();
}

    void renderPrimitive(void){
    glBegin(GL_QUADS);
    glVertex3f(-1.0f,-1.0f,0.0f);
    glVertex3f(-1.0f,1.0f,0.0f);
    glVertex3f(1.0f,1.0f,0.0f);
    glVertex3f(1.0f,-1.0f,0.0f);
    glEnd();
}

    void display(void){
    glTranslatef(0.0f,0.0f,-0.5f);
    renderPrimitive();
    glFlush();
    glClearColor(0.3f,0.3f,0.3f,0.3f);
    glClear(GL_COLOR_BUFFER_BIT);
}

int main(int argc, char **argv) {

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(320,320);
    glutCreateWindow("Dimension");
    glutDisplayFunc(display);

    glLoadIdentity();

glutSpecialFunc(ProcessSpecialKeys);


    glutMainLoop();

    return 1;
}

推荐答案

问题是在显示功能中绘制场景后,您正在清除显示内容.此外,还有一个无用的glFlush()调用.删除这些行:

The problem is that you are clearing the display after you draw your scene in the display function. Also, there is a useless glFlush() call. Remove these lines:

glFlush();
glClearColor(0.3f,0.3f,0.3f,0.3f);
glClear(GL_COLOR_BUFFER_BIT);

添加glutSwapBuffers()代替它们.

glFlush()用于单缓冲模式.

请记住,您使用的是双缓冲模式,因此有两个缓冲区.您的场景被绘制到后缓冲区,并且要显示它,您必须通过在显示功能末尾调用glutSwapBuffers()将其复制到前缓冲区.

Remember, you are using double buffered mode, so there are two buffers. Your scene is drawn to the back buffer, and to display it, you have to copy it to the front buffer by calling glutSwapBuffers() at the end of the display function.

这篇关于GLUT只是呈现空白的白色屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆