0% found this document useful (0 votes)
23 views16 pages

LAPO

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views16 pages

LAPO

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

LAPORAN PRAKTIKUM

MATA KULIAH GRAFIKA KOMPUTER


(Project Akhir)
Semester Gasal 2017/2018

Oleh:
Wisnu Alfarisi 4611415011

Dosen Pengampu:
Aji Purwinarko S.Si., M.Cs.

PROGRAM STUDI TEKNIK INFORMATIKA


JURUSAN ILMU KOMPUTER
FAKULTAS MATEMATIKA DAN ILMU PENGETAHUAN ALAM
UNIVERSITAS NEGERI SEMARANG
2017
I. Deksripsi Project
Project yang saya buat adalah Rumah dan Alam. Terdapat rumah dan pagar, pohon,
awan yang bergerak, bulan dan 3 bergerak.
:
- Panah Bawah : Menggerakkan view camera kebelakang
- Panah Atas : Menggerakkan view camera kedepan
- panah kiri : Menggerakkan view camera ke kiri dan rotasi kekiri
- panah kanan : Menggerakkan view camera ke kanan dan rotasi kekanan

II. Fungsi yang digunakan (penjelasan fungsi yang digunakan)

- Fungsi pada header


#include <GL/glu.h>, #include <GL/gl.h>, #include <GL/glut.h> :
digunakan untuk import library yang digunakan.
#include <math.h> :
untuk menampilkan perintah dari fungsi matematis.
#include <stdlib.h> , #include <stdio.h> :
cstdlib (C Standard General Utilities Library) Header yang berisi fungsi-fungsi
umum termasuk manajemen pengelolaan memori, pembuatan angka acak,
berkomunikasi dengan environment, aritmatika, pencarian, pengurutan, dan konversi.
#include <stdio.h>
#include "glm.h"
#include <windows.h>

#include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include "glm.h"

int xRot = 0, yRot = 0;

char kata1[] = {"Gunakan tombol panah untuk menggerakkan kanan, kiri,


atas, bawah"};

GLMmodel* model1 = NULL;

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();

float speed = 0.0,cepat=0.0;


void timer(int){
float i=20;
if(speed<i && cepat <i){
speed = speed + 0.01;
cepat = cepat + 0.009;}
else {speed=0;cepat=0;}
glutPostRedisplay();
glutTimerFunc(9, timer, 0);
}

float cameraAngle = 0.0;


float x = 0, y = 3, z = 20; // default camera position
float lx = 0, ly = 0, lz = -1;
void rotateCamera(float ang) {
// rotate the camera (left / right)
lx = sin(ang);
lz = -cos(ang);
glLoadIdentity();
gluLookAt(x, y, z, x + lx, y + ly, z + lz, 0, 1, 0);
}

void moveCamera(int h_direction, int v_direction) {


// move the camera (forward, backward, up, down)
x = x + h_direction*(lx)*0.3;
z = z + h_direction*(lz)*0.3;
y = y + v_direction*0.1;
glLoadIdentity();
gluLookAt(x, y, z, x + lx, y + ly, z + lz, 0, 1, 0);
}

void grid_floor(int baris, int kolom) {


// draw grid on floor (0,0,0)
int i;

int kiri = -kolom / 2;


int kanan = kolom / 2;
int bawah = -baris / 2;
int atas = baris / 2;

glBegin(GL_LINES);
glLineWidth(1);

for (i = 0; i < baris + 1; i++) {


glVertex3f(kiri, 0, baris / 2 - i);
glVertex3f(kanan, 0, baris / 2 - i);
}

for (i = 0; i < kolom + 1; i++) {


glVertex3f(kolom / 2 - i, 0, bawah);
glVertex3f(kolom / 2 - i, 0, atas);
}

glEnd();
}

float kecepatan;
void waktu(int ) //harus integer
{
// Timer code here
kecepatan ++;

//refresh tampilan
glutPostRedisplay();

//set timer dg jeda 10 milidetik


glutTimerFunc(10,waktu,0); //call back function tapi menggunakan
jeda skaligus mengirimkan parameter interger
}

//gunung malam hari


void gunungNight()
{
glColor3f(0.60,0.40,0.12);
glBegin(GL_TRIANGLES);
glVertex3d(-9,0,10);
glColor3f(0.10,0.10,0.0);
glVertex3d(-6,7,10);
glColor3f(0.10,0.10,0.0);
glVertex3d(0,0,10);
glEnd();

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();
}

void load_BMP_texture(char *filename) { //filename berupa string

FILE *file;
short int bpp;
short int planes;
long size;
unsigned int texture;

long imwidth;
long imheight;
char *imdata;

file = fopen(filename, "rb");


fseek(file, 18, SEEK_CUR);

fread(&imwidth, 4, 1, file);
fread(&imheight, 4, 1, file);
size = imwidth * imheight * 3;

fread(&bpp, 2, 1, file);
fread(&planes, 2, 1, file);

fseek(file, 24, SEEK_CUR);


imdata = (char *)malloc(size);

fread(imdata, size, 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);

glGenTextures(1, &texture); //untuk menampilkan textures


glBindTexture(GL_TEXTURE_2D, texture); // now we bind the texture
that we are working with

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imwidth, imheight, 0,


GL_RGB, GL_UNSIGNED_BYTE, imdata);

free(imdata); // free the texture


}

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 cetak() //cetak tulisan


{
glColor3f(1.0,1.0,0.0);
glRasterPos3d(5,9,0);
for(int r=0;kata1[r]!='\0';r++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,kata1[r]);
}

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();
}

void pressKey(int key, int x, int y) {

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};

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);


glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

// Material Properties
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

// Enable Various Components


glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);

glColorMaterial(GL_FRONT,GL_DIFFUSE);
}

void init() {

glClearColor(0.0, 0.0, 0.0, 0.0);

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);
}

int main(int argc, char * * argv) {


glutInit( & argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);

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;
}

You might also like