LAPO
LAPO
Oleh:
Wisnu Alfarisi 4611415011
Dosen Pengampu:
Aji Purwinarko S.Si., M.Cs.
#include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include "glm.h"
GLubyte kuning[3]={255,255,0};
void bintang(void) {
int s; // ukuran titik
float x,y; // posisi titik
for(int i=0;i<1000;i++){
s=rand()%4+1;
glPointSize(s);
glColor3ubv(kuning);
glBegin(GL_POINTS);
x=-24+200*(float)rand()/RAND_MAX;
y=4+200*(float)rand()/RAND_MAX;
glVertex2f(x,y);
glEnd();
}
}
void awanAtas(){
glColor3f(1,1,1);
glPushMatrix();
glTranslatef(-10,10,-5);
//circle(1);
glutSolidSphere(0.8, 20, 10);
glPopMatrix();
glPushMatrix();
glTranslatef(-9.5,10,-5);
//circle(1);
glutSolidSphere(1, 20, 10);
glPopMatrix();
glPushMatrix();
glTranslatef(-8.5,10,-5);
//circle(1);
glutSolidSphere(0.8, 20, 10);
glPopMatrix();
}
void awanBawah(){
glColor3f(1,1,1);
glPushMatrix();
glTranslatef(2,7,5);
//circle(1.2);
glutSolidSphere(0.6, 20, 10);
glPopMatrix();
glPushMatrix();
glTranslatef(3.0,7,5);
//circle(1.2);
glutSolidSphere(0.9, 9, 9);
glPopMatrix();
glPushMatrix();
glTranslatef(4.0,7,5);
//circle(1.2);
glutSolidSphere(0.9, 15, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(5.0,7,5);
//circle(1.2);
glutSolidSphere(0.6, 10, 10);
glPopMatrix();
glBegin(GL_LINES);
glLineWidth(1);
glEnd();
}
float kecepatan;
void waktu(int ) //harus integer
{
// Timer code here
kecepatan ++;
//refresh tampilan
glutPostRedisplay();
glColor3f(0.60,0.40,0.12);
glBegin(GL_TRIANGLES);
glVertex3d(9,0,8);
glColor3f(0.10,0.10,0.0);
glVertex3d(6,5,8);
glColor3f(0.10,0.10,0.0);
glVertex3d(-1,0,8);
glEnd();
glColor3f(0.60,0.40,0.12);
glBegin(GL_POLYGON);
glVertex3d(-4,0,9);
glColor3f(0.10,0.10,0.0);
glVertex3d(-2,7,9);
glColor3f(0.10,0.10,0.0);
glVertex3d(-1,6,9);
glColor3f(0.10,0.10,0.0);
glVertex3d(0,6,9);
glColor3f(0.10,0.10,0.0);
glVertex3d(3,0,9);
glEnd();
}
FILE *file;
short int bpp;
short int planes;
long size;
unsigned int texture;
long imwidth;
long imheight;
char *imdata;
fread(&imwidth, 4, 1, file);
fread(&imheight, 4, 1, file);
size = imwidth * imheight * 3;
fread(&bpp, 2, 1, file);
fread(&planes, 2, 1, file);
char temp;
for(long i = 0; i < size; i+=3){
temp = imdata[i];
imdata[i] = imdata[i+2];
imdata[i+2] = temp;
}
fclose(file);
void danau()
{
//danau
glPushMatrix();
glColor3b(0,0,255);
glBegin(GL_POLYGON);
glColor3ub(0,0.1,255);
glVertex3d(-8.8,0.1,8.5);
glColor3ub(0,0,225);
glVertex3d(-8.8,0.1,4.5);
glColor3ub(0,0,220);
glVertex3d(8.8,0.1,4.5);
glColor3ub(0,0,200);
glVertex3d(8.8,0.1,8.5);
glEnd();
glPopMatrix();
}
void perahu()
{
//perahu
glPushMatrix();
glColor3f(0.1,0.0,0.1);
glBegin(GL_POLYGON);
glVertex3d(-3,0.1,6);
glColor3ub(238,130,238);
glVertex3d(-5,0.1,6);
glColor3ub(230,130,238);
glVertex3d(-7,0.7,6);
glColor3ub(230,120,238);
glVertex3d(-1,0.7,6);
glEnd();
glPopMatrix();
void rumah2an()
{
glPushMatrix();
//atap
glColor3f(0.8,0.0,0.0);
glBegin(GL_TRIANGLE_FAN);
glVertex3d(-0.5,4,-4);
glVertex3d(-2,2,-6);
glVertex3d(1,2,-6);
glColor3f(0.8,0.2,0.0);
glVertex3d(-2,2,-6);
glVertex3d(-2,2,-2);
glColor3f(0.8,0.2,0.0);
glVertex3d(1,2,-6);
glVertex3d(1,2,-2);
glColor3f(0.8,0.0,0.0);
glVertex3d(-2,2,-2);
glVertex3d(1,2,-2);
glEnd();
//dinding
//depan
glColor3f(0.8,0.8,1.0);
glBegin(GL_POLYGON);
glVertex3d(-1.7,0.1,-6);
glColor3f(0.8,0.8,0.5);
glVertex3d(-1.7,2,-6);
glColor3f(0.8,1.0,0.5);
glVertex3d(0.7,2,-6);
glVertex3d(0.7,0.1,-6);
glEnd();
//jendela depan
glBegin(GL_POLYGON);
glColor3ub(255,215,0);
glVertex3d(-1.3,1.7,-6.1);
glVertex3d(-0.7,1.7,-6.1);
glVertex3d(-0.7,1.0,-6.1);
glVertex3d(-1.3,1.0,-6.1);
glEnd();
//pintu depan
glBegin(GL_POLYGON);
glColor3ub(139,69,19);
glVertex3d(-0.2,1.4,-6.1);
glVertex3d(-0.2,0.1,-6.1);
glVertex3d(0.5,0.1,-6.1);
glVertex3d(0.5,1.4,-6.1);
glEnd();
glColor3f(0.0,0.0,0.0);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex3d(-1.3,1.7,-6.1);
glVertex3d(-0.7,1.7,-6.1);
glVertex3d(-0.7,1.0,-6.1);
glVertex3d(-1.3,1.0,-6.1);
glEnd();
//samping kanan
glColor3f(0.8,1.0,1.0);
glBegin(GL_POLYGON);
glVertex3d(-1.7,0.1,-6);
glColor3f(0.8,0.8,0.5);
glVertex3d(-1.7,2,-6);
glColor3f(0.8,1.0,0.5);
glVertex3d(-1.7,2,-2);
glVertex3d(-1.7,0.1,-2);
glEnd();
//samping kiri
glColor3f(0.8,1.0,1.0);
glBegin(GL_POLYGON);
glVertex3d(0.7,0.1,-6);
glColor3f(0.8,0.8,0.5);
glVertex3d(0.7,2,-6);
glColor3f(0.8,1.0,0.5);
glVertex3d(0.7,2,-2);
glVertex3d(0.7,0.1,-2);
glEnd();
//belakang
glColor3f(0.8,0.8,1.0);
glBegin(GL_POLYGON);
glVertex3d(-1.7,0.1,-2);
glColor3f(0.8,0.8,0.5);
glVertex3d(-1.7,2,-2);
glColor3f(0.8,1.0,0.5);
glVertex3d(0.7,2,-2);
glVertex3d(0.7,0.1,-2);
glEnd();
glPopMatrix();
//bebatuan
glPushMatrix();
glTranslatef(7, 0.0, -6);
glColor3ub(169,169,169);
glutSolidSphere(0.8, 5, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(7.5, 0.0, -6);
glColor3ub(169,169,169);
glutSolidSphere(0.4, 5, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(8.0, 0.0, -6);
glColor3ub(169,169,169);
glutSolidSphere(0.4, 5, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(-7, 0.0, -6);
glColor3ub(169,169,169);
glutSolidSphere(0.8, 5, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(-6.5, 0.0, -3);
glColor3ub(169,169,169);
glutSolidSphere(0.4, 5, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(-6.0, 0.0, -3);
glColor3ub(169,169,169);
glutSolidSphere(0.4, 5, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(-6.5, 0.0, 8);
glColor3ub(169,169,169);
glutSolidSphere(0.4, 5, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(-6.0, 0.0, 8);
glColor3ub(169,169,169);
glutSolidSphere(0.4, 5, 5);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-8.0, 0.0, 9);
glColor3ub(169,169,169);
glutSolidSphere(0.4, 5, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(7.5, 0.0, 7.5);
glColor3ub(169,169,169);
glutSolidSphere(0.4, 5, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(8.0, 0.0, 7.5);
glColor3ub(169,169,169);
glutSolidSphere(0.4, 5, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(8, 0.0, 5);
glColor3ub(169,169,169);
glutSolidSphere(0.8, 5, 5);
glPopMatrix();
glPushMatrix();
glTranslatef(7.5, 0.0, 5);
glColor3ub(169,169,169);
glutSolidSphere(0.4, 5, 5);
glPopMatrix();
}
//pagar
void pagar()
{
glColor3ub(125,33,234);
glBegin(GL_POLYGON);
glColor3ub(128,0,0);
glVertex3d(-1,0.1,-10);
glColor3ub(188,143,143);
glVertex3d(-1,1,-10);
glColor3ub(255,255,0);
glVertex3d(-1.5,1.5,-10);
glColor3ub(255,69,0);
glVertex3d(-2,1,-10);
glColor3ub(34,139,34);
glVertex3d(-2,0.1,-10);
glEnd();
glColor3ub(125,33,234);
glBegin(GL_POLYGON);
glColor3ub(128,0,0);
glVertex3d(-2,0.1,-10);
glColor3ub(188,143,143);
glVertex3d(-2,1,-10);
glColor3ub(255,255,0);
glVertex3d(-2.5,1.5,-10);
glColor3ub(255,69,0);
glVertex3d(-3,1,-10);
glColor3ub(34,139,34);
glVertex3d(-3,0.1,-10);
glEnd();
glBegin(GL_POLYGON);
glColor3ub(128,0,0);
glVertex3d(-3,0.1,-10);
glColor3ub(188,143,143);
glVertex3d(-3,1,-10);
glColor3ub(255,255,0);
glVertex3d(-3.5,1.5,-10);
glColor3ub(255,69,0);
glVertex3d(-4,1,-10);
glColor3ub(34,139,34);
glVertex3d(-4,0.1,-10);
glEnd();
}
void tembok()
{
glColor3ub(255,228,225);
glBegin(GL_POLYGON);
glVertex3d(4,0.1,-8.9);
glVertex3d(4,1.3,-8.9);
glVertex3d(2.1,1.3,-8.9);
glVertex3d(2.1,0.1,-8.9);
glEnd();
//tulisan welcome
glColor3ub(0,0,0);
glBegin(GL_LINES);
//huruf W
glVertex3d(3.8,0.5,-9);
glVertex3d(3.8,1.2,-9);
glVertex3d(3.8,0.5,-9);
glVertex3d(3.7,0.7,-9);
glVertex3d(3.7,0.7,-9);
glVertex3d(3.6,0.5,-9);
glVertex3d(3.6,0.5,-9);
glVertex3d(3.6,1.2,-9);
//huruf E
glVertex3d(3.5,0.5,-9);
glVertex3d(3.5,1.2,-9);
glVertex3d(3.4,0.5,-9);
glVertex3d(3.5,0.5,-9);
glVertex3d(3.4,0.9,-9);
glVertex3d(3.5,0.9,-9);
glVertex3d(3.4,1.2,-9);
glVertex3d(3.5,1.2,-9);
//huruf L
glVertex3d(3.3,0.5,-9);
glVertex3d(3.3,1.2,-9);
glVertex3d(3.2,0.5,-9);
glVertex3d(3.3,0.5,-9);
//huruf C
glVertex3d(3.1,0.5,-9);
glVertex3d(3.1,1.2,-9);
glVertex3d(3.0,0.5,-9);
glVertex3d(3.1,0.5,-9);
glVertex3d(3.0,1.2,-9);
glVertex3d(3.1,1.2,-9);
//huruf 0
glVertex3d(2.9,0.5,-9);
glVertex3d(2.9,1.2,-9);
glVertex3d(2.8,0.5,-9);
glVertex3d(2.9,0.5,-9);
glVertex3d(2.8,1.2,-9);
glVertex3d(2.9,1.2,-9);
glVertex3d(2.8,0.5,-9);
glVertex3d(2.8,1.2,-9);
//huruf M
glVertex3d(2.7,0.5,-9);
glVertex3d(2.7,1.2,-9);
glVertex3d(2.5,0.5,-9);
glVertex3d(2.5,1.2,-9);
glVertex3d(2.6,1.0,-9);
glVertex3d(2.7,1.2,-9);
glVertex3d(2.6,1.0,-9);
glVertex3d(2.5,1.2,-9);
//huruf E
glVertex3d(2.4,0.5,-9);
glVertex3d(2.4,1.2,-9);
glVertex3d(2.3,0.5,-9);
glVertex3d(2.4,0.5,-9);
glVertex3d(2.3,0.9,-9);
glVertex3d(2.4,0.9,-9);
glVertex3d(2.3,1.2,-9);
glVertex3d(2.4,1.2,-9);
glEnd();
glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cetak();
//bintang + awan + perahu
bintang();
glPushMatrix();
glTranslatef(speed,0,0);
awanAtas();
glPopMatrix();
glPushMatrix();
glTranslatef(cepat,0,0);
awanBawah();
glPopMatrix();
glPushMatrix();
glTranslatef(cepat*0.5,0,0);
perahu();
glPopMatrix();
danau();
//bulan
glPushMatrix();
glRotatef(0.0,8,6,9);
glTranslatef(speed*0.1,8,9);
glColor3ub(255,215,0);
glutSolidSphere(0.6, 20, 10);
glPopMatrix();
//rumput
glPushMatrix();
glColor3b(0,100,0);
glBegin(GL_POLYGON);
glVertex3d(-9,0,-10);
glVertex3d(-9,0,10);
glVertex3d(9,0,10);
glVertex3d(9,0,-10);
glEnd();
glPopMatrix();
//pohon
//batang
glPushMatrix();
glTranslatef( -8, 1.0, 0.5);
glRotatef(45.0, 0.0, 1.0, 0.0);
glScalef(1.0, 6.0, 1.0);
glColor3ub(139, 69, 19);
glutSolidCube(0.5);
glPopMatrix();
//daun
glPushMatrix(); //daun1
glTranslatef(-8, 2.0, 0.5);
glColor3f(0.5, 1.0, 0.0);
glutSolidSphere(1.0, 20, 10);
glPopMatrix();
glPushMatrix(); //daun2
glTranslatef(-8, 3.0, 0.5);
glColor3f(0.5, 1.0, 0.0);
glutSolidSphere(0.8, 20, 10);
glPopMatrix();
//batang
glPushMatrix();
glTranslatef( 8, 1.0, 0.5);
glRotatef(45.0, 0.0, 1.0, 0.0);
glScalef(1.0, 6.0, 1.0);
glColor3ub(139, 69, 19);
glutSolidCube(0.5);
glPopMatrix();
//daun
glPushMatrix(); //daun1
glTranslatef(8, 2.0, 0.5);
glColor3f(0.5, 1.0, 0.0);
glutSolidSphere(1.0, 20, 10);
glPopMatrix();
glPushMatrix(); //daun2
glTranslatef(8, 3.0, 0.5);
glColor3f(0.5, 1.0, 0.0);
glutSolidSphere(0.8, 20, 10);
glPopMatrix();
//batang
glPushMatrix();
glTranslatef( -6, 1.0, -2);
glRotatef(45.0, 0.0, 1.0, 0.0);
glScalef(1.0, 6.0, 1.0);
glColor3ub(139, 69, 19);
glutSolidCube(0.5);
glPopMatrix();
//daun
glPushMatrix(); //daun1
glTranslatef(-6, 2.0, -2);
glColor3f(0.5, 1.0, 0.0);
glutSolidSphere(1.0, 20, 10);
glPopMatrix();
glPushMatrix(); //daun2
glTranslatef(-6, 3.0, -2);
glColor3f(0.5, 1.0, 0.0);
glutSolidSphere(0.8, 20, 10);
glPopMatrix();
//batang
glPushMatrix();
glTranslatef( 6, 1.0, -2);
glRotatef(45.0, 0.0, 1.0, 0.0);
glScalef(1.0, 6.0, 1.0);
glColor3ub(139, 69, 19);
glutSolidCube(0.5);
glPopMatrix();
//daun
glPushMatrix(); //daun1
glTranslatef(6, 2.0, -2);
glColor3f(0.5, 1.0, 0.0);
glutSolidSphere(1.0, 20, 10);
glPopMatrix();
glPushMatrix(); //daun2
glTranslatef(6, 3.0, -2);
glColor3f(0.5, 1.0, 0.0);
glutSolidSphere(0.8, 20, 10);
glPopMatrix();
gunungNight();
rumah2an();
pagar();
tembok();
glEnable(GL_TEXTURE_2D);
load_BMP_texture
("logoipb.bmp");
glBegin(GL_POLYGON);
glTexCoord2f(0, 0); //pojok kiri bawah
glVertex3f(8,12, -10);
glTexCoord2f(1, 0); //pojok kiri aras
glVertex3f(8,10, -10);
glTexCoord2f(1, 1); //pojok kanan aras
glVertex3f(10, 10, -10);
glTexCoord2f(0, 1); //pojok kanan bawah
glVertex3f(10, 12, -10);
glEnd();
glDisable(GL_TEXTURE_2D);
glutSwapBuffers();
glFlush();
}
switch (key) {
case GLUT_KEY_LEFT :
cameraAngle -= 0.02;
rotateCamera(cameraAngle);
break;
case GLUT_KEY_RIGHT :
cameraAngle += 0.02;
rotateCamera(cameraAngle);
break;
case GLUT_KEY_UP :
moveCamera(1, 0);
break;
case GLUT_KEY_DOWN :
moveCamera(-1, 0);
break;
case GLUT_KEY_PAGE_UP :
moveCamera(0, 1);
break;
case GLUT_KEY_PAGE_DOWN :
moveCamera(0, -1);
break;
}
glutPostRedisplay();
}
void lighting()
{
// Light Properties
GLfloat light_ambient[] = {0.0, 0.0, 0.0, 1.0};
GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};
GLfloat mat_specular[] = {0.5, 0.5, 0.5, 1.0};
GLfloat mat_shininess[]= {30.0};
// Material Properties
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glColorMaterial(GL_FRONT,GL_DIFFUSE);
}
void init() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1,1,100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(x, y, z, x + lx, y + ly, z + lz, 0, 1, 0);
}
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("4611415011 Wisnu Alfarisi");
glutDisplayFunc(display);
glutSpecialFunc(pressKey);
glutTimerFunc(0,timer,0);
glutTimerFunc(0,waktu,0);
init();
lighting();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glutMainLoop();
return 0;
}