# OpenGL Cannot get my screen to clear

This topic is 2849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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}

- Goishin

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
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

1. 1
Rutin
19
2. 2
3. 3
JoeJ
16
4. 4
5. 5

• 26
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001781
×