I have a window 32 + opengl application. in Window WS_PAINT message, I am calling GLInit() and render(), no problem drawing stuff on the screen, but also in my window WM_KEY message, if KEY is LEFT ARROW, I am again calling render(), this time I was thinking glClear( GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT ) would clear the screen and redraw. but it is NOT clearing the screen. Does anyone know why it is doing that? how can I clear and redraw.
void GLInit()
{
glViewport( 0,0, width , height );
//Set the matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();//reset projection matrix
//gluPerspective( 54.0, (GLfloat)width/(GLfloat)height, 1.0, 1000.0);
glOrtho( -10.0, 10.0, -10.0, 10.0, 1.0, 1000.0 );
glMatrixMode(GL_MODELVIEW);
}
void prerender()
{
glEnable( GL_TEXTURE_2D );
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
glClearDepth( 1.0f );//clear depth buffer
glDepthFunc( GL_LESS );
glEnable( GL_DEPTH_TEST);//enable depth testing
glShadeModel( GL_SMOOTH );
glDepthFunc( GL_LEQUAL );//Passes if the incoming z value is less than or equal to the stored z value.
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );//really nice perspective calculation
}
void render( void )
{
prerender();
glClear( GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT );
glLoadIdentity();//Identity Matrix
gluLookAt( 0.0f, 0.0f, 10.0f, //eye position
0.0f, 0.0f, 0.0f, //position where object is at origin,
0.0f, 1.0f, 0.0f//up vector
);
setColor( 0.0, 0.0, 0.0 );
drawVertices( 10, 10, 1 );
SwapBuffers( hdc );
}