OpenGL Line Width

不羁的心 提交于 2019-12-22 04:29:25

问题


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:

  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.



回答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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!