tags:

views:

72

answers:

3
+1  Q: 

OpenGL Line Width

In my OpenGL app, it won't let me draw a line greater then ten pixels wide. Is there a way to make it draw more than ten pixels?

void OGL_Renderer::drawLine(int x, int y, int x2, int y2, int r, int g, int b, int a, int line_width)
{   

glColor4ub(r, g, b, a);

glLineWidth((GLfloat)line_width);
glBegin(GL_LINES);
glVertex2i(x, y);
glVertex2i(x2, y2);
glEnd();
glLineWidth(1.0f);
}
+2  A: 

You could try drawing a quad. Make it as wide as you want your line to be long, and tall as the line width you need, then rotate and position it where the line would go.

AshleysBrain
How would I do that? Like if I give you four points(x1, y1, x2, y2), I want to draw a line larger than ten pixels with those four points.
Matt
You would call glVertex2D() four times, with the "corners" of your "line". It's especially simple for vertical/horizontal lines, not too hard to diagonal, but gets a bit trickier at angles (just approximate, or use trig). You might be able to do some tricks with the view matrix, but just drawing the quad is probably easier (even if you use trig).
peachykeen
A: 

Ah, now that I understood what you meant:

  1. draw a one by one square.
  2. calc the length and orientation of the line
  3. stretch it to the length in x
  4. translate to startpos and rotate to line_orientation

or:

  1. get vector of line: v :(x2 - x1, y2 - y1)
  2. normalize v: n 3- get orthogonal (normal) of the vector : o (easy in 2d)
  3. add and subtract o from the line's end and start point to get 4 corner points
  4. draw a quad with these points.
AndreasT
+2  A: 

It makes sense that you can't. From the glLineWidth reference:

The range of supported widths and the size difference between supported widths within the range can be queried by calling glGet with arguments GL_LINE_WIDTH_RANGE and GL_LINE_WIDTH_GRANULARITY.

jcage