#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>
//#include <glu.h>
float _angle= 10.0f;
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 1.0, 1.0);
glLoadIdentity ();
gluLookAt (1.5, 5.0, 15.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
//belakang
glutWireCube(2.0);
glTranslatef(2,0,2);
glColor3f (0.0, 1.0, 0.0);
//samping kanan
glutWireCube(2.0);
glTranslatef(-2,0,2);
glColor3f (1.0, 0.0, 0.0);
glutWireCube(2.0);
//depan
glTranslatef(-2,0,-2);
glColor3f (0.0, 0.0, 1.0);
glutWireCube(2.0);
//kiri
glTranslatef(-2,0,2);
glTranslatef(4,1.4,-3);
glTranslatef(0.0,0.1,0.0);
glColor3f (0.0, 1.0, 0.0);
glRotatef(_angle, 0.0f, 1.0f, 0.0f);
glutWireTeapot(1.0);
glFlush ();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 2.0, 20.0);
glMatrixMode (GL_MODELVIEW);
}
void update(int value){
_angle += 9.0f;
if(_angle > 360){
_angle -= 360;
}
glutPostRedisplay();//tell glut that the display changed
//Tell glut to call update
glutTimerFunc(12, update, 0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
//glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutTimerFunc(25, update,0);
glutTimerFunc(25, update,0);
glutMainLoop();
return 0;
}
Hasil Runningnya seperti berikut :