PDA

View Full Version : why my quads renderer all in white?



oscar leo
08-26-2011, 12:38 PM
hi i using C++ this time to learn how in opengl.
my question is that i have this code



void Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClearColor(0.6f, 0.6f, 0.6f, 1.0f);

glMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_PROJECTION);
//frustum(right, left, bottom, top, near, far)
glFrustum(0.5f, 0.9f, 0.5f, 0.9f, 1.0f, 3.0f);
glLoadIdentity();
glPushMatrix();
glTranslatef(0.0f, 0.0f, 0.0f);
glRotatef(3.0f, 0.0f, 0.0f, 0.0f);

/*glColor3ub(255, 255, 0);
glDisable(GL_LIGHTING);
glEnable(GL_LIGHTING);*/

glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f,-0.5f, 0.5f);
glVertex3f( 0.5f,-0.5f, 0.5f);

glNormal3f( 0.0f, 0.0f,-1.0f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f, 0.5f,-0.5f);
glVertex3f( 0.5f, 0.5f,-0.5f);
glVertex3f( 0.5f,-0.5f,-0.5f);

glNormal3f( 0.0f, 1.0f, 0.0f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f,-0.5f);
glVertex3f(-0.5f, 0.5f,-0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);

glNormal3f( 0.0f,-1.0f, 0.0f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f( 0.5f,-0.5f,-0.5f);
glVertex3f( 0.5f,-0.5f, 0.5f);
glVertex3f(-0.5f,-0.5f, 0.5f);

glNormal3f( 1.0f, 0.0f, 0.0f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f,-0.5f, 0.5f);
glVertex3f( 0.5f,-0.5f,-0.5f);
glVertex3f( 0.5f, 0.5f,-0.5f);

glNormal3f(-1.0f, 0.0f, 0.0f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f,-0.5f);
glEnd();

DrawGround();
glPopMatrix();
SwapBuffers(oGLdevice.hDC);
}

and all is draw in white the cube has not color. how i can render normally or put lights?

BionicBytes
08-26-2011, 01:09 PM
You can add colour to each vertex by using glColor3f before each glVertex3f command.
Alternatively the other way to add colour and detail us to use texture mapping. You need to supply a set of texture coordinates per face of the cube and use glBindTexture to add a texture to each face.