Posts Tagged ‘Add new tag’

Rotating Star

Friday, October 16th, 2009

By n special thank’s to Danu Kurniawan mihawkzz@yahoo.com

#include <GL/glut.h>

/*
05 PQT/Grafik Komputer
Kelompok:
Danu Kurniawan 1100030660
Toddy Prasetyo 1100031083
Yuditra Carolus P. 1100031152
Valentinus Ricky A. 1100031171
Kent Hakiki 1100031631
Bramono Wicaksono 1100032426
Even 1100032653

*/
static int year = 0;

void init(void){
glClearColor (1.0, 1.0, 1.0, 1.0);
glShadeModel (GL_FLAT);
}

void display(void){
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 0.0, 0.0);
glPushMatrix();

glBegin (GL_LINES);
glVertex3i (0, 0, 0);
glVertex3i (0, 15,0);
glEnd();
glBegin (GL_LINES);
glVertex3i (0, 0, 0);
glVertex3i (15, 0, 0);
glEnd();

glColor3f (1.0, 1.0, 0.0);
glRotatef ((GLfloat) year, 0.0, 1.0, 0.0);
glTranslatef (1.0, 0.0, 0.0);

glBegin (GL_POLYGON);
glVertex3i (5,4,0);
glVertex3i (1,7,0);
glVertex3i (9,7,0);
glVertex3i (2,2,0);
glVertex3i (5,10,0);
glVertex3i (8,2,0);
glEnd();

glPopMatrix();
glutSwapBuffers();
}

void reshape (int w, int h){
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(80.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt (0.0, 0.0, 20, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

void animate(void){
year=(year+1) % 360;
glutPostRedisplay();
}

int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (”5 pointed star”);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(animate);
glutMainLoop();
return 0;
}