Sign in to follow this  
mmorrison

OpenGL [EASY Q?] Screen not clearing on new frame

Recommended Posts

Somewhat new to opengl - just removed my dependency on glut and reworking a project at the same time.

I was/am using glDrawPixel on an array of pixels to draw to the screen.

defined like this:

struct RGBAType {
GLfloat r;
GLfloat g;
GLfloat b;
GLfloat a;
RGBAType() : a(1),r(0),g(0),b(0){}
};


(I included that to make sure I am using the right datatypes...I've read that the conversions of type may affect speed drastically)

I am initializing opengl as so:


//setup opengl
glShadeModel(GL_FLAT); // Enable Smooth Shading
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glDisable(GL_DEPTH_TEST); // Disables Depth Testing

glEnable ( GL_COLOR_MATERIAL );
glFlush();



and every frame I draw with the follow:

void ce_MainRenderer::renderToScreen ( void ) // Create The Display Function
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho (0, s_screenWidth, s_screenHeight, 0, 0, 1);

glRasterPos2f(0,s_screenHeight);//I just looked at this - I think this is setup wrong...
glDrawPixels(s_screenWidth,s_screenHeight,GL_RGBA,GL_FLOAT, pixelsToDraw);
glFlush();
//GUI();
}



When I first wrote this function I was redrawing every pixel every frame, now I am working on a graphing application and only redraw a very small ...... I just figured out what the problem was. My data structure does'nt get cleared out on every frame so the state of things simply carries over on the next frame...

I'm posting this anyways, f it - let me know if there is anything I am doing that is unnecessary ... plan to switch over to Pixel Buffer Objects soon

Share this post


Link to post
Share on other sites
Very minor, but this:

glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Black Background

is a white background, not a black one. Black is (0,0,0).

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