Monday, 26 May 2014

grafika kom (prak8)

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


float _angle = 45.0f;
//draws the 3D scene
void initRendering() {
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glShadeModel(GL_SMOOTH);
}

void handleResize(int w, int h) {
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, (double)w / (double)h,7.0, 100.0);
    glMatrixMode (GL_MODELVIEW);
}

void drawScene() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

   
    glTranslatef(0.0f, 0.0f, -8.0f);
    GLfloat ambientColor/*variabel*/[] = {0.0f, 0.0f, 0.0f, 1.0f};
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);/*pemanggilan variabel*/

    GLfloat lightColor0/*variabel*/[] = {1.0f, 1.0f, 1.0f, 2.0f};
    GLfloat lightPos0/*variabel*/[] = {3.0f, 10.0f, 2.0f, 4.0f};
   
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);/*pemanggilan variabel*/
    glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);/*pemanggilan variabel*/
    gluLookAt (2.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    glRotatef(_angle, 0.0f, 1.0f, 0.0f);
    glScalef (0.4, 0.4, 0.4);
    glColor3f(0.0,1.0,0.0);
    glutSolidCube(2.0);
    glTranslatef(4.0,0.0,0.0);
    glutSolidCube(2.0);
    glTranslatef(-2.0,2.0,0.0);
    glutSolidCube(2.0);
    glColor3f(1.0,0.0,0.0);
    glTranslatef(0.0,2.0,0.0);
    glutSolidTeapot(1.0);
    glFlush ();
    glEnd();
    glutSwapBuffers();
   
}

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(25, update, 0);
}
int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(300, 300);
    glutCreateWindow("praktikum_8");
    initRendering();
    glClearColor(1,1,1,0);
    glutDisplayFunc(drawScene);
    glutReshapeFunc(handleResize);
    glutTimerFunc(25, update,0);
    glutMainLoop();
    return 0;
}

No comments:

Post a Comment

Konversi Suhu

#include <iostream> #include <conio.h> //#include <cstdlib> //#include <iostream.h> void main( float Celcius, Kelvi...