How to draw a Triangle in OpenGL

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s