Grafika Komputer
Created By : Ahmad Asif Qolbi
Deskripsi Objek :
Gambar
2 dimensi ini merupakan gambaran lingkungan Universitas Negeri Semarang pada
malam hari. Dimana lingkungan sekitar terdapat banyak pepohonan yang membuat
udara sejuk dan nyaman tanpa ada polusi udara. Pemandangan tersebut terlihat
dari kampus Unnes dimana terlihat jalan yang mengarah ke atas menuju
Universitas Negeri Semarang. Unnes adalah kampus konservasi, dimana kampus
konservasi adalah kampus yang peduli terhadap lingkungan yang hijau dikelilingi
banyak pohon di kawasan kampus.
Gambar
ini sangat memperdulikan keselarasan warna dengan tema sehingga membuat gambar
2dimensi ini terlihat nyaman untuk dilihat. Gambar ini identik dengan kampus
Universitas Negeri Semarang yang terletak di daerah pegunungan serta banyaknya
pepohonan yang ada di kawasan sekitar Unnes sehingga kampus Unnes tampak sangat
asri.
Source Code :
#include<GL/glut.h>
#include<stdlib.h>
void display(){
glClear( GL_COLOR_BUFFER_BIT);
glPointSize(8);
glLineWidth(3);
//huruf u
glBegin(GL_POLYGON);
glVertex2f(-0.9,0.7);
glColor3f(0.0,1.0,1.0);
glVertex2f(-0.8,0.7);
glVertex2f(-0.8,0.2);
glColor3f(0.0,0.0,1.0);
glVertex2f(-0.9,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(-0.8,0.3);
glColor3f(0.0,1.0,1.0);
glVertex2f(-0.8,0.3);
glVertex2f(-0.6,0.2);
glVertex2f(-0.8,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(-0.7,0.7);
glColor3f(0.0,1.0,1.0);
glVertex2f(-0.6,0.7);
glVertex2f(-0.6,0.2);
glColor3f(0.0,0.0,1.0);
glVertex2f(-0.7,0.2);
glEnd();
// huruf n1
glBegin(GL_POLYGON);
glVertex2f(-0.5,0.7);
glColor3f(1.0,0.0,0.0);
glVertex2f(-0.4,0.7);
glColor3f(1.0,0.0,1.0);
glVertex2f(-0.4,0.2);
glVertex2f(-0.5,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(-0.4,0.7);
glColor3f(1.0,1.5,0.0);
glVertex2f(-0.4,0.5);
glVertex2f(-0.2,0.2);
glVertex2f(-0.2,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(-0.3,0.7);
glColor3f(0.0,0.5,1.0);
glVertex2f(-0.2,0.7);
glColor3f(1.0,0.0,1.0);
glVertex2f(-0.2,0.2);
glVertex2f(-0.3,0.2);
glEnd();
// huruf n2
glBegin(GL_POLYGON);
glVertex2f(-0.1,0.7);
glColor3f(1.0,0.0,0.0);
glVertex2f(0.0,0.7);
glColor3f(1.0,0.0,1.0);
glVertex2f(0.0,0.2);
glVertex2f(-0.1,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.0,0.7);
glColor3f(1.0,1.5,0.0);
glVertex2f(0.0,0.5);
glVertex2f(0.2,0.2);
glVertex2f(0.2,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.1,0.7);
glColor3f(0.0,0.5,1.0);
glVertex2f(0.2,0.7);
glColor3f(1.0,0.0,1.0);
glVertex2f(0.2,0.2);
glVertex2f(0.1,0.2);
glEnd();
// huruf e
glBegin(GL_POLYGON);
glVertex2f(0.3,0.3);
glColor3f(0.0,1.0,1.0);
glVertex2f(0.5,0.3);
glVertex2f(0.5,0.2);
glVertex2f(0.3,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.3,0.7);
glColor3f(1.0,0.0,0.0);
glVertex2f(0.4,0.7);
glColor3f(1.0,0.0,1.0);
glVertex2f(0.4,0.2);
glVertex2f(0.3,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.3,0.7);
glColor3f(0.0,1.0,1.0);
glVertex2f(0.5,0.7);
glVertex2f(0.5,0.6);
glVertex2f(0.3,0.6);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.3,0.5);
glColor3f(0.0,1.0,1.0);
glVertex2f(0.5,0.5);
glVertex2f(0.5,0.4);
glVertex2f(0.3,0.4);
glEnd();
// huruf s
glBegin(GL_POLYGON);
glVertex2f(0.6,0.7);
glColor3f(0.0,1.0,1.0);
glVertex2f(0.8,0.7);
glVertex2f(0.8,0.6);
glVertex2f(0.6,0.6);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.6,0.7);
glColor3f(0.0,1.0,1.0);
glVertex2f(0.7,0.7);
glVertex2f(0.7,0.4);
glColor3f(0.0,0.0,1.0);
glVertex2f(0.6,0.4);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.7,0.5);
glColor3f(0.0,1.0,1.0);
glVertex2f(0.8,0.5);
glVertex2f(0.8,0.4);
glVertex2f(0.7,0.4);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.7,0.5);
glColor3f(0.0,1.0,1.0);
glVertex2f(0.8,0.5);
glVertex2f(0.8,0.2);
glColor3f(0.0,0.0,1.0);
glVertex2f(0.7,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.6,0.3);
glColor3f(0.0,1.0,1.0);
glVertex2f(0.8,0.3);
glVertex2f(0.8,0.2);
glVertex2f(0.6,0.2);
glEnd();
// pohon1
glPushMatrix ();
glBegin (GL_POLYGON);
glColor3f (0.0f, 0.7f, 0.0f);
glVertex3f (-0.83, -0.28, 0.0);
glVertex3f (-0.47, -0.28, 0.0);
glVertex3f (-0.47, -0.28, 0.0);
glVertex3f (-0.58, -0.16, 0.0);
glVertex3f (-0.58, -0.16, 0.0);
glVertex3f (-0.70, -0.16, 0.0);
glVertex3f (-0.70, -0.16, 0.0);
glVertex3f (-0.83, -0.28, 0.0);
glEnd ();
glPopMatrix();
// warnain pohon kanan. bwh 2
glPushMatrix ();
glLineWidth (2.0f);
glBegin (GL_POLYGON);
glColor3f (0.0f, 0.7f, 0.0f);
glVertex3f (-0.77, -0.16, 0.0);
glVertex3f (-0.52, -0.16, 0.0);
glVertex3f (-0.52, -0.16, 0.0);
glVertex3f (-0.61, -0.04, 0.0);
glVertex3f (-0.61, -0.04, 0.0);
glVertex3f (-0.67, -0.04, 0.0);
glVertex3f (-0.67, -0.04, 0.0);
glVertex3f (-0.77, -0.16, 0.0);
glEnd ();
glPopMatrix();
//batangpohon1kanan
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (-0.67, -0.28, 0.0);
glVertex3f (-0.61, -0.28, 0.0);
glVertex3f (-0.61, -0.28, 0.0);
glVertex3f (-0.61, -0.64, 0.0);
glVertex3f (-0.61, -0.64, 0.0);
glVertex3f (-0.67, -0.64, 0.0);
glVertex3f (-0.67, -0.64, 0.0);
glVertex3f (-0.67, -0.28, 0.0);
glEnd ();
//pohon2
// pohon
glPushMatrix ();
glBegin (GL_POLYGON);
glColor3f (0.0f, 0.7f, 0.0f);
glVertex3f (-0.50, -0.28, 0.0);
glVertex3f (-0.13, -0.28, 0.0);
glVertex3f (-0.13, -0.28, 0.0);
glVertex3f (-0.25, -0.16, 0.0);
glVertex3f (-0.25, -0.16, 0.0);
glVertex3f (-0.37, -0.16, 0.0);
glVertex3f (-0.37, -0.16, 0.0);
glVertex3f (-0.50, -0.28, 0.0);
glEnd ();
glPopMatrix();
// warnain pohon kanan. bwh 2
glPushMatrix ();
glLineWidth (2.0f);
glBegin (GL_POLYGON);
glColor3f (0.0f, 0.7f, 0.0f);
glVertex3f (-0.43, -0.16, 0.0);
glVertex3f (-0.18, -0.16, 0.0);
glVertex3f (-0.18, -0.16, 0.0);
glVertex3f (-0.27, -0.04, 0.0);
glVertex3f (-0.27, -0.04, 0.0);
glVertex3f (-0.33, -0.04, 0.0);
glVertex3f (-0.33, -0.04, 0.0);
glVertex3f (-0.43, -0.16, 0.0);
glEnd ();
glPopMatrix();
//batangpohon2kanan
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (-0.33, -0.28, 0.0);
glVertex3f (-0.27, -0.28, 0.0);
glVertex3f (-0.27, -0.28, 0.0);
glVertex3f (-0.27, -0.64, 0.0);
glVertex3f (-0.27, -0.64, 0.0);
glVertex3f (-0.33, -0.64, 0.0);
glVertex3f (-0.33, -0.64, 0.0);
glVertex3f (-0.33, -0.28, 0.0);
glEnd ();
// gedungunnes
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);
glVertex3f (-0.03, -0.28, 0.0);
glVertex3f (0.72, -0.28, 0.0);
glVertex3f (0.72, -0.28, 0.0);
glVertex3f (0.72, -0.64, 0.0);
glVertex3f (0.72, -0.64, 0.0);
glVertex3f (-0.03, -0.64, 0.0);
glVertex3f (-0.03, -0.64, 0.0);
glVertex3f (-0.03, -0.28, 0.0);
glEnd ();
//atap gedung
glPushMatrix ();
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (-0.10, -0.28, 0.0);
glVertex3f (0.80, -0.28, 0.0);
glVertex3f (0.80, -0.28, 0.0);
glVertex3f (0.68, -0.16, 0.0);
glVertex3f (0.68, -0.16, 0.0);
glVertex3f (0.03, -0.16, 0.0);
glVertex3f (0.00, -0.16, 0.0);
glVertex3f (-0.12, -0.28, 0.0);
glEnd ();
glPopMatrix();
//jalan
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 1.0, 1.0);
glVertex3f (-1.03, -0.70, 0.0);
glVertex3f (1.72, -0.70, 0.0);
glVertex3f (1.72, -0.70, 0.0);
glVertex3f (1.72, -0.96, 0.0);
glVertex3f (1.72, -0.96, 0.0);
glVertex3f (-1.03, -0.96, 0.0);
glVertex3f (-1.03, -0.96, 0.0);
glVertex3f (-1.03, -0.60, 0.0);
glEnd ();
//garis jalan2
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (0.90, -0.85, 0.0);
glVertex3f (0.82, -0.85, 0.0);
glVertex3f (0.82, -0.85, 0.0);
glVertex3f (0.82, -0.80, 0.0);
glVertex3f (0.82, -0.80, 0.0);
glVertex3f (0.90, -0.80, 0.0);
glVertex3f (0.90, -0.80, 0.0);
glVertex3f (0.90, -0.50, 0.0);
glEnd ();
// garis jalan 3
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (0.70, -0.85, 0.0);
glVertex3f (0.62, -0.85, 0.0);
glVertex3f (0.62, -0.85, 0.0);
glVertex3f (0.62, -0.80, 0.0);
glVertex3f (0.62, -0.80, 0.0);
glVertex3f (0.70, -0.80, 0.0);
glVertex3f (0.70, -0.80, 0.0);
glVertex3f (0.70, -0.50, 0.0);
glEnd ();
// garis jalan 4
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (0.50, -0.85, 0.0);
glVertex3f (0.42, -0.85, 0.0);
glVertex3f (0.42, -0.85, 0.0);
glVertex3f (0.42, -0.80, 0.0);
glVertex3f (0.42, -0.80, 0.0);
glVertex3f (0.50, -0.80, 0.0);
glVertex3f (0.50, -0.80, 0.0);
glVertex3f (0.50, -0.50, 0.0);
glEnd ();
// garis jalan 5
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (0.30, -0.85, 0.0);
glVertex3f (0.22, -0.85, 0.0);
glVertex3f (0.22, -0.85, 0.0);
glVertex3f (0.22, -0.80, 0.0);
glVertex3f (0.22, -0.80, 0.0);
glVertex3f (0.30, -0.80, 0.0);
glVertex3f (0.30, -0.80, 0.0);
glVertex3f (0.30, -0.50, 0.0);
glEnd ();
// garis jalan 6
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (0.10, -0.85, 0.0);
glVertex3f (0.02, -0.85, 0.0);
glVertex3f (0.02, -0.85, 0.0);
glVertex3f (0.02, -0.80, 0.0);
glVertex3f (0.02, -0.80, 0.0);
glVertex3f (0.10, -0.80, 0.0);
glVertex3f (0.10, -0.80, 0.0);
glVertex3f (0.10, -0.50, 0.0);
glEnd ();
// garis jalan 7
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (-0.20, -0.85, 0.0);
glVertex3f (-0.12, -0.85, 0.0);
glVertex3f (-0.12, -0.85, 0.0);
glVertex3f (-0.12, -0.80, 0.0);
glVertex3f (-0.12, -0.80, 0.0);
glVertex3f (-0.20, -0.80, 0.0);
glVertex3f (-0.20, -0.80, 0.0);
glVertex3f (-0.20, -0.50, 0.0);
glEnd ();
// garis jalan 8
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (-0.40, -0.85, 0.0);
glVertex3f (-0.32, -0.85, 0.0);
glVertex3f (-0.32, -0.85, 0.0);
glVertex3f (-0.32, -0.80, 0.0);
glVertex3f (-0.32, -0.80, 0.0);
glVertex3f (-0.40, -0.80, 0.0);
glVertex3f (-0.40, -0.80, 0.0);
glVertex3f (-0.40, -0.50, 0.0);
glEnd ();
// garis jalan 9
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (-0.60, -0.85, 0.0);
glVertex3f (-0.52, -0.85, 0.0);
glVertex3f (-0.52, -0.85, 0.0);
glVertex3f (-0.52, -0.80, 0.0);
glVertex3f (-0.52, -0.80, 0.0);
glVertex3f (-0.60, -0.80, 0.0);
glVertex3f (-0.60, -0.80, 0.0);
glVertex3f (-0.60, -0.50, 0.0);
glEnd ();
// garis jalan 10
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (-0.80, -0.85, 0.0);
glVertex3f (-0.72, -0.85, 0.0);
glVertex3f (-0.72, -0.85, 0.0);
glVertex3f (-0.72, -0.80, 0.0);
glVertex3f (-0.72, -0.80, 0.0);
glVertex3f (-0.80, -0.80, 0.0);
glVertex3f (-0.80, -0.80, 0.0);
glVertex3f (-0.80, -0.50, 0.0);
glEnd ();
// garis jalan 11
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0, 0.2, 0.0);
glVertex3f (-1.00, -0.85, 0.0);
glVertex3f (-0.92, -0.85, 0.0);
glVertex3f (-0.92, -0.85, 0.0);
glVertex3f (-0.92, -0.80, 0.0);
glVertex3f (-0.92, -0.80, 0.0);
glVertex3f (-1.00, -0.80, 0.0);
glVertex3f (-1.00, -0.80, 0.0);
glVertex3f (-1.00, -0.50, 0.0);
glEnd ();
//gedunghias
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (0.67, -0.28, 0.0);
glVertex3f (0.61, -0.28, 0.0);
glVertex3f (0.61, -0.28, 0.0);
glVertex3f (0.61, -0.64, 0.0);
glVertex3f (0.61, -0.64, 0.0);
glVertex3f (0.67, -0.64, 0.0);
glVertex3f (0.67, -0.64, 0.0);
glVertex3f (0.67, -0.28, 0.0);
glEnd ();
//gedunghias2
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (0.09, -0.28, 0.0);
glVertex3f (0.03, -0.28, 0.0);
glVertex3f (0.03, -0.28, 0.0);
glVertex3f (0.03, -0.64, 0.0);
glVertex3f (0.03, -0.64, 0.0);
glVertex3f (0.09, -0.64, 0.0);
glVertex3f (0.09, -0.64, 0.0);
glVertex3f (0.09, -0.28, 0.0);
glEnd ();
//pintu
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (1.0f, 0.2f, 0.0f);
glVertex3f (0.40, -0.43, 0.0);
glVertex3f (0.30, -0.43, 0.0);
glVertex3f (0.30, -0.43, 0.0);
glVertex3f (0.30, -0.64, 0.0);
glVertex3f (0.30, -0.64, 0.0);
glVertex3f (0.40, -0.64, 0.0);
glVertex3f (0.40, -0.64, 0.0);
glVertex3f (0.40, -0.43, 0.0);
glEnd ();
//pintukunci
glPushMatrix ();
glLineWidth (1.9f);
glBegin (GL_LINES);
glBegin (GL_POLYGON);
glColor3f (0.0, 0.0, 0.0);
glVertex3f (0.35, -0.48, 0.0);
glVertex3f (0.30, -0.48, 0.0);
glVertex3f (0.30, -0.48, 0.0);
glVertex3f (0.30, -0.50, 0.0);
glVertex3f (0.30, -0.50, 0.0);
glVertex3f (0.35, -0.50, 0.0);
glVertex3f (0.35, -0.50, 0.0);
glVertex3f (0.35, -0.48, 0.0);
glEnd ();
glFlush();
}
void init(){
glClearColor(0.0, 0.0, 0.0, 0.0);//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("My Kampus");
glutDisplayFunc(display);
init();
glutMainLoop();//mulai render
return 0;
}
Screenshot :