当我运行我的演示程序时,键盘输入工作正常,但当我按下键盘上的键时,屏幕会闪烁。它是随机发生的,不仅仅是当我按下按键时,而且还发布在发布时。
这是我的渲染功能:
@self.win.event
def on_draw():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #clear backbuffer and z-buffer
#calculate view matrix
viewMatrix = self.lookat(self.cameraPos, self.cameraTarget, self.cameraUp)
texnum = -1 #set texture to default
shader = '' #set shader to default
modelMatrixNum = -1 #set model matrix to default
glEnable(GL_TEXTURE_2D) #enable textures
for render in self.renderList: #loop through poly lists in renderList
try:
if render['tex'] != texnum: #if this poly list is using a different texture,
texnum = render['tex'] #bind it, and reset default
glBindTexture(GL_TEXTURE_2D, texnum)
except KeyError: #but if it doesn't have a texture
pass #just use the last one
try:
if shader != render['shd']: #if this poly list is using a different shader,
shader = render['shd']
self.shaders[shader].UseProgram() #change shader
self.shaders[shader].SetViewMatrix(viewMatrix)
self.shaders[shader].SetProjectionMatrix(self.projectionMatrix)
self.shaders[shader].SetColorMatrix(self.colorMatrix)
except KeyError: #but if it doesn't have a shader
pass #just use the last one
#now, calculate matrices that vary for each polygon and write them
try:
modelMatrix = render['mod'] #see if this polygon has any special modeling matrix
except KeyError:
#if not, just use the identity matrix
modelMatrix = np.identity(4)
# Set uniforms in shader program
self.shaders[shader].SetModelMatrix(modelMatrix)
# Write matrices
self.shaders[shader].WriteMatrices()
render['vrt'].draw(render['prm']) #actually draw polygon
glDisable(GL_TEXTURE_2D)
self.renderList = [] #clear renderList for next loop
这些是我的输入功能(他们只是显示输入VKID):
@self.win.event
def on_key_press(symbol, modifiers):
print symbol
@self.win.event
def on_key_release(symbol, modifiers):
print symbol
我该如何解决这个问题?还有其他人有这个问题吗?
编辑:我明白了。将pyglet.clock.schedule_interval(update, 1.0/self.FPS)
更改为pyglet.clock.schedule(update)
以60 FPS的速度运行update
,但是您为它安排了一个间隔,然后当您按下按键时屏幕会闪烁。