Advertisement
gurumutant

OpenGL Lingkaran Sederhana

Sep 6th, 2017
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <GL/glut.h>
  3. using namespace std;
  4. #define PI 3.14
  5. void lingkaran(float center_x, float center_y, float jari2, int res = 100) {
  6.     glBegin(GL_LINE_LOOP);
  7.         for(int i = 0; i <= res;i++) { glVertex2f(
  8.                 center_x + (jari2 * cos(i * (2.0f * PI) / res)),
  9.                 center_y + (jari2 * sin(i * (2.0f * PI) / res))
  10.             ); }
  11.     glEnd();
  12. }
  13. void tampil() {
  14.     glClear(GL_COLOR_BUFFER_BIT);
  15.     glColor3ub(0,255,0);
  16.     lingkaran(100,100,70);
  17.     glutSwapBuffers();
  18. }
  19. int main(int argc, char** argv) {
  20.     glutInit(&argc, argv);
  21.     glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
  22.     glutInitWindowPosition(100,100); glutInitWindowSize(480,480);
  23.     glutCreateWindow("Pemrograman Grafik RPL 2017");
  24.     glClearColor(1.0,1.0,1.0,0);
  25.     gluOrtho2D(0.,200.,0.,200.); // proyeksi bidang gambar
  26.     glutDisplayFunc(tampil); glutMainLoop(); return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement