PDA

View Full Version : Line Strip changes colour when drawing quadrics



Wiggers
09-09-2003, 08:37 AM
I have a program to draw 3D graphs of Lat, Long and Altitude. Each trail of points is broken up into segments and each segment has two display lists. One list renders the line as a GL_LINE_STRIP and the other uses gluCylinder to make 'pipes'. The displaylist that's used switches from line strip to pipe as the user gets closer. The weird thing is that when the first segment on a trail switches to a pipe the remaining segments change colour! Reverse away and it switches back. Here's the code for one segment:

m_listIndex0 = glGenLists(2);
m_listIndex1 = m_listIndex0 + 1;

if( m_listIndex0 != 0 ) {
glNewList( m_listIndex0, GL_COMPILE );
glEnable( GL_COLOR_MATERIAL );
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glColor3fv( m_colour );

GLUquadricObj* quadricObj;
if ( NULL != ( quadricObj = gluNewQuadric() ) )
{
gluQuadricDrawStyle(quadricObj, GLU_FILL);
// set coords
.....
gluCylinder( quadricObj, cylRadius, cylRadius, dist, 6, 2 );
}

glCullFace(GL_BACK);
gluDeleteQuadric( quadricObj );
glDisable( GL_COLOR_MATERIAL );

glEndList();
}

// create a display list for low-res
if( m_listIndex1 != 0 ) {
glNewList( m_listIndex1, GL_COMPILE );
glEnable( GL_COLOR_MATERIAL );
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glColor3fv( m_colour );

glBegin(GL_LINE_STRIP);
for(int i=0, k=0; i<numpts; ++i, k+=3)
{
glVertex3f( vertArray[k], vertArray[k+1], vertArray[k+2] );
}
glEnd();
glDisable( GL_COLOR_MATERIAL );

glEndList();
}

Wiggers
09-09-2003, 09:20 AM
PS. I've found that by turning the ambient light up to 1,1,1,1 the effect is less noticable, but there is still a marked dimming of the lines when the quads start to be shown.

ehart
09-09-2003, 10:59 AM
You aren't specifying normals in the display list for lines. This might be causing the problem. You might be getting whatever is the last normal from the last quadric you drew.

-Evan

Wiggers
09-10-2003, 01:45 AM
That's it! Thanks. Hadn't realised lines had, or needed, normals.

Mark

zeckensack
09-10-2003, 08:32 AM
You always need normals when you use lighting. Regardless of primitive type.

You can, of course, set your lighting parameters up in a way to make normals irrelevant, ie have light intensity only influenced by distance to light.