3

So I'm trying to (what I think would be simply) draw the outline of a number of 2D shapes using OpenGL. It all seems to work until I try to change the line thickness of the outline using glLineWidth(w); My first issue is that w = 10 or w = 3000 (or any larger number) shows the same line thickness, but something smaller like w=3 produces a thinner line.

I figure this has something to do with it. My Max seems to be 7 can I increase that or something? I just want to draw a thick line!!

float lineWidth[2];
glGetFloatv(GL_LINE_WIDTH_RANGE, lineWidth);
std::cout<<"min: "<< lineWidth[0]<<" max: "<<lineWidth[1]<<"------\n";

My second issues is that the points at which my lines meet don't seem to line up or something, which makes it look like litte bits are missing in all my shapes (rectangle, circle, triangle). This is behaviour has been mention here Draw percentage of circle outline but I couldn't seem to fix it from what the post says.

This is the code I'm using to draw a rectangle:

glLineWidth(20);
glBegin(GL_LINE_LOOP);
glVertex2f(x1, y1);//1
glVertex2f(a1, a2);//2
glVertex2f(x2, y2);//3
glVertex2f(b1, b2);//4
glEnd();

From the post mentioned above this is the code I'm using for a circle:

glEnable(GL_LINE_SMOOTH);
glLineWidth(10); 
glBegin(GL_LINE_STRIP); 
for (int i=0; i < (360/10*100/10); i++) { 
     float degInRad = i*DEG2RAD; 
     glVertex2f(x1+cos(degInRad)*r,y1+sin(degInRad)*r); } 
glEnd();

The "bits missing" looks something like this:

enter image description here

I've also had a look at this post How to render perfect wireframed rectangle in 2D mode with OpenGL? but following the leads from there didn't really help.

Community
  • 1
  • 1
user1135469
  • 1,020
  • 11
  • 22

1 Answers1

0

My first issue is that w = 10 or w = 3000 (or any larger number) shows the same line thickness, but something smaller like w=3 produces a thinner line.

Check what your OpenGL implementation actually supports via glGet() and GL_LINE_WIDTH_RANGE. I wouldn't be surprised if it topped out at 10.0.

I just want to draw a think line!!

For large line-widths you'll have to do that yourself using triangles/quads.

The "bits missing" looks something like this:

OpenGL doesn't specify how GL_LINES with widths > 1.0 are supposed to be joined/endcapped. It's up to the implementation.

Community
  • 1
  • 1
genpfault
  • 51,148
  • 11
  • 85
  • 139