|
Finally, we get to add color to the triangle and quad from the previous lesson.
Lesson 3 Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 |
int DrawGLScene() {
glLoadIdentity(); glTranslatef(-1.5f,0.0f,-6.0f); glBegin(GL_TRIANGLES); glColor3f(1.0f,0.0f,0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glColor3f(0.0f,1.0f,0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glColor3f(0.0f,0.0f,1.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glEnd(); glTranslatef(3.0f,0.0f,0.0f); glColor3f(0.5f,0.5f,1.0f); glBegin(GL_QUADS); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glEnd(); return TRUE;
} |
Analyze:
Line 6: glColor3f(1.0f, 0.0f, 0.0f);
this creates a red diffuse color for everything rendered after this call. glColor3f( R,G,B ) has a maximum value of 1.0f, actually, it does (r,g,b) % 1 for each, compared to 15-bit(31) and 24-bit(255). If you have a texture applied (covered in a different lesson), you can use this to hint the colors of the texture, i.e. make a greyscale image and use glColor3f to give it the real color (Halo uses diffusion).
To make it so it does not modify the currently applied texture, call glColor3f(1,1,1);
With other glColor3f() functions called, the colors will blend together.
After you've had your fun with colors, check out the next lesson: Translations and Rotations |