Grafika Computer
Selasa, 04 Desember 2012
Membuat Rumah 3D
//by wendel H selsily (672011094)
#include <gl\gl.h>
#include <gl\glut.h>
#include <gl\glu.h> /* GLU extention library */
void init(void);
void display(void);
void keyboard(unsigned char, int, int);
void resize(int, int);
int is_depth; /* depth testing flag */
int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(40, 40);
glutCreateWindow("Rumah 3D Berwarna");
init();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(resize);
glutMainLoop();
return 0;
}
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
is_depth = 1;
glMatrixMode(GL_MODELVIEW);
glPointSize(9.0);
glLineWidth(6.0f);
}
void display(void)
{
if (is_depth)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
else
glClear(GL_COLOR_BUFFER_BIT);
//ini untuk buat lantainya
glBegin(GL_QUADS);
glColor3f(0.2f, 0.2f, 0.2f);
glVertex3f(-100.0, 0.0, -100.0);
glColor3f(0.4f, 0.4f, 0.4f);
glVertex3f(-100.0, 0.0, 100.0);
glColor3f(0.6f, 0.6f, 0.6f);
glVertex3f(100.0, 0.0, 100.0);
glColor3f(0.8f, 0.8f, 0.8f);
glVertex3f(100.0, 0.0, -100.0);
glEnd();
glBegin(GL_QUADS);//depan rumah
glColor3f(0.0f, 1.0f, 1.0f);
glVertex3f(-50.0, 0.0, 100.0);
glVertex3f(-50.0, 50.0, 100.0);
glVertex3f(50.0, 50.0, 100.0);
glVertex3f(50.0, 0.0, 100.0);
glEnd();
glBegin(GL_QUADS);//garis depan rumah`
glColor3f(0.0f, 1.0f, 1.0f);
glVertex3f(-50.0, 0.0, 100.1);
glVertex3f(-50.0, 50.0, 100.1);
glVertex3f(50.0, 50.0, 100.1);
glVertex3f(50.0, 0.0, 100.1);
glEnd();
glBegin(GL_QUADS);// pintu rumah
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-15.1, 0.0, 100.5);
glVertex3f(-15.1, 40.0, 100.5);
glVertex3f(15.1, 40.0, 100.5);
glVertex3f(15.1, 0.0, 100.5);
glEnd();
glBegin(GL_LINE_LOOP);//garis pintu rumah
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-15.1, 0.0, 100.6);
glVertex3f(-15.1, 40.0, 100.6);
glVertex3f(15.1, 40.0, 100.6);
glVertex3f(15.1, 0.0, 100.6);
glEnd();
glBegin(GL_POINTS);// tangan pintu
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-13.0, 20.0, 100.8);
glEnd();
glBegin(GL_TRIANGLES);//atap depan rumah
glColor3f(1.0f,0.6f,0.0f);
glVertex3f(0.0, 100.0, 100.0);
glVertex3f(50.0, 50.0, 100.0);
glVertex3f(-50.0, 50.0, 100.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis atap depan rumah
glColor3f(0.0f,0.0f,0.0f);
glVertex3f(0.0, 100.0, 100.0);
glVertex3f(50.0, 50.0, 100.0);
glVertex3f(-50.0, 50.0, 100.0);
glEnd();
glBegin(GL_QUADS);//samping kiri
glColor3f(0.0f, 1.0f, 1.0f);
glVertex3f(-50.0, 0.0, 100.0);
glVertex3f(-50.0, 50.0, 100.0);
glVertex3f(-50.0, 50.0, -100.0);
glVertex3f(-50.0, 0.0, -100.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis samping kiri
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-50.0, 0.0, 100.0);
glVertex3f(-50.0, 50.0, 100.0);
glVertex3f(-50.0, 50.0, -100.0);
glVertex3f(-50.0, 0.0, -100.0);
glEnd();
glBegin(GL_QUADS);//jendela samping kiri (kiri atas)
glColor3f(0.7f,0.7f,0.7f);
glVertex3f(-51.1, 25.0, 0.0);
glVertex3f(-51.1, 40.0, 0.0);
glVertex3f(-51.1, 40.0, -50.0);
glVertex3f(-51.1, 25.0, -50.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis jendela samping kiri (kiri atas)
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-51.1, 25.0, 0.0);
glVertex3f(-51.1, 40.0, 0.0);
glVertex3f(-51.1, 40.0, -50.0);
glVertex3f(-51.1, 25.0, -50.0);
glEnd();
glBegin(GL_QUADS);//jendela samping kiri (kiri bawah)
glColor3f(1.0f, 0.0f, 1.0f);
glVertex3f(-51.1, 10.0, 0.0);
glVertex3f(-51.1, 25.0, 0.0);
glVertex3f(-51.1, 25.0, -50.0);
glVertex3f(-51.1, 10.0, -50.0);
glEnd();
glBegin(GL_QUADS);//garis jendela samping kiri (kiri bawah)
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-51.1, 10.0, 0.0);
glVertex3f(-51.1, 25.0, 0.0);
glVertex3f(-51.1, 25.0, -50.0);
glVertex3f(-51.1, 10.0, -50.0);
glEnd();
glBegin(GL_QUADS);//jendela samping kiri (kanan bawah)
glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f(-51.1, 10.0, 50.0);
glVertex3f(-51.1, 25.0, 50.0);
glVertex3f(-51.1, 25.0, -50.0);
glVertex3f(-51.1, 10.0, -50.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis jendela samping kiri (kanan bawah)
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-51.1, 10.0, 50.0);
glVertex3f(-51.1, 25.0, 50.0);
glVertex3f(-51.1, 25.0, -50.0);
glVertex3f(-51.1, 10.0, -50.0);
glEnd();
glBegin(GL_QUADS);//jendela samping kiri (kanan atas)
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-51.1, 25.0, 0.0);
glVertex3f(-51.1, 40.0, 0.0);
glVertex3f(-51.1, 40.0, 50.0);
glVertex3f(-51.1, 25.0, 50.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis jendela samping kiri (kanan atas)
glColor3f(0.0f,0.0f,0.0f);
glVertex3f(-51.1, 25.0, 0.0);
glVertex3f(-51.1, 40.0, 0.0);
glVertex3f(-51.1, 40.0, 50.0);
glVertex3f(-51.1, 25.0, 50.0);
glEnd();
glBegin(GL_QUADS);//atap samping kiri
glColor3f(1.0f,0.4f,0.0f);
glVertex3f(-50.0, 50.0, -100.0);
glVertex3f(0.0, 100.0, -100.0);
glVertex3f(0.0, 100.0, 100.0);
glVertex3f(-50.0, 50.0, 100.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis atap samping kiri
glColor3f(0.0f,0.0f,0.0f);
glVertex3f(-50.0, 50.0, -100.0);
glVertex3f(0.0, 100.0, -100.0);
glVertex3f(0.0, 100.0, 100.0);
glVertex3f(-50.0, 50.0, 100.0);
glEnd();
glBegin(GL_QUADS);//samping kanan
glColor3f(0.0f, 1.0f, 1.0f);
glVertex3f(50.0, 0.0, 100.0);
glVertex3f(50.0, 50.0, 100.0);
glVertex3f(50.0, 50.0, -100.0);
glVertex3f(50.0, 0.0, -100.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis samping kanan
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(50.0, 0.0, 100.0);
glVertex3f(50.0, 50.0, 100.0);
glVertex3f(50.0, 50.0, -100.0);
glVertex3f(50.0, 0.0, -100.0);
glEnd();
glBegin(GL_QUADS);//jendela samping kanan (kanan atas)
glColor3f(0.7f,0.7f,0.7f);
glVertex3f(51.1, 25.0, 0.0);
glVertex3f(51.1, 40.0, 0.0);
glVertex3f(51.1, 40.0, -50.0);
glVertex3f(51.1, 25.0, -50.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis jendela samping kanan (kanan atas)
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(51.1, 25.0, 0.0);
glVertex3f(51.1, 40.0, 0.0);
glVertex3f(51.1, 40.0, -50.0);
glVertex3f(51.1, 25.0, -50.0);
glEnd();
glBegin(GL_QUADS);//jendela samping kanan (kanan bawah)
glColor3f(1.0f, 0.0f, 1.0f);
glVertex3f(51.1, 10.0, 0.0);
glVertex3f(51.1, 25.0, 0.0);
glVertex3f(51.1, 25.0, -50.0);
glVertex3f(51.1, 10.0, -50.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis jendela samping kanan (kanan bawah)
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(51.1, 10.0, 0.0);
glVertex3f(51.1, 25.0, 0.0);
glVertex3f(51.1, 25.0, -50.0);
glVertex3f(51.1, 10.0, -50.0);
glEnd();
glBegin(GL_QUADS);//jendela samping kiri (kiri bawah)
glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f(51.1, 10.0, 50.0);
glVertex3f(51.1, 25.0, 50.0);
glVertex3f(51.1, 25.0, -50.0);
glVertex3f(51.1, 10.0, -50.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis jendela samping kiri (kiri bawah)
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(51.1, 10.0, 50.0);
glVertex3f(51.1, 25.0, 50.0);
glVertex3f(51.1, 25.0, -50.0);
glVertex3f(51.1, 10.0, -50.0);
glEnd();
glBegin(GL_QUADS);//jendela samping kiri (kiri atas)
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(51.1, 25.0, 0.0);
glVertex3f(51.1, 40.0, 0.0);
glVertex3f(51.1, 40.0, 50.0);
glVertex3f(51.1, 25.0, 50.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis jendela samping kiri (kiri atas)
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(51.1, 25.0, 0.0);
glVertex3f(51.1, 40.0, 0.0);
glVertex3f(51.1, 40.0, 50.0);
glVertex3f(51.1, 25.0, 50.0);
glEnd();
glBegin(GL_QUADS);//atap samping kanan
glColor3f(1.0f,0.4f,0.0f);
glVertex3f(50.0, 50.0, 100.0);
glVertex3f(0.0, 100.0, 100.0);
glVertex3f(0.0, 100.0, -100.0);
glVertex3f(50.0, 50.0, -100.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis atap samping kanan
glColor3f(0.0f,0.0f,0.0f);
glVertex3f(50.0, 50.0, 100.0);
glVertex3f(0.0, 100.0, 100.0);
glVertex3f(0.0, 100.0, -100.0);
glVertex3f(50.0, 50.0, -100.0);
glEnd();
glBegin(GL_QUADS);//belakang
glColor3f(0.0f, 1.0f, 1.0f);
glVertex3f(-50.0, 0.0, -100.0);
glVertex3f(-50.0, 50.0, -100.0);
glVertex3f(50.0, 50.0, -100.0);
glVertex3f(50.0, 0.0, -100.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis belakang
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-50.0, 0.0, -100.0);
glVertex3f(-50.0, 50.0, -100.0);
glVertex3f(50.0, 50.0, -100.0);
glVertex3f(50.0, 0.0, -100.0);
glEnd();
glBegin(GL_TRIANGLES);//atap belakang
glColor3f(1.0f,0.6f,0.0f);
glVertex3f(0.0, 100.0, -100.0);
glVertex3f(-50.0, 50.0, -100.0);
glVertex3f(50.0, 50.0, -100.0);
glEnd();
glBegin(GL_LINE_LOOP);//garis atap belakang
glColor3f(0.0f,0.0f,0.0f);
glVertex3f(0.0, 100.0, -100.0);
glVertex3f(-50.0, 50.0, -100.0);
glVertex3f(50.0, 50.0, -100.0);
glEnd();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
/* Untuk kontrol dengan keyboard:
"a": ke kiri
"d": ke kanan
"w": ke depan
"s": ke belakang
"t": toggle depth-testing
"u" : ke atas
"n" : ke bawah
"i" : putar ke bawah terhadap sumbu X
"j" : putar ke atas terhadap sumbu X
"o" : putar ke kiri terhadap sumbu Y
"k" : putar ke kanan terhadap sumbu Y
"p" : putar ke kiri terhadap sumbu Z
"l" : putar ke kanan terhadap sumbu Z
*/
switch (key)
{
case 'a':
case 'A':
glTranslatef(5.0, 0.0, 0.0);
break;
case 'd':
case 'D':
glTranslatef(-5.0, 0.0, 0.0);
break;
case 'u' :
case 'U' :
glTranslatef(0.0,5.0,0.0);
break;
case 'n' :
case 'N' :
glTranslatef(0.0,-5.0, 0.0);
break;
case 'w':
case 'W':
glTranslatef(0.0, 0.0, 5.0);
break;
case 's':
case 'S':
glTranslatef(0.0, 0.0, -5.0);
break;
case 'i':
case 'I':
glRotatef(3.0,1.0,0.0,0.0);
break;
case 'j':
case 'J':
glRotatef(-3.0,1.0,0.0,0.0);
break;
case 'o':
case 'O':
glRotatef(3.0,0.0,1.0,0.0);
break;
case 'k':
case 'K':
glRotatef(-3.0,0.0,1.0,0.0);
break;
case 'p':
case 'P':
glRotatef(3.0,0.0,0.0,1.0);
break;
case 'l':
case 'L':
glRotatef(-3.0,0.0,0.0,1.0);
break;
case 't':
case 'T':
if (is_depth)
{
is_depth = 0;
glDisable(GL_DEPTH_TEST);
}
else
{
is_depth = 1;
glEnable(GL_DEPTH_TEST);
}
}
display();
}
void resize(int width, int height)
{
if (height == 0) height = 1;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, width / height, 1.0, 400.0);
/* Inisialisasi posisi */
glTranslatef(0.0, -5.0, -150.0);
glMatrixMode(GL_MODELVIEW);
}
ini adalah tombol Untuk kontrol posisi Rumah di atas dengan menggunakan keyboard :
"a": ke kiri
"d": ke kanan
"w": ke depan
"s": ke belakang
"t": toggle depth-testing
"u" : ke atas
"n" : ke bawah
"i" : putar ke bawah terhadap sumbu X
"j" : putar ke atas terhadap sumbu X
"o" : putar ke kiri terhadap sumbu Y
"k" : putar ke kanan terhadap sumbu Y
"p" : putar ke kiri terhadap sumbu Z
"l" : putar ke kanan terhadap sumbu Z
silahkan download coding dan project jadinya klik di sini
Cara Membuat 2 Garis dengan Titik Potong
#include <windows.h>
#include <gl/GL.h>
#include <gl/glut.h>
#include <stdio.h>
// pendefinisian variabel
int g=0,j=0,a,b,c,d,e,f,;
static float m1,c1,x;
static float m2,c2,y;
static float ax,cx;
static float ay,cy;
static float bx,dx;
static float by,dy;
void drawLine(int x,int y);
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0, 0.0, 0.0);
glPointSize(8.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void grad()
{
//mencetak gradien warna background
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 0.0);
glVertex2i(0, 0);
glColor3f(0.0, 1.0, 1.0);
glVertex2i(640, 0);
glColor3f(0.0, 1.0, 0.0);
glVertex2i(640, 480);
glColor3f(1.0, 0.0, 0.0);
glVertex2i(0, 480);
glEnd();
}
//rumus
void potong()
{
glColor3f(0,0,0);
glBegin(GL_LINES);
glVertex2f(ax,ay);
glVertex2f(bx,by);
glVertex2f(cx,cy);
glVertex2f(dx,dy);
glEnd();
glutSwapBuffers();
//persamaan 1
m1=((by-ay)/(bx-ax));
c1=ay-(m1*ax);
////persamaan 2
m2=((dy-cy)/(dx-cx));
c2=cy-(m2*cx);
//rumus utama
x=((c2-c1)/(m1-m2));
y=(m1*x)+c1;
a=x;
b=y;
glBegin(GL_POINTS);
glColor3f(1.0, 1.0, 0.0);
glVertex2i(a,b);
glEnd();
glutSwapBuffers();
}
void drawDot()
{
glBegin(GL_POINTS);
glColor3f(1.0, .0, 0.0);
glVertex2i(a, b);
glEnd();
glutSwapBuffers();
}
void drawLine(int x,int y)
{
grad();
if(g==1) {
ax=x;
ay=480-y;
bx=c;
by=d;
glClear(GL_COLOR_BUFFER_BIT);
grad();
glBegin(GL_LINE_STRIP);
glColor3f(0.0, 0.0, 0.0);
glVertex2i(c, d);
glVertex2i(x, 480-y);
glEnd();
glutSwapBuffers();
}
if(g>=2) {
dx=x;
dy=480-y;
cx=d;
cy=e;
potong();
drawDot();
glBegin(GL_LINE_STRIP);
glColor3f(0.0, 1.0, 0.0);
glVertex2i(d, e);
glVertex2i(x, 480-y);
glEnd();
glFlush();
}
}
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
grad();
d=x;
e=480-y;
g+=1;
if(g==1)
{
c=x;
d=480-y;
}
if(g==2) {
g=0;
}
}
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP)
{
g+=1;
grad();
}
else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
exit(-1);
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
grad();
glutSwapBuffers();
}
main(int argc, char**argv)
{
glutInit(&argc,argv);// inisialisasi toolkit
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);// set modus display
glutInitWindowSize(640,480);// set ukuran window
glutInitWindowPosition(100,150);// set posisi window di layar
glutCreateWindow("titikpotong_672011094");// buka screen window
glutDisplayFunc(myDisplay);// registrasi fungsi menggambar
glutMotionFunc(drawLine);//memanggil fungsi garis
glutMouseFunc(mouse);//memanggil fungsi mouse
myInit();
glutMainLoop();// berulang terus-menerus
}
silahkan download projectnya disini
Membuat Bentuk Obat Nyamuk persegi 6 (spiral hexagon) di OpenGL
#include <gl/Gl.h>
#include <gl/glut.h>
#include <math.h>
void obat(){
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINE_STRIP);
glColor3f(0.0, 0.0, 1.0);
double angle , angleInc, cx, cy, radius, rotAngle;
int n=6;
rotAngle=0;
if(n < 3) return;
angle = rotAngle* 3.14159265/180;
angleInc= 2 * 3.14159265/n;
for(int i = 0; i < 10; i++){
for(int j = 0; j < n; j++){
angle += angleInc;
glVertex2f((radius+i) * cos(angle) + cx, (radius+i) * sin(angle) + cy);
}
}
glEnd();
glFlush();
}
main(int argc, char *argv[]){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutCreateWindow("Obat Nyamuk");
glutDisplayFunc(obat);
glClearColor(1.0,1.0,1.0,0.0);
glPointSize(4.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10.0,10.0,-11.0,11.0);
glViewport(40, 400, 60, 300);
glutMainLoop();
}
silah kan download codingnya disini
Kamis, 29 November 2012
Cara Membuat Kubus 3D Bergerak
Hallo nama saya wendel ,,, Kali ini
saya mau share bagaimana cara membuat Kubus 3D Bergerak + ada foto di setiap
sisi sisinya..
Ini adalah Output Programnya :
Lagkah – Langkah Untuk membuat objek
Seperti output program di atas adalah …
1.buat satu folder baru dan beri
nama terserah anda, juga Sediakan Foto / Gambar yg ingin anda tempel pada
setiap sisi kubus format file foto/gambarnya harus “.bmp ” .foto/gambarnya di
copy ke dalam folder yang anda buat tadi..
2. download 3 file yg sudah
saya sediakan disini extract file tersebut pada
folder yg sudah anda buat tadi, satu folder dengan foto/gambar yg sudah anda
sediakan.
3. buka Dev C++, buat project baru
dengan memakai libary Open GL Pilih “multimedia” dan klik “glut”.
OK…… untuk nama projectnya terserah anda…dan simpan projectnya di folder yg
sudah anda buat tadi.
4. kemudian perhatikan pada
main.cpp. klik kanan pada file main.cpp tersebut klik “close” dan jangan di
simpan… pilih “NO”.
5. selanjutnya klik kanan pada
project yg sudah anda buat tadi pilih “Add to project” cari 3 file yg
sudah anda extract tadi dan klik Open satu persatu…. mulai dari
“imageloader.cpp” ,, “imageloader.h” ,, dan “main.cpp”.
6. kalau ketiga file tersebut
sudah di open buka isi dari “main.cpp” seperti gambar di bawah ini… ganti
“namafile foto/gambar anda !” dengan nama file foto/gambar yg sudah anda
siapkan tadi. contoh : “wendel.bmp” …OK.
8. Setelah di ganti, Simpan dan Run
project tersebut tekan “F9″ di keyboard...
"Selamat mencoba ya teman-teman" .. ^_^
project ini bisa di download klik disini
...
"Selamat mencoba ya teman-teman" .. ^_^
Segitiga_Bertingkat
// by : Wendel H selsily (672011094)
#include <windows.h> // digunakan oleh sistem
#include <gl/Gl.h>
#include <gl/glut.h>
//<<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>>
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0); // membuat latar belakang putih
glColor3f(0.0f, 0.0f, 0.0f); // membuat warna gambar hitam
glPointSize(4.0); // ukuran titik 4 x 4 pixel
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
//<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT); // hapus layar
//segitga 1
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2i(320, 410);
glVertex2i(290, 350);
glVertex2i(350, 350);
glEnd();
//segitiga 2
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2i(290, 350);
glVertex2i(320, 290);
glVertex2i(260, 290);
glEnd();
//segitiga 3
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2i(350, 350);
glVertex2i(320, 290);
glVertex2i(380, 290);
glEnd();
//segitiga 4
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2i(350, 230);
glVertex2i(410, 230);
glVertex2i(380, 290);
glEnd();
//segitiga 5
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2i(350, 230);
glVertex2i(290, 230);
glVertex2i(320, 290);
glEnd();
//segitiga 6
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex2i(230, 230);
glVertex2i(290, 230);
glVertex2i(260, 290);
glEnd();
glFlush(); // mengirim semua output ke layar
}
//<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
int main(int argc, char** argv)
{
glutInit(&argc, argv); // inisialisasi toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set modus display
glutInitWindowSize(640,480); // set ukuran window
glutInitWindowPosition(100, 150); // set posisi window di layar
//acuan sudut kiri-atas
glutCreateWindow("Segitiga Bertingkat"); // buka screen window
glutDisplayFunc(myDisplay); // registrasi fungsi menggambr
myInit();
glutMainLoop(); // berulang terus-menerus
}
Senin, 26 November 2012
Tugas GrafKom
// Wendel Selsily.cpp : Defines the entry point for the console application.
//
#include<stdafx.h>
#include <windows.h> // digunakan oleh sistem
#include <gl/Gl.h>
#include <gl/glut.h>
//<<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>>
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0); // membuat latar belakang putih
glColor3f(0.0f, 0.0f, 0.f); // membuat warna gambar hitam
glPointSize(4.0); // ukuran titik 4 x 4 pixel
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glLineWidth(4.0f);
gluOrtho2D(0.0, 500.0, 0.0, 300.0);
}
//<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
// hapus layar
glColor3f(0.0f,1.0f,1.0f);
glBegin(GL_POLYGON);//tembok depan
glVertex2i(100, 100);
glVertex2i(100, 200);
glVertex2i(200, 200);
glVertex2i(200, 100);
glEnd();
glBegin(GL_POLYGON);//tembok gedung
glVertex2i(200, 100);
glVertex2i(200, 200);
glVertex2i(400, 200);
glVertex2i(400, 100);
glEnd();
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_POLYGON);//pintu
glVertex2i(130, 100);
glVertex2i(130, 150);
glVertex2i(160, 150);
glVertex2i(160, 100);
glEnd();
glColor3f(0.0f,0.0f,0.0f);
glBegin(GL_POINTS);//pintu
glVertex2i(135, 130);
glEnd();
glColor3f(1.0f,0.6f,0.0f);
glBegin(GL_POLYGON);
glVertex2i(100, 200); //atap depan
glVertex2i(150, 250);
glVertex2i(200, 200);
glEnd();
glColor3f(1.0f,0.4f,0.0f);
glBegin(GL_POLYGON);//atap gedung
glVertex2i(200, 200);
glVertex2i(150, 250);
glVertex2i(350, 250);
glVertex2i(400, 200);
glEnd();
glColor3f(0.6f,0.f,0.f);
glBegin(GL_POLYGON);
glVertex2i(275, 125); // Jendela kiri bawah
glVertex2i(275, 150);
glVertex2i(300, 150);
glVertex2i(300, 125);
glEnd();
glColor3f(0.8f,0.8f,0.8f);
glBegin(GL_POLYGON);
glVertex2i(275, 150); // Jendela kiri atas
glVertex2i(275, 175);
glVertex2i(300, 175);
glVertex2i(300, 150);
glEnd();
glColor3f(1.0f,0.0f,1.0f);
glBegin(GL_POLYGON);
glVertex2i(300, 125); // Jendela kanan bawah
glVertex2i(300, 150);
glVertex2i(325, 150);
glVertex2i(325, 125);
glEnd();
glColor3f(0.7f,1.0f,0.7f);
glBegin(GL_POLYGON);
glVertex2i(300, 150); // Jendela kanan atas
glVertex2i(300, 175);
glVertex2i(325, 175);
glVertex2i(325, 150);
glEnd();
//atas polygon bawah garis
glColor3f(0.0f,0.0f,.0f);
glBegin(GL_LINE_LOOP);
glVertex2i(100, 100); // Garis tembok depan
glVertex2i(100, 200);
glVertex2i(200, 200);
glVertex2i(200, 100);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(130, 100); // garis pintu
glVertex2i(130, 150);
glVertex2i(160, 150);
glVertex2i(160, 100);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(200, 100); // garis tembok belakang
glVertex2i(200, 200);
glVertex2i(400, 200);
glVertex2i(400, 100);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(100, 200); // garis Atap depan
glVertex2i(150, 250);
glVertex2i(200, 200);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(200, 200); // garis Atap Belakang
glVertex2i(150, 250);
glVertex2i(350, 250);
glVertex2i(400, 200);
glEnd();
//garis jendela di bawah
glColor3f(0.0f,0.0f,0.0f);
glBegin(GL_LINE_LOOP);
glVertex2i(275, 125); // Jendela kiri bawah
glVertex2i(275, 150);
glVertex2i(300, 150);
glVertex2i(300, 125);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(275, 150); // Jendela kiri atas
glVertex2i(275, 175);
glVertex2i(300, 175);
glVertex2i(300, 150);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(300, 125); // Jendela kanan bawah
glVertex2i(300, 150);
glVertex2i(325, 150);
glVertex2i(325, 125);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(300, 150); // Jendela kanan atas
glVertex2i(300, 175);
glVertex2i(325, 175);
glVertex2i(325, 150);
glEnd();
glFlush(); // mengirim semua output ke layar
}
//<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
INT main(int argc, char** argv)
{
glutInit(&argc, argv); // inisialisasi toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set modus display
glutInitWindowSize(450,300); // set ukuran window
glutInitWindowPosition(100, 150); // set posisi window di layar
//acuan sudut kiri-atas
glutCreateWindow("Rumah Ku"); // buka screen window
glutDisplayFunc(myDisplay); // registrasi fungsi menggambr
myInit();
glutMainLoop(); // berulang terus-menerus
}
Langganan:
Postingan (Atom)