Monday, May 21, 2018

CONTOH CODING ANIMASI 2D MEMBUAT SETIGA

//apa fungsi dari glMatrixMode (GL_PROJECTION)

#include <GL/glut.h>  //sebagai header file untuk OpenGL32 Library
#include <windows.h>  //sebagai header file untuk windows
GLfloat xangle=0.0;  //deklarasi variabel xangle
GLfloat aangle=0.0;  //deklarasi variabel aangle
GLfloat bangle=0.0;  //deklarasi variabel bangle

void init (void) {  //fungsi utama untuk tampilan
            glClearColor (1.0,1.0,1.0,0.0);
            glLineWidth    (1.0);
            glColor3f(1.0,0.0,0.0);
            glMatrixMode (GL_PROJECTION);
            glLoadIdentity ();
            glOrtho (-6,6,-6,6,-6,6);
}

void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();

glBegin (GL_LINES);
            glVertex2f(-5.5,0.0);
            glColor3f(1.0,0.0,0.0);
            glVertex2f(5.5,0.0);
glEnd();

glBegin (GL_LINES);                                                //fungsi menggambar sumbu y
            glVertex2f(0.0,-5.5);               //sumbu Y negatif
            glColor3f(1.0,0.0,0.0);                        //merah
            glVertex2f(0.0,5.5);                //sumbu Y positif
glEnd();                                                                       //fungsi akhir perintah opengl

glRotatef(xangle, 0.0, 0.0, 1.1); //menentukan sumbu z yang berputar penuh/rotasi
glRotatef(aangle, 1.0, 0.0, 0.0); //menentukan sumbu x yang bergerak refleksi
glRotatef(bangle, 0.0, 1.1, 0.0); //menentukan sumbu y yang bergerak reklasi
glBegin(GL_POLYGON);
            glColor3f(1.-1,1.2,-2.1);         
            glVertex2f(1.0,1.0);    //titik a (1,1)
            glColor3f(-1.-2,-3.1,4.1);
            glVertex2f(4.0,1.0);                //titik b (4,1)
            glColor3f(3.2,1.7,1.9);
            glVertex2f(1.0,5.0);                //titik C (1,5)
            glEnd();

glPopMatrix();
 glutSwapBuffers();                //fungsi perpindahan
 glFlush();
}

void KeyboardAssign (GLubyte key, GLint x, GLint y){
            switch (key){
                        case 'z':
                                    xangle +=10.0;
                                    glColor3f(0.0,0.0,1.0);
                                    glutPostRedisplay();
                                    break;
                        case 'x':
                                    aangle +=10.0;
                                    glColor3f(0.0,0.0,1.0);
                                    glutPostRedisplay();
                                    break;
                        case 'y':
                                    bangle +=10.0;
                                    glColor3f(0.0,0.0,1.0);
                                    glutPostRedisplay();
                                    break;
            }
}
void main (int argc, char** argv){ //pemanggila fungsi utama
            glutInit (&argc,argv);//pemanggila fungsi utama OpenGL
            glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);//fungsi warna jenis tampilan
            glutInitWindowPosition (0,0);//menetapkan posisi windows
            glutInitWindowSize(1500,1500);//menetapkan ukuran windows
            glutCreateWindow("Latihan 2");//membuat windows dan menentukan judulnya
            init();
            glutDisplayFunc(display);//memanggil fungsi untuk menampilkan objek
            glutKeyboardFunc(KeyboardAssign);
            glutMainLoop();                                                                      //terus tampilkan hingga program diakhiri
}




No comments:

Post a Comment

CONTOH CODING LINKED LIST MENGGUNAKAN BORLAND C++

CONTOH CODING LINKED LIST MENGGUNAKAN BORLAND C++ #include<stdlib.h> #include<conio.h> #include<iostream.h> struc...