当我编译它时,它会产生一个空白的blac屏幕,如果我从任一位置取出过量交换缓冲区,或者两者同时我得到一个空白的白色屏幕,那么问题是什么?
#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 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();
glutSwapBuffers();
}
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 0;
}
答案 0 :(得分:0)
在开始新抽奖之前,您需要清除缓冲区。换句话说,在显示功能中执行此操作:
void display(void){
glClear(GL_COLOR_BUFFER_BIT); // <-----
glTranslatef(0.0f,0.0f,-0.5f);
renderPrimitive();
glutSwapBuffers();
}
并阅读有关函数glClearColor
的内容<强> EDITED 强>:
这不是正确的地方,但要更改背景颜色,请执行以下操作:
void display(void){
glClearColor(0.5, 0.5, 0.5, 1);
glClear(GL_COLOR_BUFFER_BIT); // <-----
glScalef(0.5f,0.5f,0.5f); // Your Quad is taking all the framebuffer
renderPrimitive();
glutSwapBuffers();
}
答案 1 :(得分:0)
尝试glColor3f(0.5f,0.5f,0.5f);并删除glClearColor(0.5,0.5,0.5,1);
答案 2 :(得分:-2)
试试这个:
#include <GL/glut.h>
#include <stdlib.h>
void ProcessSpecialKeys(int key, int x, int y)
{
switch(key)
{
case GLUT_KEY_RIGHT:
case GLUT_KEY_LEFT:
case GLUT_KEY_UP:
case GLUT_KEY_DOWN:
exit(0);
break;
default:
exit(0);
break;
}
}
void renderPrimitive()
{
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()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( -2, 2, -2, 2, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glPushMatrix();
glTranslatef(0.0f,0.0f,-0.5f);
renderPrimitive();
glPopMatrix();
glutSwapBuffers();
}
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);
glutSpecialFunc(ProcessSpecialKeys);
glutMainLoop();
return 0;
}