1

I'm new to OpenGL. I simply want to thicken one line using glLineWidth, but that also affects all other lines as well. So I tried the other way by putting glLineWidth inside between begin and end, then it didn't work. My code is shown below:

glBegin(GL_LINES);
glLineWidth(3);
glVertex2f(5, 10);
glVertex2f(30, 35);
glEnd();

glBegin(GL_LINES);
glVertex2f(20, 25);
glVertex2f(50, 55);
glEnd();

So is there any way to make only this line thicken? I've been googling but can't find a simple solution :S

Shuvo0o
  • 489
  • 1
  • 8
  • 16

2 Answers2

6

Did you try something like this?

glLineWidth(3);
glBegin(GL_LINES);
glVertex2f(5, 10);
glVertex2f(30, 35);
glEnd();

glLineWidth(1);
glBegin(GL_LINES);
glVertex2f(20, 25);
glVertex2f(50, 55);
glEnd();
Firas Assaad
  • 25,006
  • 16
  • 61
  • 78
  • Yeah something like that but I have other lines as well so I don't want glLineWidth to affect them. Is there any way to stop glLineWidth? – Shuvo0o Apr 06 '14 at 09:19
  • 2
    To "stop" it you can simply set it back to its default value of 1.0, like Peter Clark said it's a global state function so it stays in effect until you change it. – Firas Assaad Apr 06 '14 at 09:23
  • @Shuvo0o: Since you are using deprecated OpenGL, you still have access to the attrib stack. You can use `glPushAttrib (GL_LINE_BIT)` before you set the line width for one line and `glPopAttrib ()` when you are done drawing that line. The benefit this gives you is that you do not have to know the original value of the line width in order to restore it. – Andon M. Coleman Apr 07 '14 at 14:18
3

glLineWidth is a function that affects global state (i.e. it applies to all lines drawn after it is called). If you want other lines to have different widths, you'll have to specify a new glLineWidth before drawing them.

Note that the default line width value is 1.0.

Peter Clark
  • 2,863
  • 3
  • 23
  • 37