小编leo*_*uts的帖子

用鼠标在OpenGL GLUT中绘制多边形

我想用鼠标交互在openGL Glut中绘制一个多边形,每次左键单击都将是一个顶点,并且将在每个顶点之间绘制一条线。单击鼠标右键时,多边形将关闭,从最后一个顶点到第一个顶点绘制一条线。我想出了这个,但它似乎不起作用。

void draw_polygon(int button, int state, int x, int y) {

    bool right_pushed = 0;
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POINTS);

    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
        p1.x = x;
        p1.y = 480 - y;

        //if right is clicked draw a line to here
        first.x = x;
        first.y = 480 - y;
    }

    while (right_pushed == false) {

        if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
            p2.x = x;
            p2.y = 480 - y;
        }

        GLfloat dx = p2.x …
Run Code Online (Sandbox Code Playgroud)

c++ opengl graphics glut opengl-compat

6
推荐指数
1
解决办法
3873
查看次数

标签 统计

c++ ×1

glut ×1

graphics ×1

opengl ×1

opengl-compat ×1