[PYTHON] Try PyOpenGL

Try OpenGL using Python on modern Windows.

environment

I worked on Windows 10 (64bit).

Python is

https://www.continuum.io/downloads

Select Python 3.5 (64bit) from the Anaconda distribution distributed in. In Anaconda, numpy etc. are included from the beginning, so this is good for Windows.

Install PyOpenGL

At first, I piped as below,

> C:\Anaconda3\Scripts\pip.exe install PyOpenGL PyOpenGL-Demo

The Anaconda distribution seems to do this.

> C:\Anaconda3\Scripts\conda.exe install pyopengl

Confirmed operation with PyOpenGL-Demo

Download the archive from and unzip it.

> cd PyOpenGL-Demo-3.0.1b1\PyOpenGL-Demo
PyOpenGL-Demo-3.0.1b1\PyOpenGL-Demo> dir

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2016/03/19      2:27                da
d-----       2016/03/19      2:27                dek
d-----       2016/03/19      2:27                GLE
d-----       2016/03/19      2:27                GLUT
d-----       2016/03/19      2:27                NeHe
d-----       2016/03/19      2:27                proesch
d-----       2016/03/19      2:27                redbook
d-----       2016/03/19      2:27                tom
-a----       2008/12/08     12:25              0 readme.txt
-a----       2008/12/08     12:25              0 __init__.py

Let's go to NeHe.

PyOpenGL-Demo-3.0.1b1\PyOpenGL-Demo> cd NeHe
PyOpenGL-Demo-3.0.1b1\PyOpenGL-Demo\Nehe> C:\Anaconda3\python.exe .\lesson1.py
  File ".\lesson1.py", line 141
    print "Hit ESC key to quit."
                               ^
SyntaxError: Missing parentheses in call to 'print'

Oh, python2 spec. But,

PyOpenGL-Demo-3.0.1b1\PyOpenGL-Demo\Nehe> C:\Anaconda3\Scripts\2to3.exe -w .
PyOpenGL-Demo-3.0.1b1\PyOpenGL-Demo\Nehe> C:\Anaconda3\python.exe .\lesson1.py
Traceback (most recent call last):
  File ".\lesson1.py", line 8, in <module>
    __version__ = string.split('$Revision: 1.1.1.1 $')[1]
AttributeError: module 'string' has no attribute 'split'

Comment out

#__version__ = string.split('$Revision: 1.1.1.1 $')[1]
#__date__ = string.join(string.split('$Date: 2007/02/15 19:25:19 $')[1:3], ' ')
#__author__ = 'Tarn Weisner Burton <[email protected]>'

again.

PyOpenGL-Demo-3.0.1b1\PyOpenGL-Demo\Nehe> C:\Anaconda3\python.exe .\lesson1.py
Hit ESC key to quit.
Traceback (most recent call last):
  File ".\lesson1.py", line 142, in <module>
    main()
  File ".\lesson1.py", line 97, in main
    glutInit(sys.argv)
  File "C:\Anaconda3\lib\site-packages\OpenGL\GLUT\special.py", line 333, in glutInit
    _base_glutInit( ctypes.byref(count), holder )
  File "C:\Anaconda3\lib\site-packages\OpenGL\platform\baseplatform.py", line 407, in __call__
    self.__name__, self.__name__,
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

There is no glut.

Add Glut.

https://charmie11.wordpress.com/2015/09/28/pyopengl-installation-using-anaconda/

I see.

http://ktm11.eng.shizuoka.ac.jp/lesson/modeling.html I got glut32.dll (64bit) from and copied it to C: \ Windows \ System32.

The error remains the same. I followed the code.

# C:\Anaconda3\Lib\site-packages\OpenGL\platform\win32.py
  def GLUT( self ):
        for possible in ('freeglut%s'%(size,),'freeglut', 'glut%s'%(size,)):
            # Prefer FreeGLUT if the user has installed it, fallback to the included 
            # GLUT if it is installed
            try:
                return ctypesloader.loadLibrary(
                    ctypes.windll, possible, mode = ctypes.RTLD_GLOBAL
                )
            except WindowsError as err:
                pass
        return None

I'm looking for a dll but I'm looking for glut64. I put it in C: \ Windows \ System32 \ glut64.dll. again.

PyOpenGL-Demo-3.0.1b1\PyOpenGL-Demo\Nehe> C:\Anaconda3\python.exe .\lesson1.py
Hit ESC key to quit.
Traceback (most recent call last):
  File ".\lesson1.py", line 142, in <module>
    main()
  File ".\lesson1.py", line 115, in main
    window = glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99")
  File "C:\Anaconda3\lib\site-packages\OpenGL\GLUT\special.py", line 73, in glutCreateWindow
    return __glutCreateWindowWithExit(title, _exitfunc)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

The error has changed.

Pass the Python3 Unicode string to glutCreateWindow

115


window = glutCreateWindow(b"Jeff Molofee's GL Code Tutorial ... NeHe '99")

Add b to make a byte string. I passed. A black window came out.

There was a teapot sample, so ss. teapots.png

The rework is the same as NeHe. This method is also possible.

glutCreateWindow(sys.argv[0].encode('ascii'))

It was PyOpenGL after a long time, but the environment was created for the time being. Next time, I will maintain my glglue (unfriendly and I don't know how to use it) for python3, and then the procedure for Shader and VertexBuffer. I plan to check.

Recommended Posts

Try PyOpenGL
Try python
try pysdl2
Try touching libtaxii
Try using Tkinter
Try using docker-py
Try numpy.random Generator
Try Distributed TensorFlow
Try using cookiecutter
Try using geopandas
Try using Selenium
Try using scipy
Python> try: / except:
Try installing Polynote
Try using pandas.DataFrame
Try type hints
Try using django-swiftbrowser
Try using matplotlib
Try using tf.metrics
Try installing chainer-gogh
Try moving deepdream
Try using PyODE
Try running Pyston 0.1
Try building PySide2