numpy.float128 在 windows 中不存在,而是从 OpenGL 调用 [英] numpy.float128 doesn't exist in windows, but is called from OpenGL

查看:145
本文介绍了numpy.float128 在 windows 中不存在,而是从 OpenGL 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定尝试在 Python 中使用 OpenGL VBO 来提高 FPS.我找到了在 Linux 操作系统 (Ubuntu) 中运行良好的代码,但是当我尝试在 Windows 操作系统中启动时,代码产生了一条消息:"GLUT Display callback with (),{} 失败:返回 None 模块 'numpy' 没有属性 'float128'"

I decided to try using OpenGL VBO in Python to improve FPS. I found code, that worked perfectly fine in Linux OS (Ubuntu), but when I tried launching in Windows OS, the code resulted in a message: "GLUT Display callback with (),{} failed: returning None module 'numpy' has no attribute 'float128'"

所以,我不能专门在 Windows 上运行代码,但是因为我想创建一个跨平台的应用程序,我真的需要解决这个问题.

So, I can't run the code specifically on Windows, but because I want to create a cross-platform application, I really need to solve this.

我做了很多研究,只发现应该将 numpy.float128 替换为 numpy.longdouble.但是,因为OpenGL VBO在opengl_accelerate中,我不知道如何更改那里的用法.

I've done a lot of research and only found that numpy.float128 should be replaced to numpy.longdouble. However, because OpenGL VBO is in opengl_accelerate, I don't know how to change the usage there.

这是我的全部代码.

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()

这是完整的错误回溯:

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

Traceback (most recent call last): File "C:\Users\root\Anaconda3\lib\site-packages\OpenGL\GLUT\special.py", line 130, in safeCall return function( *args, **named ) File "C:/Users/root/Desktop/test/main3.py", line 48, in display Point() File "C:/Users/root/Desktop/test/main3.py", line 42, in Point displayPoints(points) File "C:/Users/root/Desktop/test/main3.py", line 23, in displayPoints glBufferData(GL_ARRAY_BUFFER,sys.getsizeof(points), points, GL_STREAM_DRAW) File "src/latebind.pyx", line 44, in OpenGL_accelerate.latebind.Curry.call File "C:\Users\root\Anaconda3\lib\site-packages\OpenGL\GL\VERSION\GL_1_5.py", line 86, in glBufferData data = ArrayDatatype.asArray( data ) File "src/arraydatatype.pyx", line 172, in OpenGL_accelerate.arraydatatype.ArrayDatatype.asArray File "src/arraydatatype.pyx", line 47, in OpenGL_accelerate.arraydatatype.HandlerRegistry.c_lookup File "C:\Users\root\Anaconda3\lib\site-packages\OpenGL\plugins.py", line 16, in load return importByName( self.import_path ) File "C:\Users\root\Anaconda3\lib\site-packages\OpenGL\plugins.py", line 38, in importByName module = import( ".".join(moduleName), {}, {}, moduleName) File "C:\Users\root\Anaconda3\lib\site-packages\OpenGL\arrays\numpymodule.py", line 27, in from OpenGL_accelerate.numpy_formathandler import NumpyHandler File "src/numpy_formathandler.pyx", line 55, in init OpenGL_accelerate.numpy_formathandler AttributeError: module 'numpy' has no attribute 'float128' GLUT Display callback with (),{} failed: returning None module 'numpy' has no attribute 'float128'

有没有办法在opengl_accelerate 中将numpy.float128 的用法更改为numpy.longdouble 或使numpy.float128 在windows 中工作?

Is there any way of either changing the usage of numpy.float128 to numpy.longdouble in opengl_accelerate or making numpy.float128 work in windows?

推荐答案

找到解决方案:我发现 PyOpenGL 的最后一个版本本身运行良好,但是,导致这个问题出现的是 pyopengl-accelerate 包.删除加速包后一切正常.

Found solution: I found out that PyOpenGL’s last version works fine itself, however, it’s pyopengl-accelerate package that causes this issue to appear. After I removed the acceleration package everything world fine.

这篇关于numpy.float128 在 windows 中不存在,而是从 OpenGL 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆