Draw a star using OpenGL

 #include <stdlib.h> //Needed for "exit" function

#include<GL/glut.h>
#include<stdio.h>
#include<math.h>

void init(void)
{
	glOrtho(0,800,600,0,1,-1);
}

void display(void) {
 glClearColor (0.0,0.0,0.0,0.0);
 glClear (GL_COLOR_BUFFER_BIT);
glPointSize(10.0);
 glBegin(GL_TRIANGLES);
	glColor3ub(242,65,89);
	glVertex2i(400,100);
	glColor3ub(0,0,255);
	glVertex2i(200,400);
	glColor3ub(255,255,0);
	glVertex2i(600,400);
	glColor3ub(24,243,64);
	glVertex2i(400,500);
	glColor3ub(100,10,144);
	glVertex2i(200,200);
	glColor3ub(150,10,10);
	glVertex2i(600,200);	
 glEnd();
 glFlush();
}


int main (int argc, char **argv) {
 glutInit (&argc, argv);
 glutInitDisplayMode (GLUT_SINGLE|GLUT_RGB);
 glutInitWindowSize (800, 600);
 glutInitWindowPosition (-1, -1);
 glutCreateWindow ("Actual Star");
 init();
 glutDisplayFunc (display);
 //glutIdleFunc (display);
  // glutReshapeFunc (reshape);
 //glutKeyboardFunc (keyboard);
 glutMainLoop ();
 return 0;
}

Post a Comment

Previous Post Next Post