Sign in to follow this  
sandblasted

blank screen shows up :((

Recommended Posts

hey guys I'm totally new to openGL ... I tried to compile the following sode with codeblocks IDE....no errors were shown..the code is supposed to show a spinning square(it's an example of double buffered rotating square from the RED book).. but a blank(u can say transparent as the window beneath it can be seen through it ) screen appears... here's a code... did I forget to add something, are the header files correct ?? code: #include <windows.h> #include <gl/glut.h> static GLfloat spin = 0.0; void init (void){ glClearColor(0.0,0.0,0.0,0.0); glShadeModel(GL_FLAT); } void display (void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glRotatef(spin,0.0,0.0,1.0); glColor3f(1.0, 1.0,1.0); glRectf(-25.0,-25.0,-25.0,-25.0); glBegin(GL_POLYGON); glPopMatrix(); glutSwapBuffers(); } void spinDisplay(void){ spin = spin + 2.0; if(spin > 360.0) spin = spin - 360.0; glutPostRedisplay(); } void reshape(int w , int h){ glViewport(0,0,(GLsizei) w,(GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-50.0,50.0,-50.0,50.0,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void mouse(int button, int state, int x , int y){ switch(button){ case GLUT_LEFT_BUTTON: if(state == GLUT_DOWN) glutIdleFunc(spinDisplay); break; case GLUT_MIDDLE_BUTTON: if(state == GLUT_DOWN) glutIdleFunc(NULL); break; deafault: break; } } int main(int argc, char** argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init (); glutDisplayFunc (display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMainLoop (); return 0; }

Share this post


Link to post
Share on other sites
Does this compile at all?

case GLUT_MIDDLE_BUTTON:
if(state == GLUT_DOWN)
glutIdleFunc(NULL);
break;

deafault: ////// this is a typo.
break;

Since I guess you copyied the code here, the typo is it the source too. Maybe you disabled error display or something, and didn't notice that the build was unsuccessful (I had that issue before, hunting a bug for an hour, when I noticed that)

And of course that misplaced glBegin
if you draw a primitive (point/line/triangle/quad/polygon) you need to place it between glBegin and glEnd with the appropriate parameter.

Share this post


Link to post
Share on other sites
Quote:
Original post by szecs
Does this compile at all?

case GLUT_MIDDLE_BUTTON:
if(state == GLUT_DOWN)
glutIdleFunc(NULL);
break;

deafault: ////// this is a typo.
break;

Since I guess you copyied the code here, the typo is it the source too. Maybe you disabled error display or something, and didn't notice that the build was unsuccessful (I had that issue before, hunting a bug for an hour, when I noticed that)

And of course that misplaced glBegin
if you draw a primitive (point/line/triangle/quad/polygon) you need to place it between glBegin and glEnd with the appropriate parameter.


There was a warning about the 'default case'....saying default is never used..well I edited and didnt use the default case at all ...the warning was not showing up anymore but it still didnt work... The code is taken from the red book..gkBegin() or glEnd() werent used there...I cant figure out the errors...

Share this post


Link to post
Share on other sites
Quote:
Original post by szecs
glBegin-glEnd aren't used, but you have glBegin in your code.


the display function's code is....I added glBegin by mistake...

void display (void) {
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix ();
glRotatef(spin,0.0,0.0,1.0);
glColor3f(1.0, 1.0,1.0);
glRectf(-25.0,-25.0,-25.0,-25.0);
glPopMatrix ();
glutSwapBuffers();

}

as the above didnt work I tried this too

void display (void) {
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix ();
glRotatef(spin,0.0,0.0,1.0);
glColor3f(1.0, 1.0,1.0);
glBegin(GL_POLYGON);
glRectf(-25.0,-25.0,-25.0,-25.0);
glEnd();
glPopMatrix ();
glutSwapBuffers();

}
still doesnt work ...any clue ?

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