2013-10-14 271 views
-1

該錯誤是在第5行:glBindTexture(texture.target,texture.id)的OpenGL Pyglet 「錯誤:全局名稱 '紋理' 未定義」

1. import pyglet 
2. from pyglet.gl import * 
3. class CustomGroup(pyglet.graphics.Group): 
4. def set_state(self): 
5.  glEnable(texture.target) 
6.  glBindTexture(texture.target, texture.id) 
7. def unset_state(self): 
8.  glDisable(texture.target) 

NameError:全局名稱 '紋理' 未定義 但我在第2行輸入它。 完整的代碼是here

任何幫助嗎? 我使用Python 2.7.3與pyglet和Ubuntu 12.04

+0

-1,pastebins死亡,SO永遠。將代碼編輯到問題中。 – genpfault

+0

我總是將我的pastebins設置爲永不過期,但謝謝你的提示。然而,有時你想鏈接到完整的代碼,並只顯示相關部分@genpfault – itai12345

回答

0

pyglet.gl模塊不定義任何變量texture,所以在第2行的import語句沒有提供這樣的事情。你甚至期望它包含什麼?你需要自己創建你的Texture對象。

要做到這一點,你可以使用的方法pyglet.resource.imagepyglet.resource.texture或者你也可以通過調用pyglet.image.load加載AbstractImage,並通過訪問圖像的texture成員,或者說,將其添加到TextureAtlas檢索相應Texture對象。

你爲什麼不添加到您的代碼:

img = pyglet.image.load('imagefile.png') 
texture = img.texture 

,不要忘記改變你的vertex_listaccordingly利用的紋理。

+0

謝謝,這就是問題所在。我忘了將路徑更改爲正確的紋理文件 – itai12345

相關問題