PDA

View Full Version : glClearColor and glClear



anime.igala.net
07-11-2008, 07:31 AM
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);
glClear(GL_COLOR_BUFFER_BIT);
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,

-NiCo-
07-11-2008, 08:48 AM
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.

anime.igala.net
07-11-2008, 09:03 AM
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 :(

-NiCo-
07-11-2008, 09:38 AM
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...

anime.igala.net
07-15-2008, 01:12 AM
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.

dletozeun
07-15-2008, 01:20 AM
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 :) ) You could see the line drawn at the first frame and then nothing, after clearing the framebuffer

anime.igala.net
07-15-2008, 02:35 AM
yeah, it's ok now.

Thanks all!