pyglet window.flip() 没有更新
pyglet window.flip() not updating
我正在用 pyglet 绘制一个圆圈和一些文本。我希望它在按键后更新,但是在第二次调用 window.flip() 时,window 只是空的。任何建议表示赞赏。
from math import *
from pyglet.gl import *
window = pyglet.window.Window()
def make_circle(x_pos, y_pos, radius, numPoints):
verts = []
glMatrixMode(GL_PROJECTION)
glOrtho(0, 640, 0, 480, -1, 1)
glMatrixMode(GL_MODELVIEW)
glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)
glColor3f(1, 1, 0)
for i in range(numPoints):
angle = radians(float(i) / numPoints * 360.0)
x = radius * cos(angle) + x_pos
y = radius * sin(angle) + y_pos
verts += [x, y]
circle = pyglet.graphics.vertex_list(numPoints, ('v2f', verts))
circle.draw(GL_LINE_LOOP)
def text(x, y, text):
label = pyglet.text.Label(text, font_size=36,
x=x, y=y, anchor_x='left', anchor_y='bottom',
color=(255, 123, 255, 255))
label.draw()
make_circle(5, 5, 100, 10)
text(10, 10, 'Test1')
text(30, 30, 'Text2')
window.flip()
input()
make_circle(5, 5, 22, 10)
text(23, 10, 'This text does not appear')
text(30, 23, 'Neither does this one')
window.flip()
input()
如果您不使用默认的事件循环,那么您必须自己执行事件循环的步骤。调用 .
是不够的
在绘图之前,您必须调用 pyglet.clock.tick()
to signify that one frame has passed and window.dispatch_events()
来轮询操作系统事件队列以查找新事件并调用附加的事件处理程序。
注意,由于事件是手动调度的,因此不需要设置投影矩阵。
另见 Dispatching events manually
例如:
from math import *
from pyglet.gl import *
def make_circle(x_pos, y_pos, radius, numPoints):
verts = []
glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)
glColor3f(1, 1, 0)
for i in range(numPoints):
angle = radians(float(i) / numPoints * 360.0)
x = radius * cos(angle) + x_pos
y = radius * sin(angle) + y_pos
verts += [x, y]
circle = pyglet.graphics.vertex_list(numPoints, ('v2f', verts))
circle.draw(GL_LINE_LOOP)
def text(x, y, text):
label = pyglet.text.Label(text, font_size=36,
x=x, y=y, anchor_x='left', anchor_y='bottom',
color=(255, 123, 255, 255))
label.draw()
window = pyglet.window.Window()
# make OpenGL context current
window.switch_to()
# signify that one frame has passed
pyglet.clock.tick()
# poll the operating system event queue
window.dispatch_events()
make_circle(5, 5, 100, 10)
text(10, 10, 'Test1')
text(30, 30, 'Text2')
# swap buffers
window.flip()
input()
# signify that one frame has passed
pyglet.clock.tick()
# poll the operating system event queue
window.dispatch_events()
make_circle(5, 5, 22, 10)
text(23, 10, 'This text does not appear')
text(30, 23, 'Neither does this one')
# swap buffers
window.flip()
input()
我正在用 pyglet 绘制一个圆圈和一些文本。我希望它在按键后更新,但是在第二次调用 window.flip() 时,window 只是空的。任何建议表示赞赏。
from math import *
from pyglet.gl import *
window = pyglet.window.Window()
def make_circle(x_pos, y_pos, radius, numPoints):
verts = []
glMatrixMode(GL_PROJECTION)
glOrtho(0, 640, 0, 480, -1, 1)
glMatrixMode(GL_MODELVIEW)
glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)
glColor3f(1, 1, 0)
for i in range(numPoints):
angle = radians(float(i) / numPoints * 360.0)
x = radius * cos(angle) + x_pos
y = radius * sin(angle) + y_pos
verts += [x, y]
circle = pyglet.graphics.vertex_list(numPoints, ('v2f', verts))
circle.draw(GL_LINE_LOOP)
def text(x, y, text):
label = pyglet.text.Label(text, font_size=36,
x=x, y=y, anchor_x='left', anchor_y='bottom',
color=(255, 123, 255, 255))
label.draw()
make_circle(5, 5, 100, 10)
text(10, 10, 'Test1')
text(30, 30, 'Text2')
window.flip()
input()
make_circle(5, 5, 22, 10)
text(23, 10, 'This text does not appear')
text(30, 23, 'Neither does this one')
window.flip()
input()
如果您不使用默认的事件循环,那么您必须自己执行事件循环的步骤。调用
是不够的
在绘图之前,您必须调用 pyglet.clock.tick()
to signify that one frame has passed and window.dispatch_events()
来轮询操作系统事件队列以查找新事件并调用附加的事件处理程序。
注意,由于事件是手动调度的,因此不需要设置投影矩阵。
另见 Dispatching events manually
例如:
from math import *
from pyglet.gl import *
def make_circle(x_pos, y_pos, radius, numPoints):
verts = []
glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)
glColor3f(1, 1, 0)
for i in range(numPoints):
angle = radians(float(i) / numPoints * 360.0)
x = radius * cos(angle) + x_pos
y = radius * sin(angle) + y_pos
verts += [x, y]
circle = pyglet.graphics.vertex_list(numPoints, ('v2f', verts))
circle.draw(GL_LINE_LOOP)
def text(x, y, text):
label = pyglet.text.Label(text, font_size=36,
x=x, y=y, anchor_x='left', anchor_y='bottom',
color=(255, 123, 255, 255))
label.draw()
window = pyglet.window.Window()
# make OpenGL context current
window.switch_to()
# signify that one frame has passed
pyglet.clock.tick()
# poll the operating system event queue
window.dispatch_events()
make_circle(5, 5, 100, 10)
text(10, 10, 'Test1')
text(30, 30, 'Text2')
# swap buffers
window.flip()
input()
# signify that one frame has passed
pyglet.clock.tick()
# poll the operating system event queue
window.dispatch_events()
make_circle(5, 5, 22, 10)
text(23, 10, 'This text does not appear')
text(30, 23, 'Neither does this one')
# swap buffers
window.flip()
input()