Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

OpenGL installation in Python

OpenGL is an application programming interface also we call it API which is merely software
library for accessing features in graphic hardware and also OpenGL is designed as streamlined,
hardware independent interface that can be implemented on many different types of graphic
hardware systems.

OpenGL is a graphics library which is supported by multiple platforms including Windows,


Linux, and MacOS, and is available for use in multiple other languages as well; however, the
scope of this post will be limited to its usage in the Python programming language.

OpenGL, as compared to other similar graphics libraries, is fairly simple. We'll start with setting
it up on our system, by following below procedure to add it library in our system.

1) Install python setup or interpreter


2) Install a software used for writing/editing programming language such as PyCharm,
Visual Studio
3) If you are running 64-bit windows, use the following procedure to install PyOpenGL. In
your Environment.
To properly install, follow these steps:
1. Don’t install PyOpenGL using(pip install PyOpenGL PyOpenGL_accelerate) or if
you installed previously from online website of the library of a python, Uninstall
existing PyOpenGL, to Uninstall use (pip uninstall PyOpenGL
PyOpenGL_accelerate)
2. Download the 64-bit builds of PyOpenGL and PyOpenGL accelerate from
here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl
3. How to choose which one to download? Well, first you need to check your python
version. Run python --version to determine.
Then according to your version download the .whl files for PyOpenGL and
PyOpenGL accelerate.
For example, if you have Python 3.11, download these 2 files:
PyOpenGL-3.1.6-cp311-cp311-win_amd64.whl
PyOpenGL_accelerate-3.1.6-cp311-cp311-win_amd64.whl

Similarly, if you run Python 3.9, download these instead:


PyOpenGL-3.1.5-cp39-cp39-win_amd64.whl
PyOpenGL_accelerate-3.1.5-cp39-cp39-win_amd64.whl

Note: Must download amd64 ones, after all, you're running 64-bit windows and also
if you're running 32-bit windows follow the same procedure except you have to
download win32 of PyOpenGL and PyOpenGL_accelerate from the same link. And
then follow the same steps.
4. Now go to the folder where you downloaded the files and run power shell/command
prompt(cmd) with administrator there.
5. Use pip to force install those files. For example:
pip install PyOpenGL-3.1.6-cp311-cp311-win_amd64.whl --force-reinstall
pip install PyOpenGL_accelerate-3.1.6-cp311-cp311-win_amd64.whl --force-
reinstall
Note: Install PyOpenGL first and then PyOpenGL_accelerate
6. If the installation succeeds, you may be able now to run.
It is necessary to restart your desktop if you reinstall any one of them (Python,
OpenGL)
Example:
 Let start the first program: to start our task firstly we have to import the following libraries
from OpenGL.GLUT import *
from OpenGL.GL import *
from OpenGL.GLU import *

 Then the program is started its task from this place:


glutInit() # Initialize a glut instance which will allow us to customize our window
glutInitDisplayMode(GLUT_RGBA) # Set the display mode to be colored
glutInitWindowSize(500, 500) # Set the width and height of your window
glutInitWindowPosition(0, 0) # Set the position at which this windows should appear
from computer screen
wind = glutCreateWindow("OpenGL Coding Practice") # Give your window a title
glutDisplayFunc(showScreen) # Tell OpenGL to call the showScreen method
continuously, this is the place of our tasks are displayed in it (showScreen is calling
method/function).
glutIdleFunc(showScreen) # Draw any graphics or shapes in the showScreen
function at all times
glutMainLoop() # Keeps the window created above displaying/running in a loop

 Now, if we wish to draw any shapes or make any other kind of graphics, we need to do
that in our "showScreen" function/method.

You might also like