PDA

View Full Version : Why I can't get through the simplest code??



job
02-09-2002, 06:04 PM
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... :'(

rpxmaster
02-09-2002, 07:22 PM
Are you forgetting to put glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); before all your drawing code?

job
02-09-2002, 07:30 PM
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

jmathies
02-09-2002, 07:36 PM
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 );
glLoadIdentity();
gluPerspective( 60, winwidth / winheight, 1, 10 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

/* step back from origin for our view */

glTranslatef( 0, 0, -5 );

/* draw 3d stuff at origin by starting with a new
matrix */

glPushMatrix();

/* drawing code here */

glPopMatrix();

SwapBuffers();

job
02-09-2002, 07:46 PM
Thanks, but it's still the same.

Tron
02-09-2002, 08:52 PM
did you initialize a valid render context and made it current?

Leyder Dylan
02-10-2002, 09:22 AM
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
glLoadIdentity();

// The camera location
/*
0,0,5 ==> Eye location
0,0,0 ==> The place where the eye's looking
0,1,0 ==> The directionnal vector
*/
gluLookAt(0,0,5,0,0,0,0,1,0);

glBegin(GL_QUADS);
glVertex2i(-1,1);
glVertex2i(-1,-1);
glVertex2i(1,-1);
glVertex2i(1,1);
glEnd();