Jump to content
  • Advertisement
Sign in to follow this  
Goishin

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.

If you intended to correct an error in the post then please contact us.

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
}



Anyone see anything boneheaded?

- Goishin

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!