问题
It took me >1 day and I still haven't figured out why. I'm using Ubuntu 9.10, trying to make a simple OpenGL to work in c++.
whenever I used GLUT_SINGLE parameter, it gives me a full black screen. I had to click mouse randomly on that screen in order to get out. This is so much annoying. Possibly a bug. Can anybody help?
Here is the code that I use, drawing a simple triangle in c++:
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,0.0);
glEnd();
glFlush();
glutSwapBuffers();
}
void myReshape(int a, int b)
{
}
void myMouse(int a, int b, int c, int d)
{
}
void myKeyboard(unsigned char c, int a, int b)
{
}
void myInit()
{
}
int main(int argc, char ** argv)
{
glutInit(&argc,argv); // initiaize the toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set the display mode
glutInitWindowSize(640,480); // set window size
glutInitWindowPosition(0,0);
glutCreateWindow("first window");
glutDisplayFunc(myDisplay);
glutReshapeFunc(myReshape);
//glutMouseFunc(myMouse);
//glutKeyboardFunc(myKeyboard);
myInit();
glutMainLoop();
return 0;
}
回答1:
I'm also using Ubuntu 9.10, with the latest updates. When compiling your code with
g++ -o test -lglut -lGLU -lGL test.cpp
it works perfectly. This could indeed be a bug.
Do other OpenGL applications work with single buffering? Did you try a different video driver (non-free vs. free)?
回答2:
Works fine here. Ubuntu 9.10, x64
OpenGL renderer string: Mesa DRI Intel(R) Q35 GEM 20090712 2009Q2 RC3
OpenGL version string: 1.4 Mesa 7.6
I suspect your driver may be buggy. Try disabling desktop Visual Effects (System -> Preferences -> Appearance).
来源:https://stackoverflow.com/questions/2209956/glut-single-displays-a-black-screen