我想制作简单的Painter程序,所以我学习OpenGL。
今天,我练习了GL_POINTSGL_LINE_STRIP的画线。这是一个问题。
例如



我想这样画。但是如果我使用glBegin(GL_LINE_STRIP)

看起来像这张图片。



每行都是连续的。
如何删除这些行?它困难吗?
(无论如何,对不起我的英语...)

最佳答案

您需要为每个新行再次调用glBegin(GL_LINE_STRIP)以将它们分开。如果您有以下行的列表:

std::vector<std::vector<Point>> lines;


然后您可以像这样绘制它们:

for (auto& line : lines) {
    glBegin(GL_LINE_STRIP);

    for (auto& point : line) {
        glVertex2f(point.x, point.y);
    }

    glEnd(GL_LINE_STRIP);
}


但是,您应该停止使用glBegin之类的功能,而应使用现代OpenGL函数,如以下教程中所述:


http://www.arcsynthesis.org/gltut/
http://ogldev.atspace.co.uk/
http://open.gl/
http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html

关于c++ - 使用OpenGL在拖动鼠标上绘制不连续的线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26203378/

10-11 14:02
查看更多