Karena menggunakan software Pelles C, maka obyek yang dibuat murni dibuat dengan coding program. Semua pengaturan yang berhubungan dengan obyek baik itu warna, ukuran serta posisi obyek berikut pergerakkan obyek tersebut diatur didalam coding program. Untuk memulai Pelles C (klik untuk yang mengunduh) langkahnya adalah sebagai berikut :
1. Klik start - All Programs - Pelles C for Windows - Pelles C IDE
2. Pilih File - New - Project
3. Pilih wizard yang sesuai - masukkan nama - OK
4. Kemudian next, lalu Finish
5. Double Click pada main.c
6. Maka akan muncul project area untuk menuliskan coding.
7. Coding dituliskan didalam komentar //lakukan penggambaran disini.
8. Jadi, kita mulai membuat coding di blok //lakukan penggambaran disini.
9. Selebihnya merupakan struktur yang sudah tersedia dan tidak perlu diubah - ubah.
berikut codingnya.
#include
#include
#include
#include
#include
void mulaiOpenGL(void);
int main(void)
if( glfwInit() == GL_FALSE )
MessageBox( NULL, "ERROR :: gagal menginisialisasi GLFW", "Error!", MB_OK);
return(0);
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);
glfwSetWindowTitle( "Praktikum Grafik Komputer LabTI" );
glfwSwapInterval( 1 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
gluLookAt(0.0,0.0,10.0,0.0,0.0,0.0,0.0,10.0,0.0);
//cerobong
glBegin(GL_QUADS);
glColor3f(0.1,0.0,0.0);
glVertex3f(-1.5f,0.0f,0.0f);
glVertex3f(-0.5f,3.0f,0.0f);
glVertex3f(-0.5f,4.5f,0.0f);
glVertex3f(-1.5f,4.5,0.0f);
glEnd();
//batang pohon
glBegin(GL_QUADS);
glColor3f(0.5,0.0,0.0);
glVertex3f(4.0f,-2.0f,0.0f);
glVertex3f(5.0f,-2.0f,0.0f);
glVertex3f(5.0f,1.5f,0.0f);
glVertex3f(4.0f,1.5,0.0f);
glEnd();
//pohon
glBegin(GL_TRIANGLES);
glColor3f(0.0,1.0,1.0);
glVertex3f(3.0f,1.5f,0.0f);
glColor3f(1.0,1.0,1.0);
glVertex3f(6.0f,1.6f,0.0f);
glColor3f(2.0,2.0,0.0);
glVertex3f(4.5f,5.0f,0.0f);
glEnd();
//atap
glBegin(GL_TRIANGLES);
glColor3f(0.0,1.0,1.0);
glVertex3f(-2.0f,2.0f,0.0f);
glColor3f(1.0,1.0,1.0);
glVertex3f(2.0f,2.0f,0.0f);
glColor3f(2.0,2.0,2.0);
glVertex3f(0.0f,4.0f,0.0f);
glEnd();
//badan rumah
glBegin(GL_QUADS);
glColor3f(1.0,0.5,1.0);
glVertex3f(-2.0f,2.0f,0.0f);
glColor3f(0.5,1.0,0.5);
glVertex3f(2.0f,2.0f,0.0f);
glColor3f(0.5,0.5,0.5);
glVertex3f(2.0f,-2.0f,0.0f);
glColor3f(1.0,0.5,0.0);
glVertex3f(-2.0f,-2.0f,0.0f);
//pintu
glColor3f(1.0,2.0,3.0);
glVertex3f(-1.5f,-2.0f,0.0f);
glVertex3f(-1.5f,0.0f,0.0f);
glVertex3f(-0.5f,0.0f,0.0f);
glVertex3f(-0.5f,-2.0f,0.0f);
//jendela
glColor3f(1.1,1.0,0.5);
glVertex3f(0.5f,0.5f,0.0f);
glVertex3f(0.5f,1.5f,0.0f);
glVertex3f(1.5f,1.5f,0.0f);
glVertex3f(1.5f,0.5f,0.0f);
glEnd();
//garis jendela
glBegin(GL_LINES);
glColor3f(0.0,1.0,1.0);
glVertex3f(0.5f,1.0f,0.0f);
glVertex3f(1.5f,1.0f,0.0f);
glVertex3f(1.0f,1.5f,0.0f);
glVertex3f(1.0f,0.5f,0.0f);
glEnd();
//rumput
glBegin(GL_TRIANGLE_FAN);
glColor3f(0.0,1.0,1.0);
glVertex3f(-2.5f,-2.0f,0.0f);
glColor3f(0.0,1.0,0.0);
glVertex3f(-6.0f,-2.0f,0.0f);
glColor3f(2.0,2.0,2.0);
glVertex3f(-6.5f,-0.5f,0.0f);
glVertex3f(-5.0f,-1.0f,0.0f);
glVertex3f(-4.0f,-0.5f,0.0f);
glVertex3f(-3.0f,-1.0,0.0f);
glVertex3f(-2.1f,-0.5f,0.0f);
glEnd();
void mulaiOpenGL(void)
{
glViewport( 0, 0, 640, 480 );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 60.0f, 640.0f/480.0f, 0.1f, 1000.0f );
Dan pada saat program di execute maka menghasilkan output
semoga bermanfaat
Langganan:
Posting Komentar (Atom)
0 Response to "Membuat Gambar Bagun Datar Menggunakan Pelles C"
Posting Komentar