numpy.float128在Windows中不存在,但是是从OpenGL调用的

我决定尝试在Python中使用OpenGL VBO来改善FPS。我找到了在Linux OS(Ubuntu)上运行良好的代码,但是当我尝试在Windows OS中启动时,代码导致出现一条消息: “带有()的GLUT显示回调,{}失败:返回None模块'numpy'没有属性'float128'”

因此,我无法在Windows上专门运行代码,但是由于我想创建一个跨平台的应用程序,因此我确实需要解决此问题。

我做了很多研究,仅发现numpy.float128应该替换为numpy.longdouble。但是,由于OpenGL VBO位于opengl_accelerate中,因此我不知道如何更改其用法。

这是我的全部代码。

import sys
import random #for random numbers
from OpenGL.GL import * #for definition of points
from OpenGL.GLU import *
from OpenGL.GLUT import * #for visualization in a window
import numpy as np


AMOUNT = 10
DIMENSION = 3

def changePoints(points):
    for i in range(0,3*AMOUNT):
        x = random.uniform(-1.0,1.0)
        points[i]= points[i]*x
    print(points)
    return points

def displayPoints(points):
    vbo=GLuint(0) # init the Buffer in Python!
    glGenBuffers(1,vbo) # generate a buffer for the vertices
    glBindBuffer(GL_ARRAY_BUFFER,vbo) #bind the vertex buffer
    glBufferData(GL_ARRAY_BUFFER,sys.getsizeof(points),points,GL_STREAM_DRAW)
    glBindBuffer(GL_ARRAY_BUFFER,vbo) #bind the vertex buffer

    glEnableclientState(GL_VERTEX_ARRAY) # enable Vertex Array
    glVertexPointer(DIMENSION,GL_FLOAT,ctypes.cast(0,ctypes.c_void_p))
    glBindBuffer(GL_ARRAY_BUFFER,vbo) #bind the vertex buffer
    glDrawArrays(GL_POINTS,AMOUNT)
    glDisableclientState(GL_VERTEX_ARRAY) # disable the Vertex Array
    glDeleteBuffers(1,vbo)

##creates Points
def Point():

    points = np.array([random.uniform(-1.0,1.0) for _ in range(3*AMOUNT)],dtype = np.float32)

    points = changePoints(points)

    #Visualization
    displayPoints(points)


##clears the color and depth Buffer,call Point() and swap the buffers of the current window
def display():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEpth_BUFFER_BIT)
    Point()
    glutSwapBuffers()

def main():
    ##initials GLUT
    glutInit(sys.argv)
    #sets the initial display mode (selects a RGBA mode window; selects a double buffered window; selects a window with a depth buffer)
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEpth)
    #defines the size of the Window
    glutInitWindowSize(800,1600)
    #creates a window with title
    glutCreateWindow(b'Points') #!string as title is causing a error,because underneath the PyOpenGL call is an old-school C function expecting ASCII text. Solution: pass the string in byte format.
    glutDisplayFunc(display) #sets the display callback for the current window.
    glutMainLoop() #enters the GLUT event processing loop.

main()

这是完整的错误回溯:

  

回溯(最近通话最近):     在safeCall中的文件“ C:\ Users \ root \ Anaconda3 \ lib \ site-packages \ OpenGL \ GLUT \ special.py”,第130行       返回函数(* args,** named)     显示文件“ C:/Users/root/Desktop/test/main3.py”,第48行       点()     点中的文件“ C:/Users/root/Desktop/test/main3.py”,第42行       displayPoints(点)     displayPoints中的文件“ C:/Users/root/Desktop/test/main3.py”,第23行       glBufferData(GL_ARRAY_BUFFER,sys.getsizeof(points),points,GL_STREAM_DRAW)     在OpenGL_accelerate.latebind.Curry中,文件“ src / latebind.pyx”,第44行。调用     glBufferData中的文件“ C:\ Users \ root \ Anaconda3 \ lib \ site-packages \ OpenGL \ GL \ VERSION \ GL_1_5.py”,行86       数据= ArrayDatatype.asArray(数据)     OpenGL_accelerate.arraydatatype.ArrayDatatype.asArray中的文件“ src / arraydatatype.pyx”,第172行     OpenGL_accelerate.arraydatatype.HandlerRegistry.c_lookup中的文件“ src / arraydatatype.pyx”,第47行     加载中的文件“ C:\ Users \ root \ Anaconda3 \ lib \ site-packages \ OpenGL \ plugins.py”,第16行       返回importByName(self.import_path)     在importByName中,文件“ C:\ Users \ root \ Anaconda3 \ lib \ site-packages \ OpenGL \ plugins.py”,第38行       module = 导入(“。”。join(moduleName),{},{},moduleName)     文件“ C:\ Users \ root \ Anaconda3 \ lib \ site-packages \ OpenGL \ arrays \ numpymodule.py”,第27行,在       从OpenGL_accelerate.numpy_formathandler导入NumpyHandler     初始化OpenGL_accelerate.numpy_formathandler中的文件“ src / numpy_formathandler.pyx”,第55行   AttributeError:模块“ numpy”没有属性“ float128”   带有(),{}的GLUT Display回调失败:返回None模块'numpy'没有属性'float128'

是否可以将opengl_accelerate中的numpy.float128的用法更改为numpy.longdouble或使numpy.float128在Windows中工作?

huakaijianyueming 回答:numpy.float128在Windows中不存在,但是是从OpenGL调用的

找到的解决方案: 我发现PyOpenGL的最新版本本身可以正常运行,但是它的pyopengl-accelerate软件包导致出现此问题。删除加速程序包后,一切正常。

本文链接:https://www.f2er.com/3169568.html

大家都在问