Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing a thick line with OpenGl in C++

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?

like image 684
Jhon Avatar asked Mar 04 '23 18:03

Jhon


1 Answers

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.

like image 98
Rabbid76 Avatar answered Mar 13 '23 02:03

Rabbid76