#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>
//#include <glu.h>
#include <iostream>
void init(void)
{
glClearColor (0.0,0.0,0.0,1.0);
glShadeModel (GL_FLAT);
}
float _angle = 45.0f;
//draws the 3D scene
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT|GL_DEFTH_COLOR_BUFFER_BIT)
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity ();
gluLookAt (0.0, 2.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
//kubus 1
glTranslatef(0.0,0.0,0.0);
glColor3f(1.0,0.0,0.0);
glutWireCube(0.6);
//kubus 2
glTranslatef(0.0,-0.6,0.0);
glColor3f(0.0,1.0,0.1);
glutWireCube(0.6);
//poci
glTranslatef(0.0,0.6,0.0);
glColor3f(0.0,1.0,0.0);
glutWireTeapot(0.2);
//kubus 3
glTranslatef(0.6,-0.6,0.0);
glColor3f(1.0,1.0,0.0);
glutWireCube(0.6);
//kubus 4
glTranslatef(0.6,0.0,0.0);
glColor3f(1.0,1.0,1.0);
glutWireCube(0.6);
//kubus 5
glTranslatef(0.6,0.0,0.0);
glColor3f(1.0,0.0,1.0);
glutWireCube(0.6);
//kubus 6
glTranslatef(0.0,0.6,0.0);
glColor3f(0.0,0.0,1.0);
glutWireCube(0.6);
//poci
glTranslatef(0.0,0.0,0.0);
glColor3f(0.0,1.0,1.0);
glutWireTeapot(0.2);
//ring
glRotatef(_angle, 0.0f, 1.0f, 1.0f);
glTranslatef(-1.0,1.0,0.0);
glColor3f(0.0,0.0,1.0);
glutWireTorus(0.09,0.4,40,40);
glFlush ();
glutSwapBuffers();//send the 3D scene to the screen
}
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(30, update, 0);
}
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);
}
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);
glutMainLoop();
return 0;
}
Tidak ada komentar:
Posting Komentar