To draw a triangle we need three points and join them to make a triangle .

Download source code

tria

 

void myDisplay(void)
{
//glColor3f(1.0f, 1.0f, 0.0f); //yellow
glColor3f(0.0f, 1.0f, 0.0f); //Green

glBegin(GL_TRIANGLES);
glVertex2i(220,240);
glVertex2i(320,240);
glVertex2i(270,340);

glEnd();

glFlush();

}

glColor3f(0.0f, 1.0f, 0.0f); //Green This line used for color (RGB).

glBegin(GL_TRIANGLES); This function is used to create Triangles. like GL_LINE_LOOPS are use to join points.

And finally we are drawing triangle by supply the value of X and Y vertex. the above function will join them and make a triangle.

Try changing position and color of your triangle.

Advertisements