Reputation: 530
I have very simple openGL code:
screen.cpp
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <iostream>
#define WIDTH 683
#define HEIGHT 384
void init() {
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(WIDTH, HEIGHT);
glutCreateWindow("test");
glutDisplayFunc(display);
GLenum res = glewInit();
if (res != GLEW_OK) {
std::cout<<"Error: "<<glewGetErrorString(res)<<std::endl;
return 1;
}
init();
glutMainLoop();
return 0;
}
The wierd thing is this code sometimes works and sometimes doesn't. I expect to get a white blank screen, and when I run this program, randomly and more frequently, I would just get transparent screen showing what was there before the program was run. Sometimes the program works correctly and shows me a blank white screen. What is the problem?
compiled with: g++ -o screen screen.cpp -g -Wall -std=c++11 -lGLEW -lglut -lGL
Upvotes: 1
Views: 501
Reputation: 48186
it's the alpha you specify in clearColor, 0 means transparent, change it to 1 and it will be a proper blank screen.
Upvotes: 1