PyOpenGL没有处理类型<class 'ctypes.c_ubyte'>的数组类型处理器

0 投票
1 回答
3136 浏览
提问于 2025-04-18 13:03

我刚在Mac OS 10.6.8上新安装了python 2.7(.6)。我通过homebrew安装了python,并尽可能通过pip安装了我需要的模块,其余的则是从源代码编译的。

我正在制作一个游戏,使用的是Pygame和PyOpenGL。这个游戏在我之前的python版本(2.6)上运行得很好,但不幸的是,pygame/SDL出现了问题,无法再加载PNG文件,所以我觉得是时候更新了。不过,我知道这段代码是可以运行的。

所有模块都能正常导入,但glTexImage2D却失败了。代码片段:

import numpy
from OpenGL.GL import *
from OpenGL.arrays import vbo
from OpenGLContext.arrays import *
from OpenGL.GL import shaders
from OpenGL.GLU import *

--- snip ---

def makeTexture(self, image, w, h, name = False):
    texture = glGenTextures(1)
    glActiveTexture(GL_TEXTURE0)
    glBindTexture(GL_TEXTURE_2D, texture)
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w,h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image )
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
    if name:
        self.textures[name] = texture
    else:
        self.texture = texture

然后出现的错误:

Traceback (most recent call last):
--- snip ---
  File "GameParts/Shader.py", line 88, in makeTexture
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w,h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image )
  File "latebind.pyx", line 32, in OpenGL_accelerate.latebind.LateBind.__call__ (src/latebind.c:989)
  File "wrapper.pyx", line 314, in OpenGL_accelerate.wrapper.Wrapper.__call__ (src/wrapper.c:6505)
ctypes.ArgumentError: ("argument 9: <type 'exceptions.TypeError'>: No array-type handler for type <class 'ctypes.c_ubyte'> (value: c_ubyte(0)) registered", (GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, c_ubyte(0)))

$ pip list
mercurial (2.9.2)
numpy (1.8.1)
OpenGLContext (2.3.0b1)
Pillow (2.5.1)
pip (1.5.4)
PyDispatcher (2.0.3)
pygame (1.9.2a0)
PyOpenGL (3.1.0)
PyOpenGL-accelerate (3.1.0)
PyOpenGL-Demo (3.0.1b1)
PyVRML97 (2.3.0a3)
setuptools (3.4.1)
wsgiref (0.1.2)
wxPython (3.0.0.0)
wxPython-common (3.0.0.0)

据我所知,这可能是安装顺序的问题?

1 个回答

0

我在通过“image”传递数据时搞错了,传了个零——这完全是我自己的简单错误。真正的问题是,为什么它一开始还能正常工作呢……

撰写回答