PDA

View Full Version : OpenGL 1.1/MS XP Pro - Color Codes for Vertices



shc
12-22-2004, 06:10 AM
Hi all,
I learned the 'glColorf ( )' to color the triangle created by 3 vertices:
// Drawing 4 Triangles of a Tetrahedron
glColor3f (0.0, 0.0, 1.0); //Set the color to blue
glBegin(GL_TRIANGLES); // Triangle #1 of the Tetrahedron
glVertex3f ( 0.0, 1.1, 0.0); // 1st vertex of Triangle #1
glVertex3f ( 1.1, -1.1, 0.0); // 2nd vertex of Triangle #1
glVertex3f (-1.1, -1.1, 0.0); // 3rd vertex of Triangle #1.

In some tutorial examples, I saw the following code to get the different rain-bow color for each face of the Quad of a cube:
Vertex g_cubeVertices[] =
{
// Quad 0
{ 1.0f,0.0f,0.0f, -1.0f,-1.0f, 1.0f }, // 0 (unique)
{ 0.0f,1.0f,0.0f, 1.0f,-1.0f, 1.0f }, // 1 (unique)
{ 0.0f,0.0f,1.0f, 1.0f, 1.0f, 1.0f }, // 2 (unique)
{ 1.0f,1.0f,0.0f, -1.0f, 1.0f, 1.0f }, // 3 (unique)

// Quad 1
{ 1.0f,0.0f,1.0f, -1.0f,-1.0f,-1.0f }, // 4 (unique)
{ 0.0f,1.0f,1.0f, -1.0f, 1.0f,-1.0f }, // 5 (unique)
{ 1.0f,1.0f,1.0f, 1.0f, 1.0f,-1.0f }, // 6 (unique)
{ 1.0f,0.0f,0.0f, 1.0f,-1.0f,-1.0f }, // 7 (unique)

// Quad 2
{ 0.0f,1.0f,1.0f, -1.0f, 1.0f,-1.0f }, // 5 (start repeating here)
{ 1.0f,1.0f,0.0f, -1.0f, 1.0f, 1.0f }, // 3 (repeat of vertex 3)
{ 0.0f,0.0f,1.0f, 1.0f, 1.0f, 1.0f }, // 2 (repeat of vertex 2... etc.)
{ 1.0f,1.0f,1.0f, 1.0f, 1.0f,-1.0f }, // 6

// Quad 3
{ 1.0f,0.0f,1.0f, -1.0f,-1.0f,-1.0f }, // 4
{ 1.0f,0.0f,0.0f, 1.0f,-1.0f,-1.0f }, // 7
{ 0.0f,1.0f,0.0f, 1.0f,-1.0f, 1.0f }, // 1
{ 1.0f,0.0f,0.0f, -1.0f,-1.0f, 1.0f }, // 0

// Quad 4
{ 1.0f,0.0f,0.0f, 1.0f,-1.0f,-1.0f }, // 7
{ 1.0f,1.0f,1.0f, 1.0f, 1.0f,-1.0f }, // 6
{ 0.0f,0.0f,1.0f, 1.0f, 1.0f, 1.0f }, // 2
{ 0.0f,1.0f,0.0f, 1.0f,-1.0f, 1.0f }, // 1

// Quad 5
{ 1.0f,0.0f,1.0f, -1.0f,-1.0f,-1.0f }, // 4
{ 1.0f,0.0f,0.0f, -1.0f,-1.0f, 1.0f }, // 0
{ 1.0f,1.0f,0.0f, -1.0f, 1.0f, 1.0f }, // 3
{ 0.0f,1.0f,1.0f, -1.0f, 1.0f,-1.0f } // 5
};

//
// Now, to save ourselves the bandwidth of passing a bunch or redundant vertices
// down the graphics pipeline, we shorten our vertex list and pass only the
// unique vertices. We then create a indices array, which contains index values
// that reference vertices in our vertex array.
//
// In other words, the vertex array doens't actually define our cube anymore,
// it only holds the unique vertices; it's the indices array that now defines
// the cube's geometry.
//

Vertex g_cubeVertices_indexed[] =
{
{ 1.0f,0.0f,0.0f, -1.0f,-1.0f, 1.0f }, // 0
{ 0.0f,1.0f,0.0f, 1.0f,-1.0f, 1.0f }, // 1
{ 0.0f,0.0f,1.0f, 1.0f, 1.0f, 1.0f }, // 2
{ 1.0f,1.0f,0.0f, -1.0f, 1.0f, 1.0f }, // 3
{ 1.0f,0.0f,1.0f, -1.0f,-1.0f,-1.0f }, // 4
{ 0.0f,1.0f,1.0f, -1.0f, 1.0f,-1.0f }, // 5
{ 1.0f,1.0f,1.0f, 1.0f, 1.0f,-1.0f }, // 6
{ 1.0f,0.0f,0.0f, 1.0f,-1.0f,-1.0f }, // 7
};

GLubyte g_cubeIndices[] =
{
0, 1, 2, 3, // Quad 0
4, 5, 6, 7, // Quad 1
5, 3, 2, 6, // Quad 2
4, 7, 1, 0, // Quad 3
7, 6, 2, 1, // Quad 4
4, 0, 3, 5 // Quad 5
};
......
////////////////////
I do not want the rain-bow colors for the cube -I want one color for each face of the 6 Quads of the cube. How can I do the OpenGL coding to get one color for each face of the cube in the un-indexed figure and in the indexed figure?
Please help and advise.
Thanks in advance,
shc
P.S.
What is this "{ 1.0f,0.0f,0.0f, -1.0f,-1.0f, 1.0f }, // 0 (unique)"? I think the first 3 numbers are x-, y-, z- coordinates, but I do not know what the 3 last numbers are!!! Please tell me what the 3 last numbers are and what the whole code statement is.

12-23-2004, 01:03 AM
Hi,

I'm new to OpenGl as well, but what you posted looks familiar, so I'll take a guess.

{ 1.0f,0.0f,0.0f, -1.0f,-1.0f, 1.0f }, // 0 (unique)

The first three floats are the colors and the second three or the position vectors, like so:

red, green, blue, x, y , z

I didn't look that hard and It could be the other way around but I don't think so.

its just like when specifying colors with glColorf

I hope I am not misleading you as I have only been playing with opengl for about an hour now, and cam e to these forums to get some help finding good documentation.