Varying line widths

How do I change the width of a single
line, without changing all line widths. Im drawing my lines “on the fly” in a for loop, not using vertex arrays.

Peace.

  1. Here you go…

GLfloat thickness;
glBegin(GL_LINES);
for(int i=0;i<n;++i)
{
if(ThisIsTheLine[i]) //your truth function for vertex i->i+1
thickness=5.0;
else
thickness=1.0;
glLineWidth(thickness);
glVertex3f(x[i],y[i],z[i]);
}
glEnd();
glLineWidth(1.f);//reset

  1. BUT…
    You must first see if your hardware drivers support a thickness other than 1.0
    So:
    GLfloat LineRange[2];
    glGetFloatv(GL_LINE_WIDTH_RANGE,LineRange);
    std::cout << "Minimum Line Width " << LineRange[0] << " – ";
    std::cout << "Maximum Line Width " << LineRange[1] << std::endl;

[This message has been edited by iss (edited 04-14-2001).]

Line width cannot be changed inside a Begin/End.

  • Matt

Actually, thanx.
GLfloat thickness;
for(int i=0;i<n-1;++i)
{
if(ThisIsTheLine[i]) //your truth function for vertex i->i+1
thickness=5.0;
else
thickness=1.0;
glLineWidth(thickness);
glBegin(GL_LINES);
glVertex3f(x[i],y[i],z[i]);
glVertex3f(x[i+1],y[i+1],z[i+1]);
glEnd();
}
glLineWidth(1.f);//reset

[This message has been edited by iss (edited 04-14-2001).]

Transcend think of OpenGL as a state machine. You set a state and it stays that way until you change it again. Such is linewidth … if you set the linewidth, all lines will be drawn at that width until you change it again. To change the width of a single line, set the linewidth you want, draw the line, then set it back to it’s previous width (as demonstrated in the code above).