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

问题描述 投票:1回答:1

我决定尝试在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,0, ctypes.cast(0, ctypes.c_void_p))
    glBindBuffer(GL_ARRAY_BUFFER, vbo) #bind the vertex buffer
    glDrawArrays(GL_POINTS, 0, 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行。callglBufferData中的文件“ 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 = import(“。”。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中工作?

python windows numpy opengl pyopengl
1个回答
0
投票

问题是创建numpy.array的方式。numpy.array返回一个新数组,但不更改输入数组。因此numpy.ascontiguousarray仍然是整数值的数组。

您必须分配points的返回值来解决此问题:

https://docs.scipy.org/doc/numpy/reference/generated/numpy.ascontiguousarray.html

甚至可以在points = np.arange(AMOUNT*3) points = np.ascontiguousarray(points, dtype = np.float32) 上添加dtype参数

numpy.arange

此外,这些点的坐标必须在[-1,1]范围内,因此创建具有递增整数的数组毫无意义。

创建具有范围为[-1,1]的随机值的数组就足够了:

numpy.arange
© www.soinside.com 2019 - 2024. All rights reserved.