Advertisement
Guest User

uthan

a guest
Feb 22nd, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include<windows.h>
  2. #include<iostream>
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<string.h>
  6. #include<math.h>
  7. #include<GL/gl.h>
  8. #include<GL/glu.h>
  9. #include<GL/glut.h>
  10.  
  11.  
  12. const int screenWidth = 640*2;
  13. const int screenHeight = 480*2;
  14. GLdouble A,B,C,D; // values for scaling and shifting
  15.  
  16. void myInit(void)
  17. {
  18. glClearColor(1.0, 1.0, 1.0, 0.0); //background color is white
  19. glColor3f(0.0f, 0.0f, 0.0f); //drawing color is black
  20. glPointSize(4.0); //a dot is 2 by 2 pixels
  21. glLineWidth(4.0); //a line is 4 times thicker
  22.  
  23.  
  24. //initialize view (simple orthographic projection)
  25. glMatrixMode(GL_PROJECTION);
  26. glLoadIdentity();
  27. glOrtho(-1.0,1.0,-1.0, 1.0, -1.0, 1.0);
  28.  
  29. A = screenWidth/4.0; //Set values for scaling and shifting
  30. B= 0.0;
  31. C=D=screenHeight/2.0;
  32.  
  33. //set the viewing coordinates
  34. gluOrtho2D(0.0, 640.0, 0.0, 480.0);
  35. }
  36.  
  37. void myDisplay(void)
  38. {
  39. glClear(GL_COLOR_BUFFER_BIT); //clear the screen
  40. // glRecti(10,10,150,60); //draw a rectangle with background color
  41.  
  42.  
  43. glPointSize(2.0);
  44.  
  45.  
  46. GLint h = 300, k = 300, x, x2, y, i = 1, a = 150, b = 25;
  47.  
  48. x2 = a;
  49.  
  50. for(x=1;x<=x2;x++)
  51. {
  52. y = b * sqrt(1 - (pow(x,2)/pow(a,2)));
  53.  
  54. glBegin(GL_POINTS);
  55. {
  56.  
  57. glVertex2i(x+h,y+k);
  58. glVertex2i(-x+h,-y+k);
  59. glVertex2i(-x+h,y+k);
  60. glVertex2i(x+h,-y+k);
  61. }
  62. glEnd();
  63. }
  64.  
  65. glFlush(); //send all output to display
  66. }
  67.  
  68.  
  69. int main(int argc, char** argv)
  70. {
  71. glutInit(&argc, argv); //initialize the toolkit
  72. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //set the display mode
  73. glutInitWindowSize(640,480); //set window size
  74. //set window position on screen
  75. glutInitWindowPosition(100,150);
  76. //open the screen window and set the name
  77. glutCreateWindow("My First Window");
  78.  
  79. //register the callback functions
  80. glutDisplayFunc(myDisplay);
  81.  
  82. myInit();
  83. glutMainLoop(); //go into a perpetual loop
  84.  
  85. return 1;
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement