Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
37 views4 pages

CG Lab 03

Uploaded by

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

CG Lab 03

Uploaded by

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

Lab Report-03

Course Code: CSE 422


Course Title: Computer Graphics Lab

Submitted To:
Md Shakil Ahmed(MSA)
Lectural
Department of CSE
Daffodil International University

Submitted by:
Name: Mir Saem Hasan
ID: 211-15-4066
Section: 59_C1
Department of CSE
Daffodil International University
Report: Write a program for designing an asterisk using OpenGL.

1. Objective
The objective of this lab was to create a graphical program using OpenGL and GLUT that
renders star shapes in a fan-like arrangement. The program demonstrates the use of geometric
transformations, basic drawing functions, and color manipulation in OpenGL.

2. Code
#include <GL/glut.h>
#include <cmath> // Include the math library

// Function to draw a star


void drawStar(float x, float y, float size) {
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x, y); // Center of the star

for (int i = 0; i <= 10; i++) {


float angle = i * 2.0f * 3.14159f / 10; // 10 points for the star
float radius = (i % 2 == 0) ? size : size / 2.0f; // Alternate outer and inner radius
glVertex2f(x + cos(angle) * radius, y + sin(angle) * radius);
}

glEnd();
}

// Display function
void display() {
glClear(GL_COLOR_BUFFER_BIT);
// Draw stars in a fan-like pattern with different colors
glColor3f(0.0f, 1.0f, 0.0f); // Green
drawStar(-0.3f, 0.3f, 0.2f);

glColor3f(1.0f, 0.0f, 0.0f); // Red


drawStar(0.3f, 0.3f, 0.2f);

glColor3f(0.0f, 0.0f, 1.0f); // Blue


drawStar(-0.3f, -0.3f, 0.2f);

glColor3f(0.0f, 1.0f, 0.0f); // Green


drawStar(0.3f, -0.3f, 0.2f);

glFlush();
}

// Main function
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(400, 400);
glutCreateWindow("Fan-like Stars with OpenGL and GLUT");
gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
glutDisplayFunc(display);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Set background color to black
glutMainLoop();
return 0;
}
4. Output
Upon running the program, a 500x500 pixel window opens displaying a Star.

Fig:01

6. Conclusion
This lab successfully demonstrated how to use OpenGL and GLUT to create basic 2D shapes
and manipulate colors. The program illustrates fundamental concepts of computer graphics,
including drawing primitives, coordinate systems, and color management.

You might also like