PyOpenGL はじめました:glutDisplayFunc
PyOpenGL はじめました《記事一覧》
glutDisplayFunc
《著》小粒ちゃん《監修》小泉ひよ子とタマゴ倶楽部
第0版♪2006/09/21 ● 第1版♪2009/04/07
■ 概要
glutDisplayFunc:ウィンドウを再描画する関数を設定します。
■ 関連記事
GLUT | API:英 | API:和 | Description |
---|---|---|---|
glutDisplayFunc | 7.1 glutDisplayFunc | 7.1 glutDisplayFunc | sets the display callback for the current window. |
□□□□□□□□□ | □ | □ | □□□□□□ |
概要:glutDisplayFunc
$ python2.5 -i glutDisplayFunc.py >>> print glutDisplayFunc.__doc__ Specify handler for GLUT 'Display' events def handler( ): return None
イベント Display に呼応してウィンドウ内を再描画する、イベントハンドラー handler が必要です。これは、引数を持たず、値を返さない(None をリターン値とする)関数です。すると、ウィンドウを開いたり、背後に隠れていたウィンドウ(その一部)が前面に現れるときに、イベントハンドラー関数を呼び出します。
class PyoWindow(object): def glut_Func(self, model): ... glutDisplayFunc(model.display) # ._model.display ...
以下の事例では、この関数を再利用しています。
事例:背景を塗り潰す
$ python2.5 -i glutDisplayFunc.py
>>> ex_glutDisplayFunc.ex1()
class ex_glutDisplayFunc(PyoModel): @classmethod def ex1(self): def display(): glClearColor(1.0, 1.0, 0.0, 0.0) # 背景を塗り潰す:黄色 glClear(GL_COLOR_BUFFER_BIT) glFinish() model = ex_glutDisplayFunc() model.display = display model.open(800,100,200,100, displayMode = GLUT_RGB | GLUT_DEPTH, )
事例:図形を描く
$ python2.5 -i glutDisplayFunc.py
>>> ex_glutDisplayFunc.ex2()
@classmethod
def ex2(self):
def display():
glClear(GL_COLOR_BUFFER_BIT)
glBegin(GL_LINE_LOOP) # 折れ線を閉じる
glColor3d (0.0, 1,0, 0,0)
glVertex2d(-0.5, -0.5)
glVertex2d( 0.5, -0.5)
glVertex2d( 0.5, 0.5)
glVertex2d(-0.5, 0.5)
glEnd()
glFinish()
...
事例:グラデーションを描く
$ python2.5 -i glutDisplayFunc.py
>>> ex_glutDisplayFunc.ex3()
@classmethod
def ex3(self):
def display():
glClear(GL_COLOR_BUFFER_BIT)
glBegin(GL_POLYGON) # 多角形を描く
glColor3d(1.0, 0.0, 0.0)
glVertex3d( 0.0, 0.8, 0.0)
glColor3d(1.0, 1.0, 0.0)
glVertex3d(-0.69282, 0.4, 0.0)
glColor3d(0.0, 1.0, 0.0)
glVertex3d(-0.69282, -0.4, 0.0)
glColor3d(0.0, 1.0, 1.0)
glVertex3d( 0.0, -0.8, 0.0)
glColor3d(0.0, 0.0, 1.0)
glVertex3d( 0.69282, -0.4, 0.0)
glColor3d(1.0, 0.0, 1.0)
glVertex3d( 0.69282, 0.4, 0.0)
glEnd()
glFinish()
...
事例:グラデーションを描く #2
$ python2.5 -i glutDisplayFunc.py
>>> ex_glutDisplayFunc.ex4()
@classmethod
def ex4(self):
def display():
glClear(GL_COLOR_BUFFER_BIT)
glEnableClientState(GL_COLOR_ARRAY)
glEnableClientState(GL_VERTEX_ARRAY)
glColorPointer(3, GL_FLOAT, 0, [
1.0, 0.0, 0.0,
1.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 1.0,
0.0, 0.0, 1.0,
1.0, 0.0, 1.0,
])
glVertexPointer(3, GL_FLOAT, 0, [
0.0, 0.8, 0.0,
-0.69282, 0.4, 0.0,
-0.69282, -0.4, 0.0,
0.0, -0.8, 0.0,
0.69282, -0.4, 0.0,
0.69282, 0.4, 0.0,
])
glDrawElements(GL_POLYGON, 6, GL_UNSIGNED_BYTE, [ # 多角形を描く
0, 1, 2, 3, 4, 5,
])
glutSwapBuffers()
...
misc
from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * from sys import argv class PyoWindow(object): def _title(self): s = argv[0].split("/") return s[-1][:-3] def _keyboard(self, *args): key, x, y = args if key == '\x1b': # escape exit()
Tips
》作業中です《
Last updated♪09/05/15