Cannot get my screen to clear

Started by
2 comments, last by Goishin 13 years, 6 months ago
Hi all,

I cannot get my openGL program to clear the screen when I call glClear. All I get during the running of my program is just get an empty white screen. And that's all I'm actually doing at the moment, just trying to clear the screen.

I am terrified that I am about to break the fourth rule of the openGL forum faq, so I will try to keep the code I'm posting to an absolute minimum. However, this project was in directx, and I'm attempting to port it over to opengl. Currently, I cannot get the screen to clear, so I suspect that there's something very simple I'm doing wrong. I'm checking the glGetError function pretty consistently, but it's always returning GL_NO_ERROR. I suspect that the problem may lie in one of two areas, either my openGL instantiation process, or something I'm not doing in my draw function. I'm very new to openGL, so it's probably something very very basic in my draw function. Feel free to ask for more code, I've got tons and tons in this project, but very little actual drawing code.

My draw function:
[source lang = "cpp"]int DrawGLScene(GLvoid)								// Here's Where We Do All The Drawing{  char buf[200];  if(0 != glGetError())  {    sprintf(buf, "OpenGL error code:%d\n",glGetError());    debugText->Add(buf);  }  glClearColor(1.0f, 0.156f, 0.392f, 0.0f);  glPushAttrib(GL_ALL_ATTRIB_BITS);  glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);			// Clear The Screen And The Depth Buffer  glViewport(0, 0, game_info.vert, game_info.horiz);					// Reset The Current Viewport  glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix  glLoadIdentity();							// Reset The Projection Matrix  // Calculate The Aspect Ratio Of The Window  gluPerspective(45.0f,(GLfloat)game_info.vert/(GLfloat)game_info.horiz,0.1f,100.0f);    glMatrixMode(GL_MODELVIEW);						// Select The Modelview Matrix  glLoadIdentity();							// Reset The Modelview Matrix  if(0 != glGetError())  {    sprintf(buf, "OpenGL error code:%d\n",glGetError());    debugText->Add(buf);  }  return TRUE;								// Everything Went OK}


Anyone see anything boneheaded?

- Goishin
Advertisement
Hmm not sure. Two things I maybe see, but I'm not confident this is your problem:

1) If you're using doublebuffering, are you swapping the buffer after you finish your draw call?
2) You're calling PushAttrib every loop but not popping it, do you do this somewhere else? I would expect this to crash your application pretty quickly if you don't.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Ah, I am such an idiot!

I wasn't calling SwapBuffers. So I could draw and draw and draw all I want, but if I'm never actually presenting what I'm drawing, I just get a white screen.

Thanks folks, but I wrapped this one up on my own.

- Goishin
Hey Karwosts,

Wow! That was faaaast! But yes, you were exactly right. I wasn't swapping my buffers. And, no, I'm currently not popping my buffers. But thanks very much for the tip! I'll go add that now :)

- Goishin

This topic is closed to new replies.

Advertisement