如何更改背景颜色?
我不能改变我的背景颜色.....
其他朋友的背景颜色是白色。这是相同的代码。我的其他笔记本电脑适用于vs2015(相同的代码和设置)
但是我的新笔记本电脑出现了这个问题。
拜托,我需要帮助解决这个问题
#include <glut.h>
void MyDisplay(){
float vertices[3][2]={{ 0.0,0.0 },{ 250.0,500.0 },{ 500.0,0.0 }};
float p[2] = { 75.0, 50.0 };
int i, j;
glClear(GL_COLOR_BUFFER_BIT);
for (j = 0; j<50000; j++) {
i = rand() % 3;
p[0] = (p[0] + vertices[i][0]) / 2.0;
p[1] = (p[1] + vertices[i][1]) / 2.0;
glBegin(GL_POINTS);
glVertex2fv(p);
glEnd();
} glFlush();
}
void MyInit() {
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f(1.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 500.0, 0.0, 500.0, 1, -1);
}
void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("Sierpinski Gasket");
glutDisplayFunc(MyDisplay);
MyInit();
glutMainLoop();
}
答案 0 :(得分:0)
void MyInit() {
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f(1.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 500.0, 0.0, 500.0, 1, -1);
}
You should play with the line glClearColor(1.0, 1.0, 1.0, 1.0);
Just change the values from 0 to 1.