Anda di halaman 1dari 10

Nama : Oswald Tanlee Pongayow

NIM : 2004038

Kelas : 5TI2

Project 6

Program 1. Sebuah Lit Sphere.

Dibawah ini merupakan langkah-langkah yang diperlukan untuk menambahkan pencahayaan ke


obyek.

 Tentukan vektor normal untuk setiap sudut dari semua benda. Vektor normal ini
menentukan orientasi objek relatif terhadap sumber cahaya.
 Buat, pilih, dan atur posisi satu atau lebih dari sebuah sumber cahaya.
 Ciptakan dan pilih model pencahayaan, yang mendefinisikan tingkat cahaya lingkungan
global dan lokasi efektif dari sudut pandang (untuk keperluan perhitungan pencahayaan).
 Tentukan sifat-sifat material untuk objek-objek dalam adegan.

Program 1 sebelum di ubah.

GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };

GLfloat mat_shininess[] = { 50.0 };

GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };

Codingan glOrtho (mengubah posisi)

if (w <= h)

glOrtho (-6.5, 5.5, -6.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w, - 10.0, 10.0);

else

glOrtho (-6.5*(GLfloat)w/(GLfloat)h, 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);


Program 1 setelah diubah.

GLfloat mat_specular[] = { 56.0, 40.0, 40.0, 30.0 }; - pantulan

GLfloat mat_shininess[] = { 50.0 }; - silau

GLfloat light_position[] = { 12.0, 12.0, 5.0, 4.0 }; - posisi cahaya

Codingan glOrtho (mengubah posisi)

if (w <= h)

glOrtho (-6.5, 5.5, -6.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w, - 10.0, 10.0);

else

glOrtho (-6.5*(GLfloat)w/(GLfloat)h, 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);


Program 2 Objek Sphere

Codingan sebeleum diubah.

GLfloat light_diffuse[] ={1.0, 1.0, 0.0, 1.0};

GLfloat light_position[] ={1.0, 1.0, 1.0, 0.20}; GLUquadricObj *qobj;

Codingan setelah diubah.

GLfloat light_diffuse[] ={25.0, 1.0, 0.0, 1.0};


GLfloat light_position[] ={6.0, 4.0, 1.0, 0.20}; GLUquadricObj *qobj;

Program 3 Objek Kubus

1. Cobalah program diatas

2. Lakukan perubahan sintak atau nilai yang ada dalam program diatas

3. Masukan hasil pengamatan dan masukan hasilnya yang disertai gambar hasil compile dalam table

pengamatan yang disesuaikan dengan pengamatan anda. (dengan MS Office)

Codingan sebelum diubah.

GLfloat light_diffuse[] = {1.0, 1.0, 0.0, 1.0}; /* warna merah terang. */

GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};

Codingan sesudah diubah.


GLfloat light_diffuse[] = {11.0, 11.0, 0.0, 1.0}; /* warna kuning terang. */

GLfloat light_position[] = {15.0, 5.0, 1.0, -2.0};

4. Buatlah gambar donat dilengkapi dengan pencahayaan satu sumber

#include<stdlib.h>

#include<GL/glut.h>

GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 0.0}; /* warna merah terang. */

GLfloat light_position[] = {-4.0, 1.0, 1.0, 0.0};


float w=600,h=480;

float sudut=0,sx=0,sy=0,sz=0,dalam=10,luar=30,sides=1000,rings=50;

void torus(){

glColor3d(0,1,1);

glutWireTorus(dalam,luar,sides,rings);

void display(){

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity(); glTranslatef(0,0,-130);

glRotatef(sudut,sx,sy,sz);

torus();

glutSwapBuffers();

void resize(int w1, int h1){

glViewport(0,0,w1,h1);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(45.0, (float) w1/(float) h1, 1.0,300.0);

glMatrixMode(GL_MODELVIEW); glLoadIdentity();

void init(){

glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);

glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glEnable(GL_LIGHT0);

glEnable(GL_LIGHTING);

glEnable(GL_DEPTH_TEST);

glClearColor(0.0,0.0,0.0,1.0);

glEnable(GL_DEPTH_TEST);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(45.,(GLdouble)w/(GLdouble)h,1.0,300.);
glMatrixMode(GL_MODELVIEW);

void myKeyboard(unsigned char key, int x, int y){

if(key=='x'){

sx=1;

sy=0;

sz=0;

sudut+=10;

else if(key=='y'){

sx=0;

sy=1;

sz=0;

sudut+=10;

else if(key=='z'){

sx=0;

sy=0;

sz=1;

sudut+=10;

}}

void update(int value){

glutPostRedisplay();

glutTimerFunc(50,update,0);

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

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA);

glutInitWindowPosition(100,100);

glutInitWindowSize(w,h);

glutCreateWindow("donat 3D dengan pencahayaan");


glutDisplayFunc(display);

glutReshapeFunc(resize);

init();

glutTimerFunc(50,update,0);

glutKeyboardFunc(myKeyboard);

glutMainLoop();

5. Buatlah program gambar cone dilengkapi dengan pencahayaan satu sumber

#include <windows.h>
#include<stdlib.h>
#include<GL/glut.h>
GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0}; /* warna merah. */
GLfloat light_position[] = {1.0, 32.0, 1.0, 0.0};
float w=480,h=480;
float sudut=0,sx=0,sy=0,sz=0,zz=-70;
int t=20;
void WireCone(){
glColor3d(0,1,1);
glutSolidCone(20,t,50,50);
}
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0,0,zz);
glRotatef(sudut,sx,sy,sz);
WireCone();
glutSwapBuffers();
}
void resize(int w1, int h1){
glViewport(0,0,w1,h1);glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (float) w1/(float) h1, 1.0,300.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void init(){
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glClearColor(0.0,0.0,0.0,1.0);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.,(GLdouble)w/(GLdouble)h,1.,300.);
glMatrixMode(GL_MODELVIEW);
}
void myKeyboard(unsigned char key, int x, int y){
if(key=='x'){
sx=1;
sy=0;
sz=0;
sudut+=10;
}
else if(key=='y'){
sx=0;
sy=1; sz=0;
sudut+=10;
}
else if(key=='z'){
sx=0;
sy=0;
sz=1;
}
}
void update(int value){
glutPostRedisplay();
glutTimerFunc(50,update,0);
}
int main(int argc, char **argv){
glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH |
GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(w,h);
glutCreateWindow("Objek 3D");
glutDisplayFunc(display);
glutReshapeFunc(resize);
init();
glutTimerFunc(50,update,0);
glutKeyboardFunc(myKeyboard);
glutMainLoop();
}

Anda mungkin juga menyukai