Membuat Rumah 2D dengan Netbeans

Senin, 21 Agustus 2017

Another time to share with you guys... kali ini saya bakal share cara bikin rumah 2dimensi pake Netbeans alias pake ilmu grafika. Ok kita langsung aja ke langkah-langkahnya
1.      Buka Netbeans;


2.      Pada tab File pilih New Project;



3.      Di tampilan Choose Project pilih Java Application lalu klik next;



4.      Di tampilan selanjutnya beri nama buat project yang akan kita buat. Disini saya kasih nama projectnya FCK121Rumah2D. jika sudah klik Finish (Tapi karena projectnya sudah dibikin jadi si tombol Finishnya gk muncul);



5.      Disini kita akan mengintegrasikan LWJGL. Untuk langkahnya bisa liat disini;



6.      Done ? klik kanan di Libraries lalu pilih Properties;



7.      Pada Categories pilih Run lalu di bagian VM Option ketikkan “-Djava.library.path=D:\LWJGL\lwjgl-2.9.1\native\windows” tanpa tanda kutip(“”). Disini tujuannya adalah kita mengarahkan libraries untuk mengeksekusi folder LWJGL dgn alamat yang benar. Karena saya menyimpan folder LWJGL pada directory “D” saya mengetikkan “...path=D:\...” namun apabila pembaca menyimpan LWJGL pada directory “C” maka diganti menjadi “...path=C:\...”. kalo sudah klik Ok;



8.      Di bagian code, agar cepat kita hapus semua aja. Caranya ketik dulu source code yg udah ada lalu  CTRL+a lalu Del\Backspace;



9.      Hayohh ilang semua.. kkkk ok langsung copas aja source code dibawah;






package fck121rumah2d;






import org.lwjgl.LWJGLException;


import org.lwjgl.opengl.Display;


import org.lwjgl.opengl.DisplayMode;


import org.lwjgl.opengl.GL11;






public class FCK121Rumah2D {


public void start(){


try {


Display.setDisplayMode(new DisplayMode(800,600));


Display.create();


} catch (LWJGLException e){


e.printStackTrace();


System.exit(0);


}


GL11.glMatrixMode(GL11.GL_PROJECTION);


GL11.glLoadIdentity();


GL11.glOrtho(0, 800, 0, 600, 1, -1);


GL11.glMatrixMode(GL11.GL_MODELVIEW);


// init OpenGL here


while (!Display.isCloseRequested()){


//render OpenGL here


// dibawah ini komponen gambarnya


GL11.glPointSize(5); //ini ukuran buat komponennya


GL11.glColor3f(0.0f,0.8f,1.0f); //ini format warna pake (RGB)


GL11.glBegin(GL11.GL_POLYGON); /*RUANGAN*/ //ini nama komponennya biar gampang


GL11.glVertex2i(100,155); //ini lokasi komponennya ditempatkan.. pake format (x,y)


GL11.glVertex2i(100,50); //ini ukuran


GL11.glVertex2i(250,50); //ini juga sama


GL11.glVertex2i(250,155); //yg ini juga masih


GL11.glVertex2i(100,155); //ini sama juga








//yg dibawah sini semua formatnya sama kaya yg diatas


GL11.glBegin(GL11.GL_POLYGON); /*RESPLANG*/


GL11.glColor3f(0.0f,0.5f,1.0f);


GL11.glVertex2i(50,160);


GL11.glVertex2i(50,155);


GL11.glVertex2i(300,155);


GL11.glVertex2i(300,160);


GL11.glVertex2i(50,160);


GL11.glEnd();






GL11.glBegin(GL11.GL_POLYGON); /*ATAP*/


GL11.glColor3f(1.0f,0.3f,0.0f);


GL11.glVertex2i(175,230);


GL11.glVertex2i(50,160);


GL11.glVertex2i(300,160);


GL11.glVertex2i(175,230);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*PINTU*/


GL11.glColor3f(0,0,1);


GL11.glVertex2i(160,100);


GL11.glVertex2i(160,50);


GL11.glVertex2i(190,50);


GL11.glVertex2i(190,100);


GL11.glVertex2i(160,100);


GL11.glEnd();






GL11.glBegin(GL11.GL_POLYGON); /*JENDELA 1*/


GL11.glColor3f(0,0,1);


GL11.glVertex2i(130,100);


GL11.glVertex2i(130,60);


GL11.glVertex2i(150,60);


GL11.glVertex2i(150,100);


GL11.glVertex2i(130,100);


GL11.glEnd();






GL11.glBegin(GL11.GL_POLYGON); /*JENDELA 2*/


GL11.glColor3f(0,0,1);


GL11.glVertex2i(200,100);


GL11.glVertex2i(200,60);


GL11.glVertex2i(220,60);


GL11.glVertex2i(220,100);


GL11.glVertex2i(200,100);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*TIANG*/


GL11.glColor3f(1,1,1);


GL11.glVertex2i(30,40);


GL11.glVertex2i(30,0);


GL11.glVertex2i(40,0);


GL11.glVertex2i(40,40);


GL11.glVertex2i(30,40);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*TIANG 2*/


GL11.glColor3f(1,1,1);


GL11.glVertex2i(140,40);


GL11.glVertex2i(140,0);


GL11.glVertex2i(150,0);


GL11.glVertex2i(150,40);


GL11.glVertex2i(140,40);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*PAGAR*/


GL11.glColor3f(1,1,1);


GL11.glVertex2i(40,10);


GL11.glVertex2i(140,10);


GL11.glVertex2i(140,15);


GL11.glVertex2i(40,15);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*PAGAR 2*/


GL11.glColor3f(1,1,1);


GL11.glVertex2i(40,25);


GL11.glVertex2i(140,25);


GL11.glVertex2i(140,25);


GL11.glVertex2i(140,30);


GL11.glVertex2i(40,30);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*TIANG 3*/


GL11.glColor3f(1,1,1);


GL11.glVertex2i(200,40);


GL11.glVertex2i(200,0);


GL11.glVertex2i(210,0);


GL11.glVertex2i(210,40);


GL11.glVertex2i(200,40);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*TIANG 4*/


GL11.glColor3f(1,1,1);


GL11.glVertex2i(311,40);


GL11.glVertex2i(311,0);


GL11.glVertex2i(320,0);


GL11.glVertex2i(320,40);


GL11.glVertex2i(311,40);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*PAGAR 3*/


GL11.glColor3f(1,1,1);


GL11.glVertex2i(211,10);


GL11.glVertex2i(311,10);


GL11.glVertex2i(311,15);


GL11.glVertex2i(211,15);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*PAGAR 4*/


GL11.glColor3f(1,1,1);


GL11.glVertex2i(211,25);


GL11.glVertex2i(311,25);


GL11.glVertex2i(311,30);


GL11.glVertex2i(211,30);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*CARPOT*/


GL11.glColor3f(0,1,0);


GL11.glVertex2i(155,50);


GL11.glVertex2i(155,-10);


GL11.glVertex2i(195,-10);


GL11.glVertex2i(195,50);


GL11.glVertex2i(150,50);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*LANTAI*/


GL11.glColor3f(0,1,1);


GL11.glVertex2i(160,50);


GL11.glVertex2i(160,45);


GL11.glVertex2i(190,45);


GL11.glVertex2i(190,50);


GL11.glVertex2i(160,50);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*POT*/


GL11.glColor3f(0,1,1);


GL11.glVertex2i(280,40);


GL11.glVertex2i(285,40);


GL11.glVertex2i(290,50);


GL11.glVertex2i(275,50);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*BUNGA*/


GL11.glColor3f(0,1,0);


GL11.glVertex2i(282,50);


GL11.glVertex2i(284,50);


GL11.glVertex2i(284,90);


GL11.glVertex2i(282,90);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*BUNGA 2*/


GL11.glColor3f(0,1,0);


GL11.glVertex2i(284,50);


GL11.glVertex2i(298,80);


GL11.glVertex2i(300,80);


GL11.glVertex2i(286,50);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*BUNGA 3*/


GL11.glColor3f(0,1,0);


GL11.glVertex2i(282,50);


GL11.glVertex2i(267,80);


GL11.glVertex2i(265,80);


GL11.glVertex2i(280,50);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*POT 2*/


GL11.glColor3f(0,1,1);


GL11.glVertex2i(65,40);


GL11.glVertex2i(70,40);


GL11.glVertex2i(75,50);


GL11.glVertex2i(60,50);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*BUNGA 4*/


GL11.glColor3f(0,1,0);


GL11.glVertex2i(69,50);


GL11.glVertex2i(69,90);


GL11.glVertex2i(67,90);


GL11.glVertex2i(67,50);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*BUNGA 5*/


GL11.glColor3f(0,1,0);


GL11.glVertex2i(69,50);


GL11.glVertex2i(84,80);


GL11.glVertex2i(86,80);


GL11.glVertex2i(71,50);


GL11.glEnd();


GL11.glBegin(GL11.GL_POLYGON); /*BUNGA 6*/


GL11.glColor3f(0,1,0);


GL11.glVertex2i(67,50);


GL11.glVertex2i(52,80);


GL11.glVertex2i(50,80);


GL11.glVertex2i(65,50);














Display.update();


}


Display.destroy();


}













public static void main(String[] args) {


FCK121Rumah2D displayExample = new FCK121Rumah2D(); /*FCK121Rumah2D itu


nama dari project jadi kalo beda namanya tinggal sesuaikan aja*/


displayExample.start();


}






}


10.  Kalo udah sekarang coba di Run Project (f6);



11.  Tadaaa....



And....... it’s done. Ok cukup sekian postingan kali ini. Kalo ada yg kurang ngerti atau gagal atau gk paham atau apalah, cukup tanya dikomentar aja.. see you on next post

Comments

Post a Comment

Popular Posts