You are on page 1of 1

#include <GL/glut.

h>
#include <math.h>

void drawStar(float x, float y, float outerRadius, float innerRadius, int


numPoints) {
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x, y); // Center of the star
for (int i = 0; i <= numPoints * 2; i++) {
float angle = i * 3.14159f / numPoints;
float r = (i % 2 == 0) ? outerRadius : innerRadius;
glVertex2f(x + r * cos(angle), y + r * sin(angle));
}
glEnd();
}

void display() {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
drawStar(0.5, 0.1, 0.5, 0.2, 5); // Draw a star at the origin
glFlush();
}

int main(int argc, char** argv) {


glutInit(&argc, argv);
glutCreateWindow("Star using OpenGL");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

You might also like