Bahaa
Bahaa

Reputation: 71

Fill Shapes in OpenGL using C++

How I can fill shape as rectangle in OpenGL using C++ with any color but without change the color it s border (border is the lines from which the rectangle is formed)?

Since when I used glBegin(GL_POLYGON) function to fill the rectangle, the border is also filled but I do not want to change the color of border.

The code which I used is below:

 void display( )
   {
      glClear(GL_COLOR_BUFFER_BIT);
      glColor3f(1.0,0.0,0.0);
      glBegin(GL_POLYGON);
         glVertex2i(50,90);
         glVertex2i(100,90);
         glVertex2i(100,150);
         glVertex2i(50,150);
      glEnd();
      glFlush();       

    }

Upvotes: 0

Views: 6673

Answers (1)

craig1231
craig1231

Reputation: 3877

void display( )
{
  glClear(GL_COLOR_BUFFER_BIT);

  // Draw the Polygon First
  glColor3f(1.0,0.0,0.0);
  glBegin(GL_POLYGON);
     glVertex2i(50,90);
     glVertex2i(100,90);
     glVertex2i(100,150);
     glVertex2i(50,150);
  glEnd();

  // Draw the border next
  glColor3f(0.0,1.0,0.0);
  glBegin(GL_LINES);
     glVertex2i(50,90);
     glVertex2i(100,90);
     glVertex2i(100,150);
     glVertex2i(50,150);
  glEnd();
  glFlush();       

}

Upvotes: 2

Related Questions