Raspberry Pi + Python + OpenGL memo

environment

setup

sudo apt-get install python-opengl
pip install pyopengl

If you want to put Pillow because you want to display an image

sudo apt-get install libjpeg-dev
pip install Pillow

Also keep

Operation check

Try running the code at 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 if the window comes up

Where I was addicted

pip install pyopengl

If only, the following error will occur when executing the above sample

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

It is said that OpenGL originally included in Raspberry Pi is OpenGL ES2, and I imagine that this is the case because OpenGL ES2 cannot use GLUT. Solved by putting python-opengl with apt-get like setup.

Recommended Posts

Raspberry Pi + Python + OpenGL memo
Raspberry Pi 4 setup memo
Make DHT11 available on Raspberry Pi + python (memo)
raspberry pi 1 model b, python
Python memo
python memo
Python memo
python memo
Python memo
Python memo
Python memo
Use vl53l0x with Raspberry Pi (python)
Install ghoto2 on Raspberry Pi (memo)
[Raspberry Pi] Changed Python default to Python3
python beginner memo (9.2-10)
Detect "brightness" using python on Raspberry Pi 3!
python beginner memo (9.1)
Raspberry Pi Security Infrared Camera (Python Edition)
Adafruit Python BluefruitLE works on Raspberry Pi.
Raspberry Pi backup
Python + GLFW + OpenGL
★ Memo ★ Python Iroha
[Python] EDA memo
Python 3 operator memo
Run servomotor on Raspberry Pi 3 using python
[My memo] python
Python3 metaclass memo
[Python] Basemap memo
Detect temperature using python on Raspberry Pi 3!
Python beginner memo (2)
[Python] Numpy memo
Working with GPS on Raspberry Pi 3 Python
Discord bot with python raspberry pi zero with [Notes]
Detect slide switches using python on Raspberry Pi 3!
[Amateur remarks] Raspberry Pi 3, Wordpress vs Raspberry Pi 3, python, Django
How to use Raspberry Pi pie camera Python
I tried L-Chika with Raspberry Pi 4 (Python edition)
Detect magnet switches using python on Raspberry Pi 3!
Get CPU information of Raspberry Pi with Python
Sound the buzzer using python on Raspberry Pi 3!
Serial communication between Raspberry pi --Arduino Uno (Python)
Connect to MySQL with Python on Raspberry Pi
Build a Python development environment on Raspberry Pi
GPS tracking with Raspberry Pi 4B + BU-353S4 (Python)
Measure CPU temperature of Raspberry Pi with Python
Python class (Python learning memo ⑦)
My python environment memo
python openCV installation (memo)
Python module (Python learning memo ④)
What is Raspberry Pi?
Visualization memo by Python
Python test package memo
pigpio on Raspberry pi
[Python] Memo about functions
Raspberry Pi video camera
Binary search (python2.7) memo
[My memo] python -v / python -V
Python3 List / dictionary memo
[Memo] Python3 list sort
Python Tips (my memo)
Raspberry Pi Bad Knowledge