Lyrical digression
A couple of months ago, I decided to study Python. But ... just after pushing in all this Wednesday, I had a choice: to learn about the new python3 or python2.7. The choice fell towards python 3, even if only a small amount of what is already under python2.7 works on it, and it was just interesting to participate in the development of the language.
Recently, there was a need to visualize some data (in openGL), so it was decided to figure out what and how, put the pieces together and tell the audience about it.
The article is primarily aimed at newbies in python (like me), and is written in the style of “install this and that,” so please old-timers not to throw slippers and treat with understanding.
Getting ready
Since we have to build libraries, we need to install
python3-dev . We need
python3-setuptools to install
easy_install3 .
We put:
sudo apt-get install python3-dev python3-setuptools
Now you can build libraries.
Libraries
Install pip for python3 through the installed
easy_install3 :
sudo easy_install3 pip
pip is installed, now we can build the libraries we need:
sudo pip-3.2 install numpy PyOpenGL PyOpenGL_accelerate
(at the time of installation the actual version of pip was 3.2, in the past, future or parallel universe this number may differ).
To use the OpenGL.GLUT module, set freeglut:
sudo apt-get install freeglut3
Now everything is ready, and you can try to run the examples.
Not so simple
Go to the site
http://nehe.gamedev.net/tutorial , study the examples, download the code in python, check the performance on python2.7 (if the OpenGL libraries for pytohn2.7 are installed - everything is done in the same way, pip
install numpy PyOpenGL PyOpenGL_accelerate
) .
Swing, for example, the
second example , check:

trying to run it on python3, we get the error:
$ python3 lesson02.py File "lesson02.py", line 153 print "Hit ESC key to quit." ^ SyntaxError: invalid syntax
We recycle it using the 2to3 utility (at first, this is adding parentheses to
print
):
RefactoringTool: Skipping implicit fixer: buffer RefactoringTool: Skipping implicit fixer: idioms RefactoringTool: Skipping implicit fixer: set_literal RefactoringTool: Skipping implicit fixer: ws_comma RefactoringTool: Refactored test.py --- lesson02.py (original) +++ lesson02.py (refactored) @@ -150,6 +150,6 @@ glutMainLoop() # Print message to console, and kick off the main to get it rolling. -print "Hit ESC key to quit." +print("Hit ESC key to quit.") main() RefactoringTool: Files that need to be modified: RefactoringTool: lesson02.py
, but here we are in for a surprise:
Hit ESC key to quit. Traceback (most recent call last): File "lesson02.py", line 154, in <module> main() File "lesson02.py", line 109, in main glutInit(()) File "/usr/local/lib/python3.2/dist-packages/OpenGL/GLUT/special.py", line 318, in glutInit holder[i] = arg TypeError: bytes or integer address expected instead of str instance
To make everything soar, we need to pass command line arguments to glutInit ():
glutInit(sys.argv)
Run again:
Hit ESC key to quit. Traceback (most recent call last): File "test.py", line 154, in <module> main() File "test.py", line 127, in main window = glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99") ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
So-so-so, and this is what else ... After a short googling, we find that the window title should be a byte string, respectively, we add “b” before the line:
window = glutCreateWindow(b"Ura, vzletelo!")
And about happiness!
')

Unfortunately, Russian letters do not support (I didn’t need much, so I didn’t understand).
Well, you can enjoy working OpenGL on our horse :)

Link to archive with files:
DropboxThank you for your attention, I hope this article will help someone. I am pleased to accept criticism and suggestions.
Sources
Many thanks to the materials from the site
http://nehe.gamedev.net/