[Tutorial] Membuat titik dan garis dengan OpenGL menggunakan Visual C++ / Visual Studio

Untuk yang baru berkenalan dengan OpenGL (saya pun baru mulai mempelajarinya) pasti masih kebingungan bagaimana membuat projek menggunakan OpenGL. Nah kali ini saya akan membagikan tutorial sederhana tetang bagaimana membuat titik dan garis dengan OpenGL. Pastikan kalian telah memiliki Ms. Visual Studio/Visual C++ ya, atau menggunakan IDE C++ lain pun boleh.

Langkah-langkah :

  1. Langkah pertama yaitu pastikan kalian mempunyai plugin OpenGL nya, untuk mendownload nya klik disini.
  2. Extract file
  3. copy file yang ada di folder lib ke C:Program FilesMicrosoft Visual Studio 9.0VClib
  4. copy folder GL yang berada di folder include ke C:Program FileMicrosoft Visual Studio 9.0VCinclude
  5. copy file yang ada di folder dll ke C:windowssystem32 (jika 32 bit), jika komputer kalian 64 bit copykan juga ke C:windowssysWOW64

Nah jika sudah mempunyai OpenGL bisa dilanjutkan ke langkah selanjutnya :

1. Buka Ms. Visual Studio / Visual C++ klik New project

2. Bagi yang menggunakan Visual Studio, pastikan kalian memilih Visual C++ di panel kiri, kemudian pilih Win32 Console Application,  beri nama belajar_OpenGL atau apapun lalu klik OK

 

3. Klik next lalu beri centang pada Empty Project kemudian klik Finish

4. Setelah itu tekan Alt+F7, buka Configuration Properties > Linker > Input,  lalu isikan opengl32.lib glu32.lib glaux32.lib di kolom Additional Dependencies kemudian tekan OK

5. Setelah itu kita membuat file cpp baru, caranya Klik kanan di Source File > New Item

6. Setelah muncul jendela baru, pilih C++ File (.cpp), beri nama main kemudian klik Add

7. Nah sekarang kitta sudah bisa langsung mengetikkan script, tapi untuk kali ini saya berikan contoh programnya.

#include <GL/glut.h>

void drawLine(int x1,int y1,int x2,int y2) {
glBegin(GL_LINES);
glVertex2i(x1,y1);
glVertex2i(x2,y2);
glEnd();
}

void drawDot(int x,int y) {
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}

//draw area
void userdraw() {
static int tick=0;

//set warna (R,G,B)
glColor3f(1,0,0);
//menggambar titik menggunakan fungsi drawDot
drawDot(320,280);
drawDot(319,281);
drawDot(319,279);
drawDot(321,279);
drawDot(321,281);

//set warna (R,G,B)
glColor3f(1,1,0);
//menggambar garis
drawLine(0,0,640,480);
drawLine(0,480,640,0);
}

void display(void){
//clear screen
glClear(GL_COLOR_BUFFER_BIT);
userdraw(); //jalankan userdraw()
glutSwapBuffers();
}

int main(int argc, char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowPosition(100,100); //posisi windownya di (100,100)
glutInitWindowSize(640,480); //set ukuran window jadi 640×480
glutCreateWindow(“Belajar OpenGL”); //set judul app
glClearColor(1,1,1,0); //set warna background (r,g,b,a)(range 0-1)
gluOrtho2D(0.,640.,0.,480.); //set area menggambar
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

8. Coba compile program diatas, jika berhasil maka akan memunculkan jendela baru seperti berikut :

 

 

Selesai! Selamat ya untuk yang sudah berhasil. Bagi yang belum berhasil jangan menyerah, silahkan bertanya di kolom komentar di bawah ini, Insyaallah saya akan jawab. Terima kasih atas kunjungannya!

 

4 Comments
  1. Gawa
  2. Mochi

Leave a Reply

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

nndm stockldos stock pricehydro gfx gtx 1080 tinyse fnfcoh tickerctxr stock priceudow stock pricenasdaq sedgacer aspire pew72btfl stock priceqtrrf stockonkyo tx nr747 reviewkepard vpnhack verizon jetpack for unlimited datasrra stockchromebox mounting bracketnyse invhtotallee vs peelpotash stock quotedxpe stocktwlo stockefoi stockswb2usbc thumb drivecodiustsohost lite hostingvoxx stock pricezrzh stocksnagit vs snipping toolex5250ibotta account lockedctrp stock pricekanto yu4 reviewuslmcspgfcadifcmbs etfbiohacking implantsusrm stock chartnyse bwxtfiretronlg ph150g reviewibio stock priceairadar asus rt n56ugigrig g2nasdaq crzoi7 7740k release datelogitech p710e reviewivfh stockuwt stocktwitsnyse veevelnkagritek holdings stockgnucash vs quickbookslogitech c930e reviewlumix dmc lx10kroku airplay mirroringiusg stockhtc desire 601 battery drainaj81endp stockhp z440 specsis phonerescue safeasus vivobook f510ua reviewmrcy stockpstg stock pricegtlaxbr75x850e reviewrudeinternetdell doorbustertvix stock priceableton live powerpcdagcoinchct stockipair registrationgwph stockbdp s7200netgear router r6300v2adobe kuler alternativerapportive for outlookcasio xj a130 replacement bulbakrxexelixis stock pricefeye earningsbdp s6500 reviewdell precision m6400 covet reviewdvaxkodk stock pricecentene stock pricerazer leviathan setupnuraphoneseasymoneysniperhp deskjet 2548 inkjet all in one printerbcm buttstockgwph stockmu9000 reviewwrmt nasdaqnasdaq rdfnazrxnasdaq myoshp envy x360 15 aq155nrbwxt stock pricenyse dhxlrttf stock price49ks8000snmx stock priceprasmhqcl stockastra 19.2 e satellite positionptgx stockachv stockipfire setupcntf stockowc pharmaceutical research corp stockplpm stockdevice in a joggers armbandgllkcnxr stockvpmaargx stockconatus pharmaceuticalsfujhytcl 55us57 reviewtrutv optimum channelnetgear ac1600 reviewdell d3218hnsp500trsuneq stockblu tack walmartimovie keeps crashingnasdaq clrbmdso stock pricego to www amdrewards comjanusvrhp le2201wttcnflgv6moto gk40zyxel armor z2 ac2600sony xbr55x850d 55 inch 4k ultra hd smart tvbtcs stock pricecorsair scimitar side buttons not workingpsvue coststockbeewbmd stockfugoo sport reviewnyse mkcbtfd meaningdell k1000 pricetgtx stock newsnikon d2300ptie stocklg g4 keeps restartingpkoh stockafterglow prismatic wireless headsettck stock pricedexcom g5 apple watchabev stocksbsa stockimpuy stockelk clonertcl p607zte z740 pricebiconic speakerdzsiflipstagramvly stock pricelifelock discount aarpqedn stock pricelifebeam vi reviewasus rog gl502vs ds71scwx stock pricelivehivepsec stock price todaypebble 301blasus vp278rost stock priceasus gl551jw ds71cgrwplpl stocksouhy stockepson wf 2760 troubleshootinggden stockk3000m benchmarktamron a005nsennheiser urbanite xl wireless reviewsbbp stockdell 34 ultrasharp curved monitor u3417wghostery safari iphonelunticbidu after hoursgarmin tactix bravo reviewmovado bold motion smartwatchgwph stock price todaylxgtf stockbeoplay h4 head fisony 49x900efstr stockhow to make custom gamerpic on xbox oneunitiqute 2 pricernva newslgcypozujskoks8000 rtingssony x940cemqqnewtzfujitsu lifebook p770 priceasus 10.1 transformer mini t102ha d4 grsamsung 65mu8000cytr newsoesx stockmedovex stockeurn stockvixy stockgwprfavpn serviceac799readiusue megaboom best pricedistnotedtoshiba satellite m50 a 11calaris royalty corpartx stock newsvlkay stock priceturtle beach i30aj81pslistwiselink pro downloadpegasystems stock priceasus rog strix gl502 reviewendv stocktitan x pascal neweggmvis stock pricededsec live wallpaperubd k8500 zabrvvf stockrso stock pricephilips bdp7501a315 21 95kf ustcl 55p607 55 inch 4k ultra hdquicklooksatellitedxpe stockpcrfyfreefly vr reviewmoggersnasdaq usatnaim nait 5sicigna stock price historybxmt stockbest buy ecobee3inpulse smartwatch reviewedu2020vacpnyse krghtgcipad md787ll aapple emoji 10.2 apkhp envy 4520 won t printbdp7502uvxy after hourshbhc stock pricenikon d750 walmartsony 4k projector ultra short throw vpl gtz1lifevantage stock price todayasus vg245h reviewobseva saevbnjackery giant plusrega rs7 reviewnyse wsocanon rebel 7ilgv20 pricedell u3417w reviewsamsung ks8500 49garwfsamsung np900x5l k02usesnc stockchimbotcsse stocktosyyvizio smartcast p series p c1tsro stocklnc stock pricewebroot secureanywhere removal toollbai stock pricebsgm stock priceschk stockrcii stock pricebose qc35 equalizerleju stockowcp newsnyse hhcunikoingoldmsi gs70 stealth pro pricemf839ll a specsphilips 65pus7601nyse ecomlululemon stock chartmdlnf stockhadv stock pricetopre realforce 87uabbv tickervizio d43f e1t12 haltwpz stock pricevwo stock priceccwfgoro stock pricenyse dgxnihd stock priceogsdacer es1 533 c55pccgi stock pricenasdaq gogltvix tickerlogitech mk700galaxy s7 moisture detectedbose soundtouch indiadell e6410 specsvizio sb3851ugaz stock chartgarageband crossfadeubereats surgewetf stock pricedell 34 ultrasharp curved monitor u3417wmyzone heart rate monitormass effect andromeda hainly abramsmrtx stockbrowsec extensionjp asso share pricedermira inclkndroxio photoshowmbot stock pricewalmart jaybird x3gobone reviewswfbigigabyte ma790fxt ud5p motherboard34uc79g b reviewnasdaq opgnclls stock pricefujifilm s3500 reviewinsy stock pricetrmk stock pricebear flattenerwsbf stockktos stock pricemd101hn amastec stock pricegtx 980 teraflopspanera tickervertcoin halving