Matur Nuwun Sampun Mampir Mugi-Mugi Saget Dados Ilmu Ingkang Manfaat Fiddunya Wal Akherat

Rabu, 21 Juli 2010

Primitif Drawing Kereta Api 1 Dimensi

Grafika komputer adalah cara membuat gambar atau grafik dengan menggunakan komputer. Dalam grafika komputer seseorang dianjurkan mempunyai daya imajinasi yang cukup lumayan karena grafika komputer terdiri dari koordinat titik - titik yang nantinya akan dihubungkan satu sama lainnya.

Pada pembahasan kali ini kita akan membahas tentang pembuatan kereta api 1 dimensi menggunakan visual C++, berikut langkah - langkahnya beserta source code sederhana yang dapat dikembangkan lebih lanjut. Sebelum membuatnya kita harus menambahkan openGL dapat di download di sini.

buka program file -> microsoft visual studio -> VCC -> include -> masukkan glut.h
buka program file -> microsoft visual studio -> VCC -> Lib-> masukkan glut32.lib
C: windows -> system -> masukkan glut32.dll
C: windows -> system32 -> masukkan glut32.dll

ini adalah contoh source code kereta api 1 dimensi

#include
#include

void userdraw(void);

void setColor(float red, float green, float blue)
{
glColor3f(red, green, blue);
}

void userdraw(void)
{
glPointSize(3);
glLineWidth(4.0);

setColor(0.,1.,0.);
//body
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(100,120); //a
glVertex2i(100,290); //b
glVertex2i(370,290); //c
glVertex2i(370,120); //d

glEnd();

glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(210,290);
glVertex2i(210,300);
glVertex2i(120,300);
glVertex2i(100,290);
glEnd();

//lampu
glBegin(GL_POLYGON);
glColor3f(1,0,0);
glVertex2i(100,270);
glVertex2i(100,210);
glVertex2i(95,220);
glVertex2i(95,260);
glEnd();

//tambahan body
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(210,380);
glVertex2i(210,250);
glVertex2i(370,250);
glVertex2i(370,380);
glEnd();

glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(200,300);
glVertex2i(230,330);
glVertex2i(210,200);
glEnd();

//jendela
glBegin(GL_POLYGON);
glColor3f(0,1,1);
glVertex2i(240,350);
glVertex2i(240,270);
glVertex2i(330,270);
glVertex2i(330,350);
glEnd();

glBegin(GL_LINE_LOOP);
glColor3f(1,0,0);
glVertex2i(240,350);
glVertex2i(240,270);
glVertex2i(330,270);
glVertex2i(330,350);
glEnd();

//bamper
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(87,200); //a
glVertex2i(65,100);//b
glVertex2i(65,130);//c
glVertex2i(65,90);//d
glVertex2i(163,100); //e
glVertex2i(150,205); //f
glEnd();

for(int a=80;a<=110;a++){
a+=20;
glBegin(GL_POLYGON);
glColor3f(1,1,1);
glVertex2i(a,155);
glVertex2i(a,115);
glVertex2i(10+a,115);
glVertex2i(10+a,155);
glEnd();}
//atas
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(200,400);
glVertex2i(200,370);
glVertex2i(380,370);
glVertex2i(380,400);
glEnd();

// cerobong
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(160,300);
glVertex2i(180,340);
glVertex2i(100,340);
glVertex2i(120,300);
glEnd();

glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(110,330);
glVertex2i(110,350);
glVertex2i(170,350);
glVertex2i(170,330);
glEnd();

//gerbong
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(400,330); //a
glVertex2i(400,120); //b
glVertex2i(620,120); //c
glVertex2i(620,330); //d
glEnd();

//jendela
glBegin(GL_POLYGON);
glColor3f(0,1,1);
glVertex2i(430,300); //a
glVertex2i(430,230); //b
glVertex2i(500,230); //c
glVertex2i(500,300); //d
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1,0,0);
glVertex2i(430,300); //a
glVertex2i(430,230); //b
glVertex2i(500,230); //c
glVertex2i(500,300); //d
glEnd();

glBegin(GL_POLYGON);
glColor3f(0,1,1);
glVertex2i(520,300); //a
glVertex2i(520,230); //b
glVertex2i(600,230); //c
glVertex2i(600,300); //d
glEnd();

glBegin(GL_LINE_LOOP);
glColor3f(1,0,0);
glVertex2i(520,300); //a
glVertex2i(520,230); //b
glVertex2i(600,230); //c
glVertex2i(600,300); //d
glEnd();

//atas
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(390,350);
glVertex2i(390,300);
glVertex2i(630,300);
glVertex2i(630,350);
glEnd();

//sambungan1
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(400,140); //a
glVertex2i(400,120); //b
glVertex2i(370,120); //c
glVertex2i(370,140); //d
glEnd();
//tambahan sambungan
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(370,150); //a
glVertex2i(370,120); //b
glVertex2i(380,120); //c
glVertex2i(380,140); //d
glEnd();

//sambungan2
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(600,140); //a
glVertex2i(600,120); //b
glVertex2i(640,120); //c
glVertex2i(640,140); //d
glEnd();

glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(620,150);
glVertex2i(630,140);
glVertex2i(620,140);
glEnd();

//ban1
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(240,170);
glVertex2i(240,100);
glVertex2i(170,100);
glVertex2i(170,170);
glEnd();

glBegin(GL_POLYGON);
glColor3f(0,0,1);
glVertex2i(240,110);
glVertex2i(240,100);
glVertex2i(237,100);
glEnd();

glBegin(GL_POLYGON);
glColor3f(0,0,1);
glVertex2i(170,110);
glVertex2i(170,100);
glVertex2i(173,100);
glEnd();
//ban2
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(280,170);
glVertex2i(280,100);
glVertex2i(350,100);
glVertex2i(350,170);

glEnd();

glBegin(GL_POLYGON);
glColor3f(0,0,1);
glVertex2i(280,110);
glVertex2i(280,100);
glVertex2i(283,100);

glEnd();
glBegin(GL_POLYGON);
glColor3f(0,0,1);
glVertex2i(350,110);
glVertex2i(350,100);
glVertex2i(347,100);

glEnd();
//ban3
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(420,170);
glVertex2i(420,100);
glVertex2i(490,100);
glVertex2i(490,170);

glEnd();

glBegin(GL_POLYGON);
glColor3f(0,0,1);
glVertex2i(420,110);
glVertex2i(420,100);
glVertex2i(423,100);
glEnd();

glBegin(GL_POLYGON);
glColor3f(0,0,1);
glVertex2i(490,110);
glVertex2i(490,100);
glVertex2i(487,100);
glEnd();
//ban4
glBegin(GL_POLYGON);
glColor3f(0,0,0);
glVertex2i(530,170);
glVertex2i(530,100);
glVertex2i(600,100);
glVertex2i(600,170);

glEnd();

glBegin(GL_POLYGON);
glColor3f(0,0,1);
glVertex2i(530,110);
glVertex2i(530,100);
glVertex2i(533,100);
glEnd();

glBegin(GL_POLYGON);
glColor3f(0,0,1);
glVertex2i(600,110);
glVertex2i(600,100);
glVertex2i(597,100);
glEnd();

//lintasan
glBegin(GL_POLYGON);
glColor3f(0.5,0.5,0.5);
glVertex2i(0,90);
glVertex2i(0,100);
glVertex2i(640,100);
glVertex2i(640,90);
glEnd();

glBegin(GL_LINES);
glColor3f(0,0,0);
glVertex2i(0,100);
glVertex2i(640,100);

glEnd();

//corak gerbong1
glBegin(GL_POLYGON);
glColor3f(1,1,0);
glVertex2i(100,215);
glVertex2i(100,200);
glVertex2i(370,200);
glVertex2i(370,215);
glEnd();

//corak gerbong 2

glBegin(GL_POLYGON);
glColor3f(1,1,0);
glVertex2i(400,195);
glVertex2i(400,200);
glVertex2i(620,200);
glVertex2i(620,195);
glEnd();

glBegin(GL_POLYGON);
glColor3f(1,1,0);
glVertex2i(400,215);
glVertex2i(400,210);
glVertex2i(620,210);
glVertex2i(620,215);
glEnd();
//rumput
glBegin(GL_POLYGON);
glColor3f(0,1,0);
glVertex2i(0,0);
glVertex2i(0,90);
glVertex2i(640,90);
glVertex2i(640,0);
glEnd();
//klakson
glBegin(GL_LINE_LOOP);
glColor3f(0,0,0);
glVertex2i(275,302);
glVertex2i(285,310);
glVertex2i(295,302);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0,0,0);
glVertex2i(285,348);
glVertex2i(285,310);
glEnd();

}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
userdraw();
glFlush();
}

void main(int argc, char**argv)
{
glutInit(&argc,argv);

glutInitWindowPosition(100,150);
glutInitWindowSize(640,480);
glutCreateWindow("By Yudha");
glClearColor(0.0,0.0,1.0,0.0);
gluOrtho2D(0.,640.,0.,480.0);
glutDisplayFunc(display);
glutMainLoop();
}

Selamat Mencoba. Semoga bermanfaat ^o^ sampai ketemu dalam pembahasan selanjutnya....

0 komentar:


Silakan Bekomentar.!!!


Semakin banyak berkomentar, semakin banyak backlink, semakin cinta Search Engine terhadap blog anda
:a:
:b:
:c:
:1: :2: :3: :4: :5: :6:
:7: :8: :9: :10: :11: :12:

Posting Komentar

Tinggalkan Pesan

Get cash from your website. Sign up as affiliate.Join 4Shared Now! affiliate program

EARN CASH FROM YOUR SITE

Turn your valuable site visitors into income. Work online and join our free money making partner program. We offer the most commission rate to help maximize your income stream.

Join our money making program absolutely no charge and 100% risk free.

Sign Up...

Mountain a constant stream of money

Our money making system helps you to establish a constant stream of cash, 24 hours a day, 7 days a week, 365 days a year. Allowing you more time to focus on the things you love. You'll even receive money while you sleep!

Start receiving steady affiliate revenue

This money earn program really can make you profit on the same day. Start collecting serious partner income with almost no effort at all. This is a serious revenue opportunity, the first step for you to build a steady, reliable, long-time profitable business.

A constant money generator

Imagine running of a something that never failed to provide you with income-flow. A earning money program so amazingly profitable that you never had to work for a boss ever again!

Lotta Rewards Lotta Rewards