#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glfw.h>
void mulaiOpenGL(void);
int main(void)
{
//
// mRunning = TRUE, aplikasi masih berjalan
// mRunning = FALSE, ??? :p
GLuint mRunning = GL_TRUE;
//
// inisialisasi GLFW
if( glfwInit() == GL_FALSE )
{
MessageBox( NULL, "ERROR :: gagal menginisialisasi GLFW", "Error!", MB_OK);
return(0);
}
//
// buat sebuah window yang akan digunakan untuk menggambar.
if( glfwOpenWindow( 640, 480, 0, 0, 0, 0, 24, 0, GLFW_WINDOW ) == GL_FALSE )
{
MessageBox( NULL, "ERROR :: gagal membuat window", "Error!", MB_OK );
glfwTerminate();
return(0);
}
//
// Set judul yang ada di window dan Swap interval.
glfwSetWindowTitle( "Praktikum Grafik Komputer LabTI" );
glfwSwapInterval( 1 );
//
// mulai OpenGL (melakukan setting awal OpenGL)
mulaiOpenGL();
//
// mulai looping utama program
float x1=0, x2=5, y1=0, y2=5 , z1=0, z2=5;
while( mRunning )
{
//
// bersihkan layar dan depth buffer
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
//
// lakukan penggambaran di sini
//------------------------------------------------------------------------------------
/*glBegin(GL_TRIANGLES);
glColor3f(0,255,255);
glVertex3f(0,10,0);
glVertex3f(5,15,0);
glVertex3f(10,10,0);
glEnd();
glBegin(GL_QUADS);
glColor3f(255,0,255);
glVertex3f(0,0,0);
glVertex2f(0,10);
glVertex2f(10,10);
glVertex2f(10,0);*/
//DEPAN
gluLookAt(10,25,30,0,0,0,0,1,0);
//DEPAN
glBegin(GL_QUADS);
glColor3f(255,255,0);
glVertex3f(x1,y1,z1);
glVertex3f(x1,y2,z1);
glVertex3f(x2,y2,z1);
glVertex3f(x2,y1,z1);
glEnd();
//ATAS
glBegin(GL_QUADS);
glColor3f(0,255,0);
glVertex3f(x1,y2,z1);
glVertex3f(x1,y2,z2);
glVertex3f(x2,y2,z2);
glVertex3f(x2,y2,z1);
glEnd();
//BAWAH
glBegin(GL_QUADS);
glColor3f(0,255,255);
glVertex3f(x1,y1,z1);
glVertex3f(x1,y1,z2);
glVertex3f(x2,y1,z2);
glVertex3f(x2,y1,z1);
glEnd();
//KANAN
glBegin(GL_QUADS);
glColor3f(0,0,255);
glVertex3f(x1,y1,z1);
glVertex3f(x1,y2,z1);
glVertex3f(x1,y2,z2);
glVertex3f(x1,y1,z2);
glEnd();
//BELAKANG
glBegin(GL_QUADS);
glColor3f(255,255,255);
glVertex3f(x1,y1,z2);
glVertex3f(x1,y2,z2);
glVertex3f(x2,y2,z2);
glVertex3f(x2,y1,z2);
glEnd();
//KIRI
glBegin(GL_QUADS);
glColor3f(255,255,0);
glVertex3f(x2,y1,z1);
glVertex3f(x2,y2,z1);
glVertex3f(x2,y2,z2);
glVertex3f(x2,y1,z2);
glEnd();
glTranslatef(10,0,0);
glScalef(1,2,1);
glRotatef(60,0,1,0);
glBegin(GL_QUADS);
glColor3f(255,255,0);
glVertex3f(x1,y1,z1);
glVertex3f(x1,y2,z1);
glVertex3f(x2,y2,z1);
glVertex3f(x2,y1,z1);
glEnd();
//ATAS
glBegin(GL_QUADS);
glColor3f(0,255,0);
glVertex3f(x1,y2,z1);
glVertex3f(x1,y2,z2);
glVertex3f(x2,y2,z2);
glVertex3f(x2,y2,z1);
glEnd();
//BAWAH
glBegin(GL_QUADS);
glColor3f(0,255,255);
glVertex3f(x1,y1,z1);
glVertex3f(x1,y1,z2);
glVertex3f(x2,y1,z2);
glVertex3f(x2,y1,z1);
glEnd();
//KANAN
glBegin(GL_QUADS);
glColor3f(0,0,255);
glVertex3f(x1,y1,z1);
glVertex3f(x1,y2,z1);
glVertex3f(x1,y2,z2);
glVertex3f(x1,y1,z2);
glEnd();
//BELAKANG
glBegin(GL_QUADS);
glColor3f(255,255,255);
glVertex3f(x1,y1,z2);
glVertex3f(x1,y2,z2);
glVertex3f(x2,y2,z2);
glVertex3f(x2,y1,z2);
glEnd();
//KIRI
glBegin(GL_QUADS);
glColor3f(255,255,0);
glVertex3f(x2,y1,z1);
glVertex3f(x2,y2,z1);
glVertex3f(x2,y2,z2);
glVertex3f(x2,y1,z2);
glEnd();
//------------------------------------------------------------------------------------
//
// tampilkan ke layar (swap double buffer)
glfwSwapBuffers();
//
// check input , apakah tombol esc ditekan atau tombol "close" diclick
mRunning = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED );
}
glfwTerminate();
return(0);
}
void mulaiOpenGL(void)
{
//
// Set viewport ke resolusi 640x480 viewport bisa diibaratkan
// layar monitor anda
glViewport( 0, 0, 640, 480 );
//
// Set mode OpenGL ke mode pryeksi (Projection) dan set proyeksi
// menggunakan proyeksi perspective, dengan sudut pandang (Field Of
// View) 60 derajat
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 60.0f, 640.0f/480.0f, 0.1f, 1000.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
//
// Set mode gradasi warna halus (Smooth)
glShadeModel( GL_SMOOTH );
//
// warna yang digunakan untuk membersihkan layar
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
//
// nilai untuk membersihkan depth buffer.
glClearDepth( 1.0f );
//
// Depth test digunakan untuk menghindari polygon yang
// tumpang tindih.
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LEQUAL );
//
// beritahu OpenGL untuk menggunakan perhitungan perspective
// yang terbaik (perhitungan ini tidak bisa selalu 100% akurat)
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
}
Tidak ada komentar:
Posting Komentar