I want to draw unfilled rectangle shape in OpenGL
, but when I used glBegin(GL_QUADS)
or glBegin(GL_POLYGON)
, the resulted shape is filled but I want to be unfilled. How I can draw unfilled 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();
}
Use GL_LINE_LOOP
(instead of GL_POLYGON
) to draw a connected series of line segments on the perimeter of your polygon rather than filling the polygon.
Alternatively, you could use glPolygonMode (GL_FRONT_AND_BACK, GL_LINE)
... remember to set it back to the default glPolygonMode (GL_FRONT_AND_BACK, GL_FILL)
to resume usual (filled) rendering though.
You need to set the fill mode for your rendering.
You can use the glPolygonMode(...);
method.
Try the following:
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();
}
This one worked for me..
glBegin(GL_LINE_LOOP);
glVertex2f(x1,y1);
glVertex2f(x2,y1);
glVertex2f(x2,y2);
glVertex2f(x1,y2);
glEnd();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With