game - design - multimedia - web - programming - tutorials - There are currently viewers visiting Apron Tutorials.

TECHNICAL
GRAPHICAL
SOUND
GAME
WEB
ARTICLE
TOOL
PROJECT

 NEWS
 TECHNICAL TUTORIALS
 WEB TUTORIALS
 IMAGE EDITING
 3D MODELING
 PROJECTS
 DEMOS
 ARTICLES
 COMMUNITY

# OPENGL COLOR TUTORIAL

 All we are going to do in this tutorial is apply a color to our triangle. To be more specific we are going to apply a different color to each vertex by using the glColor3f(red, green, blue) function. The color values range from 0.0f to 1.0f. 0.0f being the darkest and 1. 0f being the brightest. The glColor3f uses RGB values and the glColor4f uses RGBA values. The first parameter is the Red Intensity, the second parameter is for Green and the third is for Blue. The closer the value of the number is to 1.0f, the brighter that specific color will be. The last number is an Alpha value. Blending green and blue creates shades of cyan. Blue and red combine for magenta. Red and green create yellow. glColor3f (1.0f, 0.0f, 0.0f); full red, no green, no blue. glColor3f (0.0f, 1.0f, 0.0f); no red, full green, no blue. glColor3f (0.0f, 0.0f, 1.0f); no red, no green, full blue.

 ```int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing { // Clear Screen And Depth Buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset The Current Modelview Matrix glLoadIdentity(); //NEW//////////////////NEW//////////////////NEW//////////////////NEW///////////// glTranslatef(0.0f, 0.0f, -6.0f); // Translate Into The Screen glBegin(GL_TRIANGLES); // Start Drawing A Triangle glColor3f( 1.0f,0.0f,0.0f); // Red Color glVertex3f(0.0f, 1.0f, 0.0f); // Top Color glColor3f(0.0f,1.0f,0.0f); // Green glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left Vertex glColor3f(0.0f,0.0f,1.0f); // Blue Color glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right Vertex glEnd(); // Finished Drawing The Triangle //NEW//////////////////NEW//////////////////NEW//////////////////NEW///////////// return TRUE; // Keep Going } ```

If you have managed to draw a triangle, colouring it is no problem...

Regards