Whenever I try to run any openGL/glut programs under Ubuntu, the image (not an animation) generated displays for a fraction of a second and then disappears. The tab of the window of the image remains in the taskbar and reclicking the tab reshows the image for a fraction of a second again.
A temporarily solution I’m using is glutIdleFunc() in conjunction with glutPostRedisplay(). However this merely redraws the image constantly.
Under my Windows systems, the image from the code below doesn’t disappear without the idle function. What’s going on with Ubuntu?
Thanks for the help
edit: oh and i’m using Ubuntu with gnome, x1600 mobility radeon
#include <stdlib.h>
#include <GL/glut.h>
//------------------------------------------------------------ Reshape()
void OnReshape(int w, int h)
{
// prevent a division by zero when minimising the window
if (h==0)
h=1;
// set the drawable region of the window
glViewport(0,0,w,h);
// set up the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// just use a perspective projection
gluPerspective(45,(float)w/h,0.1,100);
// go back to modelview matrix so we can move the objects about
glMatrixMode(GL_MODELVIEW);
}
//------------------------------------------------------------ Draw()
//
void OnDraw() {
// clear the screen & depth buffer
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
// clear the previous transform
glLoadIdentity();
// set the camera position
gluLookAt( 1,1,10, // eye pos
0,0,0, // aim point
0,1,0); // up direction
// draw a simple teapot
glutWireTeapot(1);
// currently we've been drawing to the back buffer, we need
// to swap the back buffer with the front one to make the image visible
glutSwapBuffers();
}
//------------------------------------------------------------ OnInit()
//
void OnInit() {
// enable depth testing
glEnable(GL_DEPTH_TEST);
}
//------------------------------------------------------------ OnExit()
//
void OnExit() {
}
//------------------------------------------------------------ main()
//
int main(int argc,char** argv) {
// initialise glut
glutInit(&argc,argv);
// request a depth buffer, RGBA display mode, and we want double buffering
glutInitDisplayMode(GLUT_DEPTH|GLUT_RGBA|GLUT_DOUBLE);
// set the initial window size
glutInitWindowSize(640,480);
// create the window
glutCreateWindow("A basic glut example");
// set the function to use to draw our scene
glutDisplayFunc(OnDraw);
// set the function to handle changes in screen size
glutReshapeFunc(OnReshape);
// run our custom initialisation
OnInit();
// set the function to be called when we exit
atexit(OnExit);
// this function runs a while loop to keep the program running.
glutMainLoop();
return 0;
}