PDA

View Full Version : Varying line widths

transcend
04-14-2001, 08:44 AM
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.

iss
04-14-2001, 01:03 PM
1) Here you go... http://www.opengl.org/discussion_boards/ubb/smile.gif

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
----------------------------------------
2) BUT... http://www.opengl.org/discussion_boards/ubb/frown.gif
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).]

04-14-2001, 01:27 PM
Line width cannot be changed inside a Begin/End.

- Matt

iss
04-14-2001, 04:02 PM
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).]

pleopard
04-14-2001, 05:15 PM
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).