0% found this document useful (0 votes)
4 views2 pages

lab exercises

This document contains a C++ program that uses OpenGL to draw a flag with two triangles and a star. The flag's body is red, the triangles are yellow, and the star is outlined in white. The program initializes a window and sets up the drawing environment before entering the main loop to render the flag.

Uploaded by

atinasianegash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

lab exercises

This document contains a C++ program that uses OpenGL to draw a flag with two triangles and a star. The flag's body is red, the triangles are yellow, and the star is outlined in white. The program initializes a window and sets up the drawing environment before entering the main loop to render the flag.

Uploaded by

atinasianegash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <windows.

h>
#include <GL/glut.h>

void init() {
glClearColor(0.0, 0.0, 0.0, 1.0);
gluOrtho2D(0.0, 500.0, 0.0, 500.0);
}

void drawFlag() {
glClear(GL_COLOR_BUFFER_BIT);

// Draw the flag body


glColor3f(1.0, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex2d(50, 100);
glVertex2d(400, 100);
glVertex2d(400, 400);
glVertex2d(50, 400);
glEnd();

// Draw the first triangle


glColor3f(1.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
glVertex2d(50, 100);
glVertex2d(200, 400);
glVertex2d(50, 400);
glEnd();

// Draw the second triangle


glColor3f(1.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
glVertex2d(250, 100);
glVertex2d(400, 100);
glVertex2d(400, 400);
glEnd();

// Draw the star


glColor3f(1.0, 1.0, 1.0);
glPointSize(3);
glLineWidth(10);
glBegin(GL_LINE_LOOP);
glVertex2d(300, 300); // p1
glVertex2d(180, 210); // p2
glVertex2d(240, 350); // p3
glVertex2d(280, 200); // p4
glVertex2d(180, 300); // p5
glEnd();

glFlush();
}

int main() {
glutInitWindowSize(500, 500);
glutInitWindowPosition(10, 20);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutCreateWindow("Flag");
glutDisplayFunc(drawFlag);
init();
glutMainLoop();
return 0;
}

You might also like