Berikut syntaksnya :
#include<stdlib.h>
#include<glut.h>
float w=480,h=480;
float
sudut=0,sumbu_x=0,sumbu_y=0,sumbu_z=0;
void objek (){
glColor3d(1,0,1);
glutWireTeapot(20);
}
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0,0,-100);
glRotatef(sudut,sumbu_x,sumbu_y,sumbu_z);
objek();
glutSwapBuffers();
}
void resize(int w1, int h1){
glViewport(0,0,w1,h1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (float) w1/(float) h1, 1.0,300.0);
glMatrixMode(GL_MODELVIEW);
}
void init(){
glShadeModel(GL_SMOOTH);
glClearColor(0.0f,0.0f,0.0f,0.05f);
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return;
}
void myKeyboard(unsigned char key, int x, int y){
if(key=='y'){
sumbu_y=1;
sudut+=10;
}
if(key=='x')
{
sumbu_x=1;
sudut+=10;
}
if(key=='z')
{
sumbu_z=1;
sudut+=10;
}
}
void update(int value){
glutPostRedisplay();
glutTimerFunc(50,update,0);
}
void main(int argc, char
**argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(w,h);
glutCreateWindow("Latihan 10");
glutDisplayFunc(display);
glutReshapeFunc(resize);
init();
glutTimerFunc(50,update,0);
glutKeyboardFunc(myKeyboard);
glutMainLoop();
}objek ini sudah dapat diRotasikan searah sumbu x, y, dan z.
Hasilnya setelah di build adalah:
Let's Try guys.. :D
Tidak ada komentar:
Posting Komentar