PyOpenGL3.0について

PyOpenGLはOpenGLPythonで扱うためのライブラリです。

PyOpenGL3.0のインストール

PyOpenGL3.0の公式サイトhttp://pyopengl.sourceforge.net/documentation/installation.html
Downloads>PyOpenGLからダウンロード。PyOpenGL-3.0.1.win32.exeを起動するとすぐにインストール終了。

PyOpenGLの簡単なサンプル

黒画面に三角形を表示するだけのサンプルです。OpenGLの関数をそのまま利用することができます。
InitGLでOpenGLの初期化、DrawGLSceneで描画を行っています。

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

def init():                
    glClearColor(0.0, 0.0, 0.0, 0.0) 
      
def display():
    glClear(GL_COLOR_BUFFER_BIT)
    glBegin(GL_TRIANGLE_STRIP)
    glVertex2d(0.,0.)
    glVertex2d(0.7,0.7)
    glVertex2d(0.,0.7)
    glEnd()

    #double buffer
    glutSwapBuffers()

def main():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)
    glutInitWindowSize(400, 300)
    glutInitWindowPosition(0, 0)

    glutCreateWindow("PyOpenGL")
    glutDisplayFunc(display)
    init()
    glutMainLoop()

main()