3

i wanted to create a line that is thick using OpenGL library in c++ but it is not working. i tried this code:

glBegin(GL_LINES);
glLineWidth(3);
glVertex2f(-0.7f, -1.0f);
glVertex2f(-0.7f, 1.0f);
glEnd();

is there something wrong here?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Jhon
  • 99
  • 3
  • 15
  • Could you please post also a screenshot of what it is showing instead? – Zac Jul 04 '19 at 15:52
  • It just shows a thin regular straight line like 1px wide – Jhon Jul 04 '19 at 15:53
  • [Use glLineWidth for a particular line without affecting other lines](https://stackoverflow.com/questions/22891985), [opengl glLineWidth() doesn't change size of lines](https://stackoverflow.com/questions/34866964) – t.niese Jul 04 '19 at 16:11
  • This way of programming OpenGL is deprecated since version 3. – Adrian Maire Jan 15 '22 at 10:29

1 Answers1

6

Note that rendering with glBegin/glEnd sequences and also glLineWidth is deprecated. See OpenGL Line Width for a solution using "modern" OpenGL.


It is not allowed to call glLineWidth with in a glBegin/glEnd sequence. Set the line width before:

glLineWidth(3);

glBegin(GL_LINES);
glVertex2f(-0.7f, -1.0f);
glVertex2f(-0.7f, 1.0f);
glEnd();

Once drawing of primitives was started by glBegin it is only allowed to specify vertex coordinates (glVertex) and change attributes (e.g. glColor, glTexCoord, etc.), till the drawn is ended (glEnd).
All other instruction will be ignored and cause a GL_INVALID_OPERATION error, which can be get by glGetError.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174