LoginSignup
7
13

More than 5 years have passed since last update.

ラズパイ + Python + OpenGL メモ

Posted at

環境

セットアップ

sudo apt-get install python-opengl
pip install pyopengl

もし画像を表示したいなどで Pillow を入れたい場合

sudo apt-get install libjpeg-dev
pip install Pillow

もしておく

動作確認

http://tomosoft.jp/design/?p=9152 のコードを動かしてみる

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys

def display():
    glClear(GL_COLOR_BUFFER_BIT)
    glFlush()


def main():
    glutInit(sys.argv)
    glutInitWindowSize(300, 300)
    glutInitDisplayMode(GLUT_RGBA)
    glutCreateWindow(b"OpenGL")

    glutDisplayFunc(display)
    glClearColor(0.0, 0.0, 0.0, 1.0)
    glutMainLoop()

    return 0


if __name__ == "__main__":
    main()

ウィンドウが立ち上がれば OK

ハマったところ

pip install pyopengl

のみだと、上記サンプル実行時に以下のようなエラーが起こる

Traceback (most recent call last):
  File "gltest.py", line 25, in <module>
    main()
  File "gltest.py", line 12, in main
    glutInit(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/PyOpenGL-3.1.1a1-py2.7.egg/OpenGL/GLUT/special.py", line 333, in glutInit
    _base_glutInit( ctypes.byref(count), holder )
  File "/usr/local/lib/python2.7/dist-packages/PyOpenGL-3.1.1a1-py2.7.egg/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

ラズパイに元々入っている OpenGL は OpenGL ES2 だという話しがあり、 OpenGL ES2 は GLUT を使えないのでこのようなことになっているのではないかと想像している。
セットアップ のように python-opengl を apt-get で入れて解決。

7
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
13