glClearColor and glClear

I have a function that draw a line on the screen:

void Viewer::drawScence(){
    glClearColor        (0.f,0.f,1.0f,1.f);
    glMatrixMode        (GL_PROJECTION);
    glFrustumf (-1000.f,1000.f,-1000.f,1000.f,3.f,1000.f);

    glMatrixMode        (GL_MODELVIEW);
    glShadeModel        (GL_SMOOTH);
    glEnableClientState (GL_VERTEX_ARRAY);

    
    glTranslatef            (0,0,-5.f);
    
    glColor4f(0,1,0,1);

	static const GLfloat vertices[3 * 3] =
	{
	     -1000,    1000,    0,
	      1000,   -1000,    0,
	      1000,    1000,    0
	};
	
	static const GLubyte colors[3*4] = {
			255, 0, 0, 255,
			0, 255, 0, 255,
			0, 0, 255, 255
	};

    glVertexPointer( 3, GL_FLOAT, 0, vertices );
    
    glDrawArrays( GL_LINES, 0, 2);
}

When I add glClear, i cannot see anything on the screen:
glClear(GL_COLOR_BUFFER_BIT);

void Viewer::drawScence(){
    glClearColor        (0.f,0.f,1.0f,1.f);
[color:#FF0000][b]glClear(GL_COLOR_BUFFER_BIT);[/b][/color]
    glMatrixMode        (GL_PROJECTION);
    glFrustumf (-1000.f,1000.f,-1000.f,1000.f,3.f,1000.f);

    glMatrixMode        (GL_MODELVIEW);
    glShadeModel        (GL_SMOOTH);
    glEnableClientState (GL_VERTEX_ARRAY);

    
    glTranslatef            (0,0,-5.f);
    
    glColor4f(0,1,0,1);

	static const GLfloat vertices[3 * 3] =
	{
	     -1000,    1000,    0,
	      1000,   -1000,    0,
	      1000,    1000,    0
	};
	
	static const GLubyte colors[3*4] = {
			255, 0, 0, 255,
			0, 255, 0, 255,
			0, 0, 255, 255
	};

    glVertexPointer( 3, GL_FLOAT, 0, vertices );
    
    glDrawArrays( GL_LINES, 0, 2);
}

Can anyone tell me why?

thanks,

I doubt that clearing the buffer is the problem. You should probably insert glLoadIdentity() after your glMatrixMode(GL_PROJECTION) call to make sure the projection transformations are not being accumulated over time.

I have tried and don’t see anything too :frowning:

You should also look into the parameters of your glfrustum call. It’s very different from a glOrtho call. Your image plane is of size 2000.0f in both directions and it’s placed at only 0.3f away from the camera, that’s an extremely large field of view…

I just don’t know why i cannot see anything when i try to add the line glClear(GL_COLOR_BUFFER_BIT) to clear screen before drawing.

did you add glLoadIdentity() in modelview matrix mode too?

I am pretty sure that if you slow down your draw function (add a sleep inside :slight_smile: ) You could see the line drawn at the first frame and then nothing, after clearing the framebuffer

yeah, it’s ok now.

Thanks all!