Drawing an empty rectangular shape in openGL

I want to draw a rectangle's blank form in OpenGL, but when I used glBegin(GL_QUADS)or glBegin(GL_POLYGON), the given form is filled, but I want to be blank. How can I draw an empty rectangle.

void draweRect(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0,0.0,1.0);
    glLineWidth(30);
    glBegin(GL_POLYGON);
        glVertex2i(50,90);
        glVertex2i(100,90);
        glVertex2i(100,150);
        glVertex2i(50,150);
    glEnd();
    glFlush();   
}
+4
source share
3 answers

Use GL_LINE_LOOP(instead GL_POLYGON) to draw a connected series of line segments around the perimeter of your polygon, rather than filling the polygon.

Alternatively, you can use glPolygonMode (GL_FRONT_AND_BACK, GL_LINE)... do not forget to return it to the standard ones glPolygonMode (GL_FRONT_AND_BACK, GL_FILL)to resume normal (filled) rendering.

+7
source

.

glPolygonMode(...);.

:

void draweRect(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0,0.0,1.0);
    glLineWidth(30);

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

    glBegin(GL_POLYGON);
        glVertex2i(50,90);
        glVertex2i(100,90);
        glVertex2i(100,150);
        glVertex2i(50,150);
    glEnd();

    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glFlush();   
}
+4

..

glBegin(GL_LINE_LOOP);
    glVertex2f(x1,y1);
    glVertex2f(x2,y1);
    glVertex2f(x2,y2);
    glVertex2f(x1,y2);
glEnd();
0
source

Source: https://habr.com/ru/post/1544442/


All Articles