Senin, 05 Mei 2014

prak 6

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <glut.h>
//#include <glu.h>
#include <iostream>

float _angle = 45.0f;
//draws the 3D scene
void mydisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //menghapus layar
glMatrixMode(GL_MODELVIEW); //switch to setting the camera perspective
glLoadIdentity();//reset the camera
//glTranslatef(0.5f, 0.0f, 0.0f);//translasi
//glScalef(2.0f, 2.0f, 3.0f);//skala
//glRotatef(_angle, 0.0f, 0.0f, 1.0f);
glPushMatrix();//save the transformations performed thus far
glRotatef(_angle, 0.0f, 0.0f, 1.0f);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex3f(-0.1f, -0.1f, 0.0f);
glVertex3f(-0.1f, 0.1f, 0.0f);
glVertex3f(0.1f, 0.1f, 0.0f);
glVertex3f(0.1f, -0.1f, 0.0f);
glEnd();

glTranslatef(0.5f, 0.0f, .0f);//translasi
glRotatef(_angle, 0.0f, 0.0f, 1.0f);
glColor3f(0.0,1.0,0.0);
glBegin(GL_POLYGON);
glVertex3f(-0.1f, -0.1f, 0.0f);
glVertex3f(-0.1f, 0.1f, 0.0f);
glVertex3f(0.1f, 0.1f, 0.0f);
glVertex3f(0.1f, -0.1f, 0.0f);
glEnd();

glTranslatef(0.5f, 0.0f, .0f);//translasi
glRotatef(_angle, 0.0f, 0.0f, -1.0f);
glColor3f(1.0,0.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(-0.1f, -0.1f, 0.0f);
glVertex3f(-0.1f, 0.1f, 0.0f);
glVertex3f(0.1f, 0.1f, 0.0f);
glVertex3f(0.1f, -0.1f, 0.0f);
glEnd();
glPopMatrix();//undo the move to the center of the trapezoid
glutSwapBuffers();//send the 3D scene to the screen
glFlush();
}



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(80, update, 0);
}
int main(int argc, char** argv)
{
glutInitWindowSize(400,400);
printf("Contoh Sederhana Kotak ");
glutCreateWindow("Praktikum");
glutDisplayFunc(mydisplay);
glutTimerFunc(25, update,0);
glutMainLoop();
return 0;
}

0 comments:

Posting Komentar

"bayuaji-master.blogspot.com". Diberdayakan oleh Blogger.