# Using gl_quad_strips with multiple colors

I’d like to use gl_quad_strips but have unique colors on each quad. I’m guessing this may be impossible, but I’d like to know for sure.

Thanks.

what ? how do you do your stuff ?

“having unique colors on each quad” should be what you get when using glShadeModel(GL_FLAT);

although this might not really be what you want, i think it is a valid answer to your question Let me give a simplistic example of what I want. Then maybe you’ll see what’s puzzling me.

Suppose I want a red rectangle abutting a green rectangle.
//Set up some vertices
float v[ 6 ][ 2 ] = {
/////////////////////// 1 3 5
{ -0.5, -0.5 }, // x x x
{ -0.5, 0.5 }, //
{ 0.0, -0.5 }, //
{ 0.0, 0.5 }, //
{ 0.5, -0.5 }, // x x x
{ 0.5, 0.5 } // 0 2 4
};

// Set color for first quad
glColor3f( 1, 0, 0 );

glVertex2fv( v[ 0 ] );
glVertex2fv( v[ 1 ] );
glVertex2fv( v[ 3 ] );
// I want to add other color call here somewhere, // but I’m guessing you can’t since you’re in the
// in the middle of a glBegin/End sequence.
// Besides, you’re reusing these 2 vertices, so
// where would it go?
glVertex2fv( v[ 2 ] );
glVertex2fv( v[ 5 ] );
glVertex2fv( v[ 4 ] );
glEnd();

Do you see what I’m thinking about now?

I don’t know how to used the shading model to specify color.

you can call the function glColor*() between the glBegin()/glEnd() pairs. Before each glVertex*(), you can specify a color by calling the function glColor*():

glColor*();
glVertex*();
glColor*();
glVertex*();

glEnd();

Remember to enable the smooth shading by calling the following function:
glShadeModel( GL_SMOOTH ); //(As Rigid Body said before )

-Ehsan-

Hmmm, okay, thanks for that comment. I see what you’re saying, but I don’t want to blend the colors.

For this particular example, I want a purely red rectangle next to a purely green rectangle.

Let me try again to explain what I’m trying to do. Here’s how you do it with 2 consecutive quads:

glColor3f( 1,0,0 );

glVertex2fv( v[ 0 ] );
glVertex2fv( v[ 1 ] );
glVertex2fv( v[ 3 ] );
glVertex2fv( v[ 2 ] );

glColor3f( 0,1,0 );

glVertex2fv( v[ 2 ] );
glVertex2fv( v[ 3 ] );
glVertex2fv( v[ 5 ] );
glVertex2fv( v[ 4 ] );
glEnd();

ehsan,

actually i said that smooth shading should be disabled if glShadeModel(GL_FLAT) is used, each tria will have a constant color.

Sorry. I didn’t notcie you don’t want to blend the colors. So as Rigid Body said, disable smooth shading :rolleyes:
-Ehsan-

Hi, thanks again for your efforts, but we’re still back where we started.

Smooth shading or no, there’s still the problem of what color to set the vertices that are being REUSED in the rect. strip.

The more I talk about this, the more convinced I become that you just can’t do it. Do you agree?

try this

`````` glBegin(GL_QUAD_STRIP);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-1.0, -1.0, 0.);
glVertex3f( 1.0, -1.0, 0.);
glVertex3f(-1.0,  0.0, 0.);
glVertex3f( 1.0,  0.0, 0.);
glColor3f(1.0, 1.0, 0.0);
glVertex3f(-1.2,  1.0, 0.);
glVertex3f( 1.2,  1.0, 0.);