//To change to color of anything, you must call a color function //before the drawing of the object. to do this you can use //glColor3f(R,G,B); or glColor4f(R,G,B,A); but in this tutorial //we are only going to use glColor3f because glColor4f has an extra //use which is known as alpha. Also known as transparency or opacity, in other words, how much you can see through it. //Now with R, G, B and A, the highest value you can have is a 1. //The lower the number, the less of that color. //With: glColor3f(1.0, 0.0, 0.0); you can see that we have set //the R value to 1, and all the other values to 0. This means that it will only show the color red, and to its full extent. #include #include void square (void) { glColor3f(1.0, 0.0, 0.0); //this will set the square to red. glBegin(GL_QUADS); glVertex3f(-0.5, -0.5, 0.0); glVertex3f(-0.5, 0.5, 0.0); glVertex3f(0.5, 0.5, 0.0); glVertex3f(0.5, -0.5, 0.0); glEnd(); } void display (void) { glClearColor (0.0,0.0,0.0,1.0); glClear (GL_COLOR_BUFFER_BIT); glLoadIdentity(); gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); square(); glFlush(); } void reshape (int w, int h) { glViewport (0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0); glMatrixMode (GL_MODELVIEW); } int main (int argc, char **argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE); glutInitWindowSize (500, 500); glutInitWindowPosition (100, 100); glutCreateWindow ("A basic OpenGL Window"); glutDisplayFunc (display); glutReshapeFunc (reshape); glutMainLoop (); return 0; }