18 June 2012

OpenGL untuk membuat 2 benda yg berbeda.

Berikut ini adalah program OpenGL untuk membuat 2 benda yg berbeda.

Praktikum grafika 5.

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

float _angel=45.0f;

void mydisplay()
{
glClear(GL_COLOR_BUFFER_BIT); //menghapus layar
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.8f,0.8f,0.8f);
glScalef(2.0f,2.0f,2.0f);
glRotatef(_angel,0.0f,0.0f,1.0f);
glPushMatrix();
glBegin(GL_POLYGON);
glColor3f(1,0,0);
glVertex2f(-0.1, -0.1);
glVertex2f(-0.1, 0.1);
glVertex2f(0.1, 0.1);
glVertex2f(0.1, -0.1);
glEnd();

glPopMatrix();
glutSwapBuffers();

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f,0.5f,0.0f);
glScalef(2.0f,2.0f,2.0f);
//glRotatef(_angel,0.0f,0.0f,1.0f);
glPushMatrix();
glBegin(GL_POLYGON);
glColor3f(1,1,1);
glVertex2f(-0.2, -0.2);
glVertex2f(-0.2, 0.2);
glVertex2f(0.2, 0.2);
glVertex2f(0.2, -0.2);

glEnd();
glPopMatrix();
glutSwapBuffers();

glFlush();
}

void update(int value){
       _angel +=-9.0f;
       if(_angel > 360){
                      _angel=-360;
       }
       glutPostRedisplay();
       glutTimerFunc(25,update,0);
}

int main(int argc, char** argv)
{
printf("Contoh Sederhana Kotak");
glutCreateWindow("Praktikum6");
glutDisplayFunc(mydisplay);
glutTimerFunc(25,update,0);
glutMainLoop();
}





0 komentar:

Post a Comment