やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

PyOpenGL-Demoのコードを手直ししてPython3で実行してみた

3Dデモが動くかどうか。

開発環境

  • Linux Mint 17.3 MATE 32bit
  • pyenv 1.0.10
    • Python 3.6.1
      • PyOpenGL (3.1.0)
      • PyOpenGL-accelerate (3.1.0)
      • PyOpenGL-Demo (3.0.0)
      • numpy (1.13.1)
      • pygame (1.9.3)
      • pgu (0.18)

前回まで

前回lesson1.pyと同様に修正し、他のコードも動かしてみた。

lesson2.py

f:id:ytyaru:20170716134647p:plain

lesson3.py

f:id:ytyaru:20170716135041p:plain

lesson4.py

f:id:ytyaru:20170716135104p:plain

Y軸、X軸を中心に回転アニメーション。

lesson5.py

f:id:ytyaru:20170716135343p:plain

3Dの三角柱と立方体が回転アニメーション。

lesson6.py

$ python lesson6.py 
Traceback (most recent call last):
  File "lesson6.py", line 52, in <module>
    from Image import *
ModuleNotFoundError: No module named 'Image'

おそらくPillow(Python Imaging Library)ライブラリが必要と思われる。後回し。

lesson11.py

f:id:ytyaru:20170716135917p:plain

網目上のオブジェクトが揺らめくアニメーション。

lesson12.py

f:id:ytyaru:20170716140117p:plain

lesson13.py

バグ1

$ python lesson13.py 
  File "lesson13.py", line 155
    glPrint("Active OpenGL Text With NeHe - %7.2f" %(cnt1)); # // Print GL Text To The Screen
                                                                                            ^
TabError: inconsistent use of tabs and spaces in indentation

行の先頭に半角スペースが1つ入っていてエラーになっていた。というか、ハードタブでインデントしている……。たしかPythonではハードタブは自動的に半角スペース8つに置き換えられて予期せぬインデント不具合になる可能性があるから半角スペースでインデントするのが作法だと思うのだが。

バグ2

$ python lesson13.py 
  File "lesson13.py", line 43
    True = 1==1
    ^
SyntaxError: can't assign to keyword
# *********************** Globals *********************** 
# Python 2.2 defines these directly
try:
    True
except NameError:
    True = 1==1
    False = 1==0

Python3ではTrue,False予約語になっている。まとめてコメントアウトする。

バグ3

$ python lesson13.py 
Traceback (most recent call last):
  File "lesson13.py", line 32, in <module>
    from OpenGL.WGL import *    # wglUseFontBitmaps (), wglGetCurrentDC ()
  File "/media/mint/85f78c06-a96e-4020-ac36-9419b7e456db/mint/root/tools/pyenv/3.6.1/venv/game/lib/python3.6/site-packages/OpenGL/WGL/__init__.py", line 1, in <module>
    from OpenGL.raw.WGL.VERSION.WGL_1_0 import *
  File "/media/mint/85f78c06-a96e-4020-ac36-9419b7e456db/mint/root/tools/pyenv/3.6.1/venv/game/lib/python3.6/site-packages/OpenGL/raw/WGL/VERSION/WGL_1_0.py", line 48, in <module>
    @_p.types(_cs.c_int,_cs.HDC,ctypes.POINTER(_cs.PIXELFORMATDESCRIPTOR))
  File "/media/mint/85f78c06-a96e-4020-ac36-9419b7e456db/mint/root/tools/pyenv/3.6.1/venv/game/lib/python3.6/site-packages/OpenGL/raw/WGL/VERSION/WGL_1_0.py", line 13, in _f
    return _p.createFunction( function,_p.PLATFORM.WGL,'WGL_VERSION_WGL_1_0',error_checker=_errors._error_checker)
AttributeError: 'GLXPlatform' object has no attribute 'WGL'

WGLというキーワードが見えた。WGLはおそらくグラフィックボード固有の機能なのだろう。古いマシンやノートPCには存在しない可能性がある。

lesson16.py

$ python lesson16.py 
Traceback (most recent call last):
  File "lesson16.py", line 8, in <module>
    from Image import *
ModuleNotFoundError: No module named 'Image'

おそらくPillow(Python Imaging Library)ライブラリが必要と思われる。後回し。

lesson18.py

$ python lesson18.py 
Traceback (most recent call last):
  File "lesson18.py", line 52, in <module>
    from Image import *
ModuleNotFoundError: No module named 'Image'

おそらくPillow(Python Imaging Library)ライブラリが必要と思われる。後回し。

lesson19.py

$ python lesson19.py 
Traceback (most recent call last):
  File "lesson19.py", line 10, in <module>
    from Image import *
ModuleNotFoundError: No module named 'Image'

おそらくPillow(Python Imaging Library)ライブラリが必要と思われる。後回し。

lesson23.py

$ python lesson23.py 
Traceback (most recent call last):
  File "lesson23.py", line 10, in <module>
    from Image import *
ModuleNotFoundError: No module named 'Image'

おそらくPillow(Python Imaging Library)ライブラリが必要と思われる。後回し。

lesson26.py

$ python lesson26.py 
Traceback (most recent call last):
  File "lesson26.py", line 7, in <module>
    from Image import *
ModuleNotFoundError: No module named 'Image'

おそらくPillow(Python Imaging Library)ライブラリが必要と思われる。後回し。

lesson41.py

$ python lesson41.py 
  File "lesson41.py", line 56
    True = 1==1
    ^
SyntaxError: can't assign to keyword
$ python lesson41.py 
Traceback (most recent call last):
  File "lesson41.py", line 45, in <module>
    import Image                # PIL
ModuleNotFoundError: No module named 'Image'

lesson42.py

$ python lesson42.py 
  File "lesson42.py", line 86
    True = 1==1
    ^
SyntaxError: can't assign to keyword

実行エラー

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 234, in 'calling callback function'
  File "lesson42.py", line 269, in DrawGLScene
    glViewport (0, window_height/2, window_width/2, window_height/2);
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

もしやPython2だとintになるが、Python3だとfloatになるエラーか?

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 234, in 'calling callback function'
  File "lesson42.py", line 308, in DrawGLScene
    glTexCoord2f(1.0, 0.0);     glVertex2i(window_width/2, 0              );
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

f:id:ytyaru:20170716143616p:plain

lesson45.py

$ python lesson45.py 
  File "lesson45.py", line 83
    True = 1==1
    ^
SyntaxError: can't assign to keyword
$ python lesson45.py 
Traceback (most recent call last):
  File "lesson45.py", line 66, in <module>
    import Image                # PIL
ModuleNotFoundError: No module named 'Image'

所感

Pillow(PIL)がなくて動作しないのが多かった。その昔Python2ではPILだったが、現在はPillowプロジェクトになっている。はたしてPillowで動作するのか?