imtiazaasif

Half circle with radious using OpenGL

Jun 18th, 2022
1,235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. // making half cicrle
  2.  
  3. #include <GL/gl.h>
  4. #include <GL/glut.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7.  
  8. int r, p, x = 0, y;
  9. void display(void)
  10. {
  11.  
  12.     glClear(GL_COLOR_BUFFER_BIT);
  13.     glColor3f(1.0, 1.0, 1.0);
  14.     glBegin(GL_POINTS);
  15.  
  16.     p = 1 - r;
  17.  
  18.     while (x <= y)
  19.     {
  20.         if (p < 0)
  21.         {
  22.             x = x + 1;
  23.             y = y;
  24.             p = p + (2 * x + 1) + 1;
  25.         }
  26.         else
  27.         {
  28.             x = x + 1;
  29.             y = y - 1;
  30.             p = p + (2 * x + 1) + 1 - (2 * y);
  31.         }
  32.  
  33.         glVertex2i(r - x, y);
  34.         glVertex2i(r - y, x);
  35.         glVertex2i(x - r, y);
  36.         glVertex2i(r - y, -x);
  37.         glVertex2i(x - r, -y);
  38.         glVertex2i(y - r, -x);
  39.         glVertex2i(r - x, -y);
  40.         glVertex2i(y - r, x);
  41.     }
  42.  
  43.     glEnd();
  44.     glutSwapBuffers();
  45. }
  46. void init(void)
  47. {
  48.  
  49.     glClearColor(0.0, 0.0, 0.0, 0.0); /* select clearing (background) color */
  50.     glMatrixMode(GL_PROJECTION);      /* initialize viewing values */
  51.     glLoadIdentity();
  52.     glOrtho(-100, 100.0, -100, 100.0, -1, 1);
  53. }
  54.  
  55. int main(int argc, char **argv)
  56. {
  57.  
  58.     printf("Enter Radius value: ");
  59.     scanf("%d", &r);
  60.     y = r;
  61.  
  62.     glutInit(&argc, argv);
  63.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  64.     glutInitWindowSize(300, 300);
  65.     glutInitWindowPosition(100, 100);
  66.     glutCreateWindow("circle");
  67.     init();
  68.     glutDisplayFunc(display);
  69.     glutMainLoop();
  70.     return 0; /* ISO C requires main to return int. */
  71. }
Advertisement
Add Comment
Please, Sign In to add comment