问题
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);
}
回答1:
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.
回答2:
Ah, now that I understood what you meant:
- draw a one by one square.
- calc the length and orientation of the line
- stretch it to the length in x
- translate to startpos and rotate to line_orientation
or:
- get vector of line: v :(x2 - x1, y2 - y1)
- normalize v: n 3- get orthogonal (normal) of the vector : o (easy in 2d)
- add and subtract o from the line's end and start point to get 4 corner points
- draw a quad with these points.
回答3:
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.
来源:https://stackoverflow.com/questions/3484260/opengl-line-width