Laporan Tugas Grafika Komputer bangun 2 dimensi Code Block
Click here to load reader
-
Upload
ihsan-nurhalim -
Category
Documents
-
view
3.224 -
download
15
Transcript of Laporan Tugas Grafika Komputer bangun 2 dimensi Code Block
BAB I
PENDAHULUAN
Grafik komputer adalah bagian dari ilmu komputer yang berkaitan dengan
pembuatan dan manipulasi gambar (visual) secara digital. Bentuk sederhana dari
grafik komputer adalah grafik komputer 2D yang kemudian berkembang menjadi
grafik komputer 3D, pemrosesan citra (image processing), dan pengenalan pola
(pattern recognition). Dan di era globalisasi saat ini, grafik komputer merupakan
bagian ilmu teknologi yang sangat berkembang. Salah satunya contohnya banyak
industri film, yang sudah menggunakan grafik komputer tersebut untuk
menghasilkan film-film 3D sangat mudah dan cepat dan memanjakan mata anda
yang sedang menyaksikan film-film tersebut.
Aplikasi grafika komputer dapar dibagi mejadi beberapa kelompok, yaitu :
Aplikasi pengolah bentuk dan citra
Aplikasi Pengolah bentuk dan Citra merupakan aplikasi yang banyak
digunakan oleh Desaigner grafis dan ilustrator.
Aplikasi pengolah bentuk
Aplikasi pengoleh Bentuk ditujukan untuk mengolah bentuk (Shape) yang
disusun dari serangkaian garis sedangkan Aplikasi pengolah Citra ditujukan
untuk memanipulasi sekumpulan titik yang membentuk sebuah gambar
(Citra).
Aplikasi presentasi
Aplikasi presentasi banyak digunakan oleh kalangan bisnis dalam
mempresentasikan ide-ide ataupun konsep-konsep. Dalam perkembangannya,
aplikasi presentasi tidak hanya sekedar menampilkan slide ke layar tetapi juga
dilengkapi dengan fasilitas animasi. (contoh aplikasi presentasi antara lain :
Power point, Marcomedia Flash)
Aplikasi CAD
Aplikasi CAD banyak digunkan dalam bidang Teknik. Dengan menggunakan
CAD seorang perancang teknik tidak lagi menggunakan meja gambar dan
kertas tetapi mengunakan komputer sebagai media. Contoh Aplikasi CAD .
Contoh aplikasi CAD antara lain AutoCad untuk aplikasi teknik/rekayasa
1 | Grafika Komputer
bangunan/mesin,Protel untuk aplikasi rekyasa elektronik Home Designer untuk
aplikasi design anterior dan NuGraf untuk aplikasi pemodelan benda tiga
dimensi.
Animasi
Aplikasi animasi merupakan aplikasi yang banyak digunakan dalam bidang
periklanan dan Film. Dengan mengunakan aplikasi animasi, seorang kreator
dapat menciptakan benda-benda maya yang dapat bergerak dalam dunia nyata.
Contoh aplikasi animasi antara lain Autodesk 3D Studio, Extreme 3D,
Animator Pro, Ray Dream Studio. Representas Data Representasi data
merupakan salah satu cara melihat data dalam bentuk yang lebih mudah
diamati. Aplikasi representasi data banyak digunakan dalam bidang analisa
statistik dan geografi. Contoh apliasi untuk merepresentasikan data geografis
antara lain ArcInfor, MapInfo.
Permainan
Saat ini hampir tidak ada aplikasi permainan komputer yang tidak
memanfaatkan modus grafik. Aplikasi permainan antara lain aplikasi tembak
dan lari (Shoot and run), Aplikasi permainan strategi (war games), dll.
2 | Grafika Komputer
BAB IIPEMBAHASAN
#include <windows.h>#include <glut.h>#include "tutorial14.h"#include "texture.h"#include "3dsloader.h"
// The width and height of your window, change them as you likeint screen_width=640;int screen_height=480;
// Absolute rotation values (0-359 degrees) and rotation increments for each framedouble rotation_x=0, rotation_x_increment=0.05;double rotation_y=0, rotation_y_increment=0.03;double rotation_z=0, rotation_z_increment=0.05;
// Flag for rendering as lines or filled polygonsint filling=1; //0=OFF 1=ON
//Now the object is generic, the cube has annoyed us a little bit, or not?obj_type object;
void init(void){
glClearColor(1.0, 0.1, 0.0, 0.0); // This clear the background color to black
glShadeModel(GL_SMOOTH); // Type of shading for the polygons
// Viewport transformationglViewport(0,0,screen_width,screen_height);
// Projection transformationglMatrixMode(GL_PROJECTION); // Specifies which matrix stack
is the target for matrix operationsglLoadIdentity(); // We initialize the projection matrix as
identity
gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,10.0f, 10000.0f); // We define the "viewing volume"
glEnable(GL_DEPTH_TEST); // We enable the depth test (also called z buffer)
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); // Polygon rasterization mode (polygon filled)
glEnable(GL_TEXTURE_2D); // This Enable the Texture mappingLoad3DS (&object,"test7.3ds");object.id_texture=LoadBitmap("ksc_inside.bmp"); // The
Function LoadBitmap() return the current texture ID
// If the last function returns -1 it means the file was not found so we exit from the program
3 | Grafika Komputer
if (object.id_texture==-1){
MessageBox(NULL,"Image file: ksc_inside.bmp not found", "Zetadeck",MB_OK | MB_ICONERROR);
exit (0);}
}void resize (int width, int height){
screen_width=width; // We obtain the new screen width values and store it
screen_height=height; // Height value
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // We clear both the color and the depth buffer so to draw the next frame
glViewport(0,0,screen_width,screen_height); // Viewport transformation
glMatrixMode(GL_PROJECTION); // Projection transformationglLoadIdentity(); // We initialize the projection matrix as
identity
gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,10.0f, 10000.0f);
glutPostRedisplay (); // This command redraw the scene (it calls the same routine of glutDisplayFunc)}void keyboard (unsigned char key, int x, int y){
switch (key){
case ' ':rotation_x_increment=1;rotation_y_increment=0;rotation_z_increment=1;
break;case 'r': case 'R':
if (filling==0){
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); // Polygon rasterization mode (polygon filled)
filling=1;}else{
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); // Polygon rasterization mode (polygon outlined)
filling=0;}
break;}
}void keyboard_s (int key, int x, int y){
switch (key){
4 | Grafika Komputer
case GLUT_KEY_UP:rotation_x_increment = rotation_x_increment
+0.010;break;case GLUT_KEY_DOWN:
rotation_x_increment = rotation_x_increment -0.010;
break;case GLUT_KEY_LEFT:
rotation_y_increment = rotation_y_increment +0.010;
break;case GLUT_KEY_RIGHT:
rotation_y_increment = rotation_y_increment -0.010;
break;}
}void display(void){
int l_index;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW); // Modeling transformationglLoadIdentity(); // Initialize the model matrix as identity
glTranslatef(0.0,0.0,-50); // We move the object forward (the model matrix is multiplied by the translation matrix)
rotation_x = rotation_x + rotation_x_increment;rotation_y = rotation_y + rotation_y_increment;rotation_z = rotation_z + rotation_z_increment;
if (rotation_x > 359) rotation_x = 0;if (rotation_y > 359) rotation_y = 0;if (rotation_z > 359) rotation_z = 0;
glRotatef(rotation_x,1.0,0.0,0.0); // Rotations of the object (the model matrix is multiplied by the rotation matrices)
glRotatef(rotation_y,0.0,1.0,0.0);glRotatef(rotation_z,0.0,0.0,1.0);
glBindTexture(GL_TEXTURE_2D, object.id_texture); // We set the active texture
glBegin(GL_TRIANGLES); // glBegin and glEnd delimit the vertices that define a primitive (in our case triangles)
for (l_index=0;l_index<object.polygons_qty;l_index++){
//----------------- FIRST VERTEX -----------------// Texture coordinates of the first vertex
glTexCoord2f( object.mapcoord[ object.polygon[l_index].a ].u,
object.mapcoord[ object.polygon[l_index].a ].v);
// Coordinates of the first vertex
5 | Grafika Komputer
glVertex3f( object.vertex[ object.polygon[l_index].a ].x,
object.vertex[ object.polygon[l_index].a ].y,
object.vertex[ object.polygon[l_index].a ].z);//Vertex definition
//----------------- SECOND VERTEX -----------------// Texture coordinates of the second vertex
glTexCoord2f( object.mapcoord[ object.polygon[l_index].b ].u,
object.mapcoord[ object.polygon[l_index].b ].v);// Coordinates of the second vertex
glVertex3f( object.vertex[ object.polygon[l_index].b ].x,
object.vertex[ object.polygon[l_index].b ].y,
object.vertex[ object.polygon[l_index].b ].z);
//----------------- THIRD VERTEX -----------------// Texture coordinates of the third vertex
glTexCoord2f( object.mapcoord[ object.polygon[l_index].c ].u,
object.mapcoord[ object.polygon[l_index].c ].v);
// Coordinates of the Third vertex
glVertex3f( object.vertex[ object.polygon[l_index].c ].x,
object.vertex[ object.polygon[l_index].c ].y,
object.vertex[ object.polygon[l_index].c ].z);}glEnd();glFlush(); // This force the execution of OpenGL commandsglutSwapBuffers(); // In double buffered mode we invert the
positions of the visible buffer and the writing buffer}
int main(int argc, char **argv){
glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(screen_width,screen_height);glutInitWindowPosition(0,0);glutCreateWindow("CREATED BY : Doni Nuriksa A.M (1006037)");glutDisplayFunc(display);glutIdleFunc(display);glutReshapeFunc (resize);glutKeyboardFunc (keyboard);glutSpecialFunc (keyboard_s);
6 | Grafika Komputer
init();glutMainLoop();
return(0);}
Hasil Output :
7 | Grafika Komputer