Буфер глубины из PyOpenGL для отображаемого треугольника

evgen_i

Не могли бы подсказать, из за чего вылетает ошибка "AttributeError: ("module 'numpy' has no attribute 'float128'"" и как ее пофиксить?
from OpenGL.GL import *
from OpenGL.GLUT import *
import numpy as np
import sys
 
def draw_scene():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glBegin(GL_TRIANGLES)
    glColor3f(1, 0, 0)
    glVertex3f(-1, -1, 0)
    glColor3f(0, 1, 0)
    glVertex3f(0, 1, 0)
    glColor3f(0, 0, 1)
    glVertex3f(1, -1, 0)
    glEnd()
 
def draw_texture():
    global color_texture
    glColor3f(1, 1, 1)
    glBindTexture(GL_TEXTURE_2D, color_texture)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glBegin(GL_QUADS)
    glTexCoord2f(0, 0)
    glVertex3f(-1, -1, 0)
    glTexCoord2f(0, 1)
    glVertex3f(-1, 1, 0)
    glTexCoord2f(1, 1)
    glVertex3f(1, 1, 0)
    glTexCoord2f(1, 0)
    glVertex3f(1, -1, 0)
    glEnd()
    glBindTexture(GL_TEXTURE_2D, 0)
 
def update_display():
    global fbo, color_texture, depth_texture
 
    #Render the scene to an offscreen FBO
    glBindFramebuffer(GL_FRAMEBUFFER, fbo)
    draw_scene()
    glBindFramebuffer(GL_FRAMEBUFFER, 0)
 
    #Then render the results of the color texture attached to the FBO to the screen
    draw_texture()
 
    #Obtain the color data in a numpy array
    glBindTexture(GL_TEXTURE_2D, color_texture)
    color_str = glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE)
    glBindTexture(GL_TEXTURE_2D, 0)
    color_data = np.fromstring(color_str, dtype=np.*****)
 
    #Obtain the depth data in a numpy array
    glBindTexture(GL_TEXTURE_2D, depth_texture)
    depth_str = glGetTexImage(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, GL_FLOAT)
    glBindTexture(GL_TEXTURE_2D, 0)
    depth_data = np.fromstring(depth_str, dtype=np.float32)
    print(np.min(depth_data), np.max(depth_data))#This is just to show the normalized range of depth values obtained
 
    glutSwapBuffers()
 
width, height = 800, 600
fbo = None
color_texture = None
depth_texture = None
 
if __name__ == '__main__':
    glutInit([])
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)
    glutInitWindowSize(width, height)
    glutInitWindowPosition(0, 0)
    glutCreateWindow(b"Triangle Test")
 
    glEnable(GL_TEXTURE_2D)#not needed if using shaders...
    glEnable(GL_DEPTH_TEST)
 
    color_texture = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, color_texture)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, None)
    glBindTexture(GL_TEXTURE_2D, 0)
 
    depth_texture = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, depth_texture)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, None)
    glBindTexture(GL_TEXTURE_2D, 0)
 
    fbo = glGenFramebuffers(1)
    glBindFramebuffer(GL_FRAMEBUFFER, fbo)
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color_texture, 0)
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_texture, 0)
    glBindFramebuffer(GL_FRAMEBUFFER, 0)
 
    glutDisplayFunc(update_display)
__________________________________________________________________________________________
class NumpyHandler( formathandler.FormatHandler ):  
  File "C:\ProgramData\Anaconda3\lib\site-packages\OpenGL\arrays\numpymodule.py", line 93, in NumpyHandler
    numpy.float128,
 
AttributeError: ("module 'numpy' has no attribute 'float128'", 'Failure in cConverter  
<OpenGL.converters.SizedOutputOrInput object at 0x00000239E10158C8>',
 (1, <object object at 0x00000239DE71B320>), 1,  <OpenGL.platform.baseplatform.glGenTextures object at 0*****************>)
3 ответа

evgen_i

Попробуй обновить numpy


evgen_i

Действительно, это сработалоТабуретY, Не пойму что теперь не так?
 File "C:\ProgramData\Anaconda3\lib\site-packages\OpenGL\error.py", line 232, in glCheckError
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
        err = 1282,
        description = b'\xed\xe5\xe4\xee\xef\xf3\xf1\xf2\xe8\xec\xe0\xff \xee\xef\xe5\xf0\xe0\xf6\xe8\xff',
        baseOperation = glEnable,
        cArguments = (GL_TEXTURE_2D,)


evgen_i

Попробуй установить PyOpenGL в ручную, нужно скачать отсюда https://pypi.python.org/pypi/PyOpenGL архив, у меня заработал PyOpenGL-3.1.1a1