Sign in to follow this  

Problem with basic GLUT program

Recommended Posts

Hi. This is a simple GLUT program that animates a rectangle(moves it around). The code has been take from "OpenGL Super Bible" and is as below: //An animated square #include <windows.h> #include <gl\glut.h> GLfloat x1=100.0f; GLfloat y1=150.0f; GLsizei rsize=50; GLfloat xstep=1.0f; GLfloat ystep=1.0f; GLfloat windowWidth; GLfloat windowHeight; void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f,0.0f,0.0f); glRectf(x1,y1,x1+rsize,y1+rsize); glutSwapBuffers(); } //Called by GLUT library when "idle" void TimerFunction(int value) { if( (x1 > windowWidth-rsize) || x1<0) xstep = -xstep; if( (y1 > windowHeight-rsize) || y1<0) ystep = -ystep; //Suspicious Code if(x1>windowWidth-rsize) x1=windowWidth-rsize-1; if(y1>windowHeight-rsize) y1=windowHeight-rsize-1; //End of Suspicious Code x1+=xstep; y1+=ystep; //Redraw the scene with new coordinates glutPostRedisplay(); glutTimerFunc(33,TimerFunction,1); } void SetupRC(void) { glClearColor(0.0f,1.0f,0.0f,1pppp.0f); } void ChangeSize(GLsizei w, GLsizei h) { if(h==0) h=1; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) { windowHeight = 250.0f*h/w; windowWidth = 250.0f; } else { windowWidth = 250.0*w/h; windowHeight = 250.0f; } glOrtho(0.0f,windowWidth,0.0f,windowHeight,1.0f,-1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(void) { glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutCreateWindow("Bouncing Stuff"); glutDisplayFunc(RenderScene); glutReshapeFunc(ChangeSize); glutTimerFunc(33,TimerFunction,1); SetupRC(); glutMainLoop(); return 0; } //////////////////////////////////////////////////////////////// The problem: When the window appears, it shows nothing. In fact, when minimized and maximized, the new window captures the screen area behind it... much like the Print Screen button. I've checked and re-checked the code hundred times. Other demos have worked well on my PC. By the way, I'm using GLUT 3.7 with Dev C++. Thanks in advance.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this