다음은 그 위치에 이미지를 배치하는 저를 허용와 내가 올 수있는 간단한 코드 (0, 0, -10) : 내가 찾은
#!/usr/bin/env python
import pyglet
from pyglet.gl import *
window = pyglet.window.Window()
glEnable(GL_DEPTH_TEST)
image = pyglet.image.load('imgs/appfolio.png')
texture = image.get_texture()
glEnable(texture.target)
glBindTexture(texture.target, texture.id)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width, image.height,
0, GL_RGBA, GL_UNSIGNED_BYTE,
image.get_image_data().get_data('RGBA', image.width * 4))
rect_w = float(image.width)/image.height
rect_h = 1
@window.event
def on_draw():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(0, 0, -10)
glBindTexture(texture.target, texture.id)
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0); glVertex3f(-rect_w, -rect_h, 0.0)
glTexCoord2f(1.0, 0.0); glVertex3f(rect_w, -rect_h, 0.0)
glTexCoord2f(1.0, 1.0); glVertex3f(rect_w, rect_h, 0.0)
glTexCoord2f(0.0, 1.0); glVertex3f(-rect_w, rect_h, 0.0)
glEnd()
def on_resize(width, height):
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(65.0, width/float(height), 0.1, 1000.0)
glMatrixMode(GL_MODELVIEW)
window.on_resize = on_resize # we need to replace so can't use @window.event
pyglet.app.run()
가장 어려운 부분은 on_resize이었다 함수는 디폴트의 직교 투영이 작동하지 않기 때문에 예상대로 작동하도록 교체되어야했습니다.
NeHe tutorial on texture mapping의 Jess Hill's pyglet conversion이 가장 유용합니다.
전체 로고 시각화 코드는 방금 전에 작성한 블로그 항목 "Moving Images in 3D Space with Pyglet"에서 찾을 수 있습니다.