OpenGL is a cross-language, cross-platform API for rendering 2D and 3D Vector Graphics. Using this, we can make a lot of design as well as animations. Below is the simple animation made using OpenGL.
To make a picture moving, we need to understand the working procedure of a function used to display i.e glClear(GL_COLOR_BUFFER_BIT). Its task is to clear screen with default value after a certain time (normally, after 1/30 sec or 1/60 sec). So, if any change of coordinate happens, then it will appear to be moving as human eye can distinguish image only which is separated by 1/16 second (persistence of vision).
Now, the coordinates of circle are X = r*cos(θ) and Y = r*sin(θ) or for ellipse X = rx*cos(θ) and Y = ry*cos(θ) where rx and ry are radius in X- and Y- direction and θ is the angle.
If we vary θ from 0 to 2*pi (360 degree) at very small increase (say of 1 degree) and draw point on that coordinate, we can make a complete circle or ellipse. We can also make semi-circle or any arc of circle or ellipse by varying the starting and ending value of θ (angle).
These concepts are used to draw the following Animation:
- 7 horizontal parts of ellipse and 3 vertical complete ellipse as well as 1 outer circle and one outer ellipse are used to visualise an orbit drawn by adjusting the θ as well as radius.
- One vertical line is drawn to make the figure. Then to make it move, an oter loop is given where value of j changes with very small amount to make the motion smoother.
- Since, we had to make all point moving in same type of motion to keep the figure together, so equation of motion, that is, glVertex2i(x/2 – 600*cos(j), y/2 – 100*sin(j)) is given inside every inner for loop, so that it can be applied to all points altogether.
For working on Ubuntu operating system:
gcc filename.c -lGL -lGLU -lglut -lm where filename.c is the name of the file with which this program is saved.
Below is the implementation in C.
This article is contributed by Aditya Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- OpenGL program for Simple Ball Game
- Getting started with OpenGL
- Rendering a Triangle using OpenGL(using Shaders)
- Scan-line Polygon filling using OPENGL in C
- Computer Animation
- Principles Of Animation
- scanf() and fscanf() in C - Simple Yet Poweful
- C program to print a string without any quote (singe or double) in the program
- Hello World Program : First program while learning Programming
- C program to detect tokens in a C program
- Program to compute Log n
- How to compile 32-bit program on 64-bit gcc in C and C++
- How does a C program executes?
- Output of C Program | Set 29
- Splint -- A C program verifier