Hello, I’m a very beginner in OpenGL. The problem is that I try to write a very simple code using C++Builder, actually it’s a first code in the red book drawing white rectangle on black background. There is no any error while compile…but when running, nothing came out. It’s just a blank form and the background color still be a button face color. So…help me please… :’(
Are you forgetting to put glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); before all your drawing code?
again, Here is my code:-
glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColor3f(1.0,1.0,1.0); glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0); glBegin(GL_POLYGON); glVertex2f(-0.5,-0.5); glVertex2f(-0.5,0.5); glVertex2f(0.5,0.5); glVertex2f(0.5,-0.5); glEnd(); glFlush();
I put it on a FormPaint event. nothing happens…why?
Thanks - job
If you drawing with a 3d matrix, you’ll
have to step back a little to see your scene.
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
gluPerspective( 60, winwidth / winheight, 1, 10 );
glMatrixMode( GL_MODELVIEW );
/* step back from origin for our view */
glTranslatef( 0, 0, -5 );
/* draw 3d stuff at origin by starting with a new
/* drawing code here */
Thanks, but it’s still the same.
did you initialize a valid render context and made it current?
Put this code in your DrawGL function, this work.
// Clear the color buffer and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reset the axes
// The camera location
0,0,5 ==> Eye location
0,0,0 ==> The place where the eye’s looking
0,1,0 ==> The directionnal vector