openGPMP
Open Source Mathematics Package
openGL_example00.c
Go to the documentation of this file.
1 
2 // C program to demonstrate
3 // drawing a circle using
4 // OpenGL
5 #include <GL/glut.h>
6 #include <math.h>
7 #include <stdio.h>
8 #define pi 3.142857
9 
10 // function to initialize
11 void myInit(void) {
12  // making background color black as first
13  // 3 arguments all are 0.0
14  glClearColor(0.0, 0.0, 0.0, 1.0);
15 
16  // making picture color green (in RGB mode), as middle argument
17  // is 1.0
18  glColor3f(0.0, 1.0, 0.0);
19 
20  // breadth of picture boundary is 1 pixel
21  glPointSize(1.0);
22  glMatrixMode(GL_PROJECTION);
23  glLoadIdentity();
24 
25  // setting window dimension in X- and Y- direction
26  gluOrtho2D(-780, 780, -420, 420);
27 }
28 
29 void display(void) {
30  glClear(GL_COLOR_BUFFER_BIT);
31  glBegin(GL_POINTS);
32  float x, y, i;
33 
34  // iterate y up to 2*pi, i.e., 360 degree
35  // with small increment in angle as
36  // glVertex2i just draws a point on specified co-ordinate
37  for (i = 0; i < (2 * pi); i += 0.001) {
38  // let 200 is radius of circle and as,
39  // circle is defined as x=r*cos(i) and y=r*sin(i)
40  x = 200 * cos(i);
41  y = 200 * sin(i);
42 
43  glVertex2i(x, y);
44  }
45  glEnd();
46  glFlush();
47 }
48 
49 int main(int argc, char **argv) {
50  glutInit(&argc, argv);
51  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
52 
53  // giving window size in X- and Y- direction
54  glutInitWindowSize(1366, 768);
55  glutInitWindowPosition(0, 0);
56 
57  // Giving name to window
58  glutCreateWindow("Circle Drawing");
59  myInit();
60 
61  glutDisplayFunc(display);
62  glutMainLoop();
63 }
#define pi
int main(int argc, char **argv)
void display(void)
void myInit(void)