Friday, May 11, 2018

A. Membuat Titik L Pada Dev C++ OpenGL

saya akan memberikan tutorial membuat objek titik L pada Dev C++ OpenGL. berikut adalah langkah-langkah yang harus diikuti  :

1. Klik File > New > Project > OK


2. Setelah New Project akan tampil jenis lembar kerja yang akan digunakan, klik Console Application > OK


3. Setelah itu Save Project, klik Save


4. Klik kanan pada Bar Project, lalu pilih Project Options


5. Pada Project Options, klik Parameters > Linker
  Pada Box Linker ketik -lopengl32, -lfreeglut, -lglu32, lalu klik lah OK


6. Pada lembar kerja akan muncul Script seperti ini,


 7. Kosongkan Script dan ketikan script seperti dibawah ini :
  1. #include <GL/glut.h>           
  2. #include <GL/gl.h>
  3. #include <windows.h>
  4.  
  5. void userdraw () {
  6. glBegin (GL_POINTS); 
  7. glVertex2i (150,0); 
  8. glVertex2i (150,200); 
  9. glVertex2i (370,200);
  10.  
  11. glEnd ();
  12. }
  13.  
  14. void display (void) {
  15. glClear (GL_COLOR_BUFFER_BIT);
  16. userdraw ();
  17. glutSwapBuffers ();
  18. }
  19. int main (int argc, char **argv) {
  20. glutInit (&argc,argv);
  21. glutInitDisplayMode (GLUT_DOUBLE|GLUT_RGB);
  22. glutInitWindowSize (640,480);
  23. glutCreateWindow ("Membuat Objek Titik");
  24. glClearColor (0.0, 0.0, 0.0, 0.0);
  25. gluOrtho2D (0.,640.,-240.,240.);
  26. glutIdleFunc (display); 
  27. glutDisplayFunc (display);
  28. glutMainLoop (); 
  29. return 0;
  30. }


8. Setelah di ketikkan scriptnya maka akan menjadi seperti ini.


9. Compile dan Run (Execute, Compile & Run) dan output akan terlihat seperti ini : 

sekian tutorial  membuat Objek Titik pada Dev C OpenGl , Semoga Bermanfaat ^^

B. Membuat Persegi pada Dev C++ OpenGL

saya akan memberikan tutorial pembuatan persegi pada Dev C++ pada OpenGL.

1. Berikut script untuk membuat persegi pada Dev C++ OpenGL :

  1. #include <windows.h>
  2. #include <GL/gl.h>
  3. #include <GL/glu.h>
  4. #include <GL/glut.h>
  5. void display(void)
  6. glClearColor (0.0,0.0,0.0,0.0); 
  7. glClear (GL_COLOR_BUFFER_BIT); 
  8. glBegin(GL_POLYGON); 
  9. glVertex2f(-0.5,-0.5); 
  10. glVertex2f(-0.5,0.5); 
  11. glVertex2f(0.5,0.5); 
  12. glVertex2f(0.5,-0.5); 
  13. glEnd (); 
  14. glFlush();
  15. }
  16. int main(int argc, char** argv)
  17. glutInit(&argc, argv); 
  18. glutCreateWindow("Membuat Persegi"); 
  19. glutDisplayFunc(display); 
  20. glutMainLoop(); 
  21. return 0;
  22. }

2. Lalu jalankan script dengan cara Execute > Compile & Run, maka hasilnya akan menjadi seperti ini :


C. Tutorial Pembuatan Persegi Pelangi Dengan 7 warna pada Dev C++ OpenGL

kali ini saya akan memberikan tutorial pembuatan persegi dengan 7 warna pada Dev C++.

1. Berikut merupakan coding yang akan digunakan dalam pembuatan persegi dengan 7 warna pada Dev C++ :



  1. #include <GL/glut.h>
  2.  
  3. void persegi();
  4. int main(int argc, char** argv)
  5. {    
  6. glutInit(&argc,argv);    
  7. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  8. glutInitWindowSize(640,640);        
  9. glutCreateWindow("Membuat Persegi Pelangi");      
  10. glutDisplayFunc(persegi);    
  11. glutMainLoop();
  12. }
  13. void persegi()
  14. {        
  15.  
  16. glBegin(GL_POLYGON);    
  17. glColor3f(1.0, 0.0 ,0.0);    
  18. glVertex2f(-0.8,0.7);
  19. glVertex2f(-0.8,0.8);  
  20. glVertex2f(0.8,0.8);
  21. glVertex2f(0.8,0.7);    
  22. glEnd();
  23.  
  24. glBegin(GL_POLYGON);    
  25. glColor3f(1.0, 0.5, 0.0);    
  26. glVertex2f(-0.8,0.6);
  27. glVertex2f(-0.8,0.7);
  28. glVertex2f(0.8,0.7);
  29. glVertex2f(0.8,0.6);
  30. glEnd();
  31.  
  32. glBegin(GL_POLYGON);    
  33. glColor3f(1.0, 1.0, 0.0);    
  34. glVertex2f(-0.8,0.5);
  35. glVertex2f(-0.8,0.6);
  36. glVertex2f(0.8,0.6);
  37. glVertex2f(0.8,0.5);    
  38. glEnd();  
  39.  
  40. glBegin(GL_POLYGON);    
  41. glColor3f(0.0, 1.0, 0.0);    
  42. glVertex2f(-0.8,0.4);
  43. glVertex2f(-0.8,0.5);
  44. glVertex2f(0.8,0.5);
  45. glVertex2f(0.8,0.4);    
  46. glEnd();
  47.  
  48. glBegin(GL_POLYGON);    
  49. glColor3f(0.0, 1.0, 1.0);    
  50. glVertex2f(-0.8,0.3);
  51. glVertex2f(-0.8,0.4);
  52. glVertex2f(0.8,0.4);
  53. glVertex2f(0.8,0.3);    
  54. glEnd();  
  55.  
  56. glBegin(GL_POLYGON);    
  57. glColor3f(0.0, 0.0, 1.0);    
  58. glVertex2f(-0.8,0.2);
  59. glVertex2f(-0.8,0.3);
  60. glVertex2f(0.8,0.3);
  61. glVertex2f(0.8,0.2);    
  62. glEnd();
  63.  
  64. glBegin(GL_POLYGON);    
  65. glColor3f(0.53, 0.12, 0.47);    
  66. glVertex2f(-0.8,0.1);
  67. glVertex2f(-0.8,0.2);
  68. glVertex2f(0.8,0.2);
  69. glVertex2f(0.8,0.1);    
  70. glEnd();                                  
  71.                                
  72. glFlush();
  73. }



2. Apabila coding sudah diketikkan maka jalankan dengan cara Execute > Compile & Run




D. Tutorial Pembuatan Bangun-Bangun Dasar Grafik pada Dev C++

berikut merupakan tutorial pembuatan bangun dasar grafik pada Dev C++

1. Berikut coding untuk membuat bangun-bangun dasar grafik pada Dev C++ :


  1. #include <GL/glut.h>           
  2. #include <windows.h>   
  3. #include <GL/gl.h>
  4. void init (void) { 
  5. glClearColor (1.0, 1.0, 1.0, 0.0); 
  6. glLineWidth (1.0); 
  7. glColor3f (1.0, 0.0, 0.0);         
  8. glOrtho (-6,6, -6,6, -6,6);
  9. }              
  10. void Display (void) {      
  11. glClear (GL_COLOR_BUFFER_BIT); 
  12. glBegin (GL_LINES);
  13. glVertex2f (-5.5, 0.0);    
  14. glColor3f (1.0, 0.0, 0.0);
  15. glVertex2f (5.5, 0.0);     
  16. glEnd ();      
  17. glBegin (GL_LINES);    
  18. glVertex2f (0.0, -5.5);
  19. glColor3f (1.0, 0.0, 0.0); 
  20. glVertex2f (0.0, 5.5);     
  21. glEnd ();      
  22.            
  23.            
  24. glBegin (GL_LINE_LOOP);        
  25. glColor3f (-1.0, 0.0, 0.0);    
  26. glVertex2f (1.0, 1.0);     
  27. glColor3f (-1.0, 0.0, 0.0);    
  28. glVertex2f (4.0, 1.0);
  29. glColor3f (0.0, 1.0, 0.0);
  30. glVertex2f (1.0, 5.0);
  31. glEnd ();
  32. glutSwapBuffers ();
  33. }
  34. int main (int argc, char** argv) { 
  35. glutInit (&argc, argv);
  36. glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);  
  37. glutInitWindowPosition (0, 0);
  38. glutInitWindowSize (1500, 1500);
  39. glutCreateWindow ("bangun dasar grafik");  
  40. init ();
  41. glutDisplayFunc (Display);
  42. glutMainLoop ();
  43. return 0;
  44. }



2. Jika coding sudah diketikkan maka jalankan dengan cara Execute > Compile & Run






Semoga Bermanfaat ^^