er

Saturday 25 October 2014

Gambar Sederhana 2D OpenGL (2)

Tema              : Pariwisata Indonesia
Judul Proyek : Museum Fatahillah Jakarta

Deskripsi       
       Gambar 2 dimensi Museum Fatahillah yang berada di daerah Jakarta dibuat dengan menggunakan aplikasi codeblock dengan menggunakan bahasa c++. Objek 2 dimensi ini dibuat sedemikian rupa agar tampak seperti bentuk aslinya. Walaupun masih jauh dengan kenyataan, setidaknya gambar 2 dimensi yang menggunakan aplikasi codeblock ini dibuat secara pribadi dan dibuat semenarik mungkin untuk mendekati gambar aslinya.

#include<GL/glut.h>
#include<stdlib.h>

void display(){
   glClear( GL_COLOR_BUFFER_BIT);

   glPointSize(8);
   glLineWidth(3);


//latarhalaman

glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.3, 0.3, 0.3);
glVertex3f (-1.03, -0.70, 0.0);
glVertex3f (1.72, -0.70, 0.0);

glVertex3f (1.72, -0.70, 0.0);
glVertex3f (1.72, -1.00, 0.0);

glVertex3f (1.72, -1.00, 0.0);
glVertex3f (-1.03, -1.00, 0.0);

glVertex3f (-1.03, -1.00, 0.0);
glVertex3f (-1.03, -0.60, 0.0);

glEnd ();


//lantaisatu
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (-0.87, -0.65, 0.0);
glVertex3f (0.87, -0.65, 0.0);

glVertex3f (0.87, -0.65, 0.0);
glVertex3f (0.87, -0.02, 0.0);

glVertex3f (0.87, -0.02, 0.0);
glVertex3f (-0.87, -0.02, 0.0);

glVertex3f (-0.87, -0.02, 0.0);
glVertex3f (-0.87, -0.65, 0.0);

glEnd ();


//pintu1
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (-0.82, -0.60, 0.0);
glVertex3f (-0.73, -0.60, 0.0);

glVertex3f (-0.73, -0.60, 0.0);
glVertex3f (-0.73, -0.32, 0.0);

glVertex3f (-0.73, -0.32, 0.0);
glVertex3f (-0.82, -0.32, 0.0);

glVertex3f (-0.82, -0.32, 0.0);
glVertex3f (-0.82, -0.60, 0.0);

glEnd ();

//jendela1
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (-0.82, -0.25, 0.0);
glVertex3f (-0.73, -0.25, 0.0);

glVertex3f (-0.73, -0.25, 0.0);
glVertex3f (-0.73, -0.17, 0.0);

glVertex3f (-0.73, -0.17, 0.0);
glVertex3f (-0.82, -0.17, 0.0);

glVertex3f (-0.82, -0.17, 0.0);
glVertex3f (-0.82, -0.25, 0.0);

glEnd ();


//pintu2
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (-0.60, -0.60, 0.0);
glVertex3f (-0.51, -0.60, 0.0);

glVertex3f (-0.51, -0.60, 0.0);
glVertex3f (-0.51, -0.32, 0.0);

glVertex3f (-0.51, -0.32, 0.0);
glVertex3f (-0.60, -0.32, 0.0);

glVertex3f (-0.60, -0.32, 0.0);
glVertex3f (-0.60, -0.60, 0.0);

glEnd ();


//jendela2
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (-0.60, -0.25, 0.0);
glVertex3f (-0.51, -0.25, 0.0);

glVertex3f (-0.51, -0.25, 0.0);
glVertex3f (-0.51, -0.17, 0.0);

glVertex3f (-0.51, -0.17, 0.0);
glVertex3f (-0.60, -0.17, 0.0);

glVertex3f (-0.60, -0.17, 0.0);
glVertex3f (-0.60, -0.25, 0.0);

glEnd ();

//pintu3
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (-0.38, -0.60, 0.0);
glVertex3f (-0.29, -0.60, 0.0);

glVertex3f (-0.29, -0.60, 0.0);
glVertex3f (-0.29, -0.32, 0.0);

glVertex3f (-0.29, -0.32, 0.0);
glVertex3f (-0.38, -0.32, 0.0);

glVertex3f (-0.38, -0.32, 0.0);
glVertex3f (-0.38, -0.60, 0.0);

glEnd ();


//jendela3
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (-0.38, -0.25, 0.0);
glVertex3f (-0.29, -0.25, 0.0);

glVertex3f (-0.29, -0.25, 0.0);
glVertex3f (-0.29, -0.17, 0.0);

glVertex3f (-0.29, -0.17, 0.0);
glVertex3f (-0.38, -0.17, 0.0);

glVertex3f (-0.38, -0.17, 0.0);
glVertex3f (-0.38, -0.25, 0.0);

glEnd ();
//pintu4tengah
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (-0.16, -0.65, 0.0);
glVertex3f (0.22, -0.65, 0.0);

glVertex3f (0.22, -0.65, 0.0);
glVertex3f (0.22, -0.07, 0.0);

glVertex3f (0.22, -0.07, 0.0);
glVertex3f (-0.16, -0.07, 0.0);

glVertex3f (-0.16, -0.07, 0.0);
glVertex3f (-0.16, -0.65, 0.0);

glEnd ();



//pintu4
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (0.32, -0.60, 0.0);
glVertex3f (0.41, -0.60, 0.0);

glVertex3f (0.41, -0.60, 0.0);
glVertex3f (0.41, -0.32, 0.0);

glVertex3f (0.41, -0.32, 0.0);
glVertex3f (0.32, -0.32, 0.0);

glVertex3f (0.32, -0.32, 0.0);
glVertex3f (0.32, -0.60, 0.0);

glEnd ();

//jendela4
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (0.32, -0.25, 0.0);
glVertex3f (0.41, -0.25, 0.0);

glVertex3f (0.41, -0.25, 0.0);
glVertex3f (0.41, -0.17, 0.0);

glVertex3f (0.41, -0.17, 0.0);
glVertex3f (0.32, -0.17, 0.0);

glVertex3f (0.32, -0.17, 0.0);
glVertex3f (0.32, -0.25, 0.0);

glEnd ();

//pintu5
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (0.52, -0.60, 0.0);
glVertex3f (0.61, -0.60, 0.0);

glVertex3f (0.61, -0.60, 0.0);
glVertex3f (0.61, -0.32, 0.0);

glVertex3f (0.61, -0.32, 0.0);
glVertex3f (0.52, -0.32, 0.0);

glVertex3f (0.52, -0.32, 0.0);
glVertex3f (0.52, -0.60, 0.0);

glEnd ();


//jendela5
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (0.52, -0.25, 0.0);
glVertex3f (0.61, -0.25, 0.0);

glVertex3f (0.61, -0.25, 0.0);
glVertex3f (0.61, -0.17, 0.0);

glVertex3f (0.61, -0.17, 0.0);
glVertex3f (0.52, -0.17, 0.0);

glVertex3f (0.52, -0.17, 0.0);
glVertex3f (0.52, -0.25, 0.0);

glEnd ();


//pintu6
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (0.73, -0.60, 0.0);
glVertex3f (0.82, -0.60, 0.0);

glVertex3f (0.82, -0.60, 0.0);
glVertex3f (0.82, -0.32, 0.0);

glVertex3f (0.82, -0.32, 0.0);
glVertex3f (0.73, -0.32, 0.0);

glVertex3f (0.73, -0.32, 0.0);
glVertex3f (0.73, -0.60, 0.0);

glEnd ();

//jendela6
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (0.73, -0.25, 0.0);
glVertex3f (0.82, -0.25, 0.0);

glVertex3f (0.82, -0.25, 0.0);
glVertex3f (0.82, -0.17, 0.0);

glVertex3f (0.82, -0.17, 0.0);
glVertex3f (0.73, -0.17, 0.0);

glVertex3f (0.73, -0.17, 0.0);
glVertex3f (0.73, -0.25, 0.0);

glEnd ();

// atap
glPushMatrix ();

glLineWidth (2.0f);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);

glVertex3f (-0.87, -0.07, 0.0);
glVertex3f (0.87, -0.07, 0.0);

glVertex3f (0.87, -0.01, 0.0);
glVertex3f (0.77, 0.15, 0.0);

glVertex3f (0.77, 0.15, 0.0);
glVertex3f (-0.77, 0.15, 0.0);

glVertex3f (-0.77, 0.15, 0.0);
glVertex3f (-0.87, -0.01, 0.0);

glEnd ();


//jendelatengahataskiri
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (-0.13, -0.27, 0.0);
glVertex3f (0.02, -0.27, 0.0);

glVertex3f (0.02, -0.27, 0.0);
glVertex3f (0.02, -0.19, 0.0);

glVertex3f (0.02, -0.19, 0.0);
glVertex3f (-0.13, -0.19, 0.0);

glVertex3f (-0.13, -0.19, 0.0);
glVertex3f (-0.13, -0.27, 0.0);

glEnd ();
//jendelatengahataskiri2
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (-0.13, -0.18, 0.0);
glVertex3f (0.02, -0.18, 0.0);

glVertex3f (0.02, -0.18, 0.0);
glVertex3f (0.02, -0.10, 0.0);

glVertex3f (0.02, -0.10, 0.0);
glVertex3f (-0.13, -0.10, 0.0);

glVertex3f (-0.13, -0.10, 0.0);
glVertex3f (-0.13, -0.18, 0.0);

glEnd ();

//jendelatengahataskanan
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (0.05, -0.27, 0.0);
glVertex3f (0.20, -0.27, 0.0);

glVertex3f (0.20, -0.27, 0.0);
glVertex3f (0.20, -0.19, 0.0);

glVertex3f (0.20, -0.19, 0.0);
glVertex3f (0.05, -0.19, 0.0);

glVertex3f (0.05, -0.17, 0.0);
glVertex3f (0.05, -0.25, 0.0);

glEnd ();

//jendelatengahbawahkanan
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (0.05, -0.18, 0.0);
glVertex3f (0.20, -0.18, 0.0);

glVertex3f (0.20, -0.18, 0.0);
glVertex3f (0.20, -0.10, 0.0);

glVertex3f (0.20, -0.10, 0.0);
glVertex3f (0.05, -0.10, 0.0);

glVertex3f (0.05, -0.10, 0.0);
glVertex3f (0.05, -0.18, 0.0);

glEnd ();

//pintutengahkiri
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (-0.13, -0.65, 0.0);
glVertex3f (0.02, -0.65, 0.0);

glVertex3f (0.02, -0.65, 0.0);
glVertex3f (0.02, -0.37, 0.0);

glVertex3f (0.02, -0.37, 0.0);
glVertex3f (-0.13, -0.37, 0.0);

glVertex3f (-0.13, -0.37, 0.0);
glVertex3f (-0.13, -0.65, 0.0);

glEnd ();

//pintutengahkanan
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (0.05, -0.65, 0.0);
glVertex3f (0.20, -0.65, 0.0);

glVertex3f (0.20, -0.65, 0.0);
glVertex3f (0.20, -0.37, 0.0);

glVertex3f (0.20, -0.37, 0.0);
glVertex3f (0.05, -0.37, 0.0);

glVertex3f (0.05, -0.37, 0.0);
glVertex3f (0.05, -0.65, 0.0);

glEnd ();

//hiasgenteng
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (-0.32, 0.15, 0.0);
glVertex3f (0.39, 0.15, 0.0);

glVertex3f (0.39, 0.15, 0.0);
glVertex3f (0.39, 0.24, 0.0);

glVertex3f (0.39, 0.24, 0.0);
glVertex3f (-0.32, 0.24, 0.0);

glVertex3f (-0.32, 0.24, 0.0);
glVertex3f (-0.32, 0.15, 0.0);

glEnd ();

//menaratengah
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (-0.12, 0.27, 0.0);
glVertex3f (0.18, 0.27, 0.0);

glVertex3f (0.18, 0.27, 0.0);
glVertex3f (0.18, 0.24, 0.0);

glVertex3f (0.18, 0.24, 0.0);
glVertex3f (-0.12, 0.24, 0.0);

glVertex3f (-0.12, 0.24, 0.0);
glVertex3f (-0.12, 0.27, 0.0);

glEnd ();

//menaratengahatas
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (-0.02, 0.47, 0.0);
glVertex3f (0.08, 0.47, 0.0);

glVertex3f (0.08, 0.47, 0.0);
glVertex3f (0.08, 0.24, 0.0);

glVertex3f (0.08, 0.24, 0.0);
glVertex3f (-0.02, 0.24, 0.0);

glVertex3f (-0.02, 0.24, 0.0);
glVertex3f (-0.02, 0.47, 0.0);

glEnd ();

// atapujungpintu
glPushMatrix ();

glLineWidth (2.0f);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (-0.21, -0.07, 0.0);
glVertex3f (0.27, -0.07, 0.0);

glVertex3f (0.27, -0.01, 0.0);
glVertex3f (0.17, 0.15, 0.0);

glVertex3f (0.17, 0.15, 0.0);
glVertex3f (-0.11, 0.15, 0.0);

glVertex3f (-0.11, 0.15, 0.0);
glVertex3f (-0.21, -0.01, 0.0);

glEnd ();

// atapujungpintu2
glPushMatrix ();

glLineWidth (2.0f);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (-0.21, -0.00, 0.0);
glVertex3f (0.27, -0.00, 0.0);

glVertex3f (0.27, 0.06, 0.0);
glVertex3f (0.17, 0.22, 0.0);

glVertex3f (0.17, 0.22, 0.0);
glVertex3f (-0.11, 0.22, 0.0);

glVertex3f (-0.11, 0.22, 0.0);
glVertex3f (-0.21, 0.06, 0.0);

glEnd ();

// atapujungmenara
glPushMatrix ();

glLineWidth (2.0f);
glBegin (GL_POLYGON);
glColor3f (0.3, 0.3, 0.3);

glVertex3f (-0.03, 0.30, 0.0);
glVertex3f (0.09, 0.30, 0.0);

glVertex3f (0.09, 0.36, 0.0);
glVertex3f (0.07, 0.52, 0.0);

glVertex3f (0.07, 0.52, 0.0);
glVertex3f (-0.01, 0.52, 0.0);

glVertex3f (-0.01, 0.52, 0.0);
glVertex3f (-0.03, 0.36, 0.0);

glEnd ();

// atapujungmenarapol
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);

glVertex3f (0.02, 0.52, 0.0);
glVertex3f (0.04, 0.52, 0.0);

glVertex3f (0.04, 0.52, 0.0);
glVertex3f (0.04, 0.65, 0.0);

glVertex3f (0.04, 0.65, 0.0);
glVertex3f (0.02, 0.65, 0.0);

glVertex3f (0.02, 0.65, 0.0);
glVertex3f (0.02, 0.52, 0.0);

glEnd ();

//jendelagentengkiri1
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (-0.75, 0.00, 0.0);
glVertex3f (-0.66, 0.00, 0.0);

glVertex3f (-0.66, 0.00, 0.0);
glVertex3f (-0.66, 0.07, 0.0);

glVertex3f (-0.66, 0.07, 0.0);
glVertex3f (-0.75, 0.07, 0.0);

glVertex3f (-0.75, 0.07, 0.0);
glVertex3f (-0.75, 0.00, 0.0);

glEnd ();

//jendelagentengkiri2
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (-0.55, 0.00, 0.0);
glVertex3f (-0.46, 0.00, 0.0);

glVertex3f (-0.46, 0.00, 0.0);
glVertex3f (-0.46, 0.07, 0.0);

glVertex3f (-0.46, 0.07, 0.0);
glVertex3f (-0.55, 0.07, 0.0);

glVertex3f (-0.55, 0.07, 0.0);
glVertex3f (-0.55, 0.00, 0.0);

glEnd ();

//jendelagentengkiri3
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (-0.35, 0.00, 0.0);
glVertex3f (-0.26, 0.00, 0.0);

glVertex3f (-0.26, 0.00, 0.0);
glVertex3f (-0.26, 0.07, 0.0);

glVertex3f (-0.26, 0.07, 0.0);
glVertex3f (-0.35, 0.07, 0.0);

glVertex3f (-0.35, 0.07, 0.0);
glVertex3f (-0.35, 0.00, 0.0);

glEnd ();

//jendelagentengkanan1
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (0.38, 0.00, 0.0);
glVertex3f (0.29, 0.00, 0.0);

glVertex3f (0.29, 0.00, 0.0);
glVertex3f (0.29, 0.07, 0.0);

glVertex3f (0.29, 0.07, 0.0);
glVertex3f (0.38, 0.07, 0.0);

glVertex3f (0.38, 0.07, 0.0);
glVertex3f (0.38, 0.00, 0.0);

glEnd ();

//jendelagentengkanan2
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (0.58, 0.00, 0.0);
glVertex3f (0.49, 0.00, 0.0);

glVertex3f (0.49, 0.00, 0.0);
glVertex3f (0.49, 0.07, 0.0);

glVertex3f (0.49, 0.07, 0.0);
glVertex3f (0.58, 0.07, 0.0);

glVertex3f (0.58, 0.07, 0.0);
glVertex3f (0.58, 0.00, 0.0);

glEnd ();

//jendelagentengkanan3
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);

glVertex3f (0.78, 0.00, 0.0);
glVertex3f (0.69, 0.00, 0.0);

glVertex3f (0.69, 0.00, 0.0);
glVertex3f (0.69, 0.07, 0.0);

glVertex3f (0.69, 0.07, 0.0);
glVertex3f (0.78, 0.07, 0.0);

glVertex3f (0.78, 0.07, 0.0);
glVertex3f (0.78, 0.00, 0.0);

glEnd ();

   glFlush();

}

void init(){
     glClearColor(0.7, 0.7, 0.7, 0.7);//definisiin warna clear atau background

     glMatrixMode(GL_PROJECTION);

     glLoadIdentity ();

     gluOrtho2D(-1.0,1.0,-1.0,1.0);//MENENTUKAN UKURAN KANVAS
     //           k   k    b   a
     glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char **argv){
    glutInit(&argc,argv);
    glutInitWindowSize(800,400);
    glutInitWindowPosition(300,300);//jarak windows dari tepi monitor

    glutCreateWindow("Gedung Fatahillah jkt");
    glutDisplayFunc(display);
    init();
    glutMainLoop();//mulai render
    return 0;
}




Comments
0 Comments

0 comments:

Post a Comment

Berkomentarlah dengan kata-kata yang sopan, tidak spam, dan bijak ^.^
Terima Kasih telah berkunjung