这些是我的代码:
import sys
import pygame
teapotList = None
def loadTexture(gambar):
textureSurface = pygame.image.load(gambar)\
...
def gambarMeja():
glDisable(GL_LIGHTING)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, loadTexture('Batik.jpg'))
glPushMatrix()
glTranslatef(15.0, 5.0, 1.0)
glRotatef(-15, 0, 1, 0)
glRotatef(20, 1, 0, 0)
glBegin(GL_QUADS)
..
def mejaTV():
gambarMeja()
def display():
..
mejaTV()
gambarLemari()
def keyboard(key, x, y):
if key == chr(27):
sys.exit()
# Main Loop
if __name__ == "__main__":
..
glutKeyboardFunc(keyboard)
glutMainLoop()
我想用动作改变我的照片对于此代码:glBindTexture(GL_TEXTURE_2D, loadTexture('Batik.jpg'))
我想通过按下glBindTexture(GL_TEXTURE_2D, loadTexture('persona.jpg'))
按钮将图像更改为p
。该代码正在使用def keyboard(key, x, y):
您能帮我解决这个问题吗?
OpenGL是一个状态引擎。状态会一直保留,直到再次更改为止。
在全局名称空间中添加变量tob_batik
,tob_persona
和tob_current
:
tob_batik = None
tob_persona = None
tob_current = None
def loadTexture(gambar):
textureSurface = pygame.image.load(gambar)
# [...]
在调用glutMainLoop()
之前加载2个纹理。
# Main Loop
if __name__ == "__main__":
# [...]
glutKeyboardFunc(keyboard)
tob_batik = loadTexture('Batik.jpg')
tob_persona = loadTexture('persona.jpg')
tob_current = tob_batik
glutMainLoop()
更改tob_current
,取决于所按下的键(b或p)
def keyboard(key, x, y):
if key == chr(27):
sys.exit()
elif key == b'b':
tob_current = tob_batik
elif key == b'p':
tob_current = tob_persona
在tob_current
中绑定gambarMeja
:
def gambarMeja():
glDisable(GL_LIGHTING)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, tob_current)
# [...]