在 LWJGL 和 PyOpenGL 中为 opengl 代码提供参数的区别
difference in giving parameters to opengl code in LWJGL and PyOpenGL
我正在通过 python.and 学习 opengl,学习这门课程
https://www.youtube.com/watch?v=WMiggUPst-Q&list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP&index=2
只是为了能够 do.he 正在使用 LWJGL,我是 PyOpengl。我注意到他的一些方法(glgenVertexArray
、gldeleteVertexArray
...ex)是在没有参数的情况下使用的,即使文档另有说明。虽然我在 python 中写了相同的代码,但它说
glGenVertexArrays requires 1 arguments (n, arrays), received 0: ()
它需要我为同一方法提供一个参数。这不是问题(我认为)给 1 但是当它到达 glDeleteVertexArrays
如果我不给 1 和我保留 vao 的列表,vbo ids 它会引发这个
Traceback (most recent call last):
File "C:\Users\TheUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\OpenGL\latebind.py", line 43, in call
return self._finalCall( *args, **named )
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/TheUser/Desktop/MyPytonDen/ThinMatrixOpenGl/engineTester/MainGameLoop.py", line 22, in
Loader.CleanUP()
File "C:\Users\TheUser\Desktop\MyPytonDen\ThinMatrixOpenGl\renderEngine\Loader.py", line 12, in CleanUP
glDeleteVertexArrays()
File "C:\Users\TheUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\OpenGL\latebind.py", line 47, in call
return self._finalCall( *args, **named )
File "C:\Users\TheUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\OpenGL\wrapper.py", line 689, in wrapperCall
pyArgs = tuple( calculate_pyArgs( args ))
File "C:\Users\TheUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\OpenGL\wrapper.py", line 436, in calculate_pyArgs
raise ValueError(
ValueError: glDeleteVertexArrays requires 2 arguments (n, arrays), received 0: ()
我按我说的处理,但我认为它不合适。
所以我问它到底想从我这里得到什么(文档对我来说不够明确)以及为什么它需要 PyOpenGl 而不是 LWJGL
这是文件:
from ThinMatrixOpenGl.renderEngine.RawModel import RawModel
from OpenGL.GL import *
import numpy as np
VAOs = []
VBOs = []
def CleanUP():
print(VAOs, VBOs)
for vao in VAOs:
glDeleteVertexArrays(int(vao), VAOs)
for vbo in VBOs:
glDeleteBuffers(int(vbo), VBOs)
def LoadToVao(positions):
global VAOs
VAO_ID = CreateVao()
VAOs.append(VAO_ID)
storeDataInAttribList(0, positions)
unbindVao()
return RawModel(vao_id=VAO_ID, vertex_count=(len(positions) / 3))
def CreateVao():
VAO_ID = glGenVertexArrays(1)
glBindVertexArray(VAO_ID)
return VAO_ID
def storeDataInAttribList(attrib_number: int, data: float):
global VBOs
VBO_id = glGenBuffers(1)
VBOs.append(VBO_id)
glBindBuffer(GL_ARRAY_BUFFER, VBO_id)
buffer = StoreDataInFloatBuffer(data)
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW)
glVertexAttribPointer(attrib_number, 3, GL_FLOAT, GL_FALSE, 0, None)
glBindBuffer(GL_ARRAY_BUFFER, 0)
def unbindVao():
glBindVertexArray(0)
def StoreDataInFloatBuffer(data: float):
buffer = np.array(data, dtype=np.float32)
return buffer
见OpenGL 4.6 API Core Profile Specification - 10.3.1 Vertex Array Objects
void DeleteVertexArrays( sizei n, const uint *arrays );
参见 PyOpneGL - glDeleteVertexArrays
:
Signature
glDeleteVertexArrays( GLsizei ( n ) , const GLuint *( arrays ) )-> void
def glDeleteVertexArrays( n , arrays )
第二个参数必须是元素类型为“unit”的数组:
def CleanUP():
np_vaos = np.array([vao], dtype="uint")
glDeleteVertexArrays(np_vaos.size, np_vaos)
但是,在较新的 PyOpenGL 版本中,第二个参数也可以是列表:
def CleanUP():
glDeleteVertexArrays(len(VAOs), VAOs)
使用 LWJGL 时,大小参数 (n) 是从 Java 数组对象中推导出来的。不同语言的不同库为 OpenGL API 函数提供不同的重载。如果函数行为异常并且与 OpenGL 规范不同,您必须查阅库的 API 文档。
我正在通过 python.and 学习 opengl,学习这门课程
https://www.youtube.com/watch?v=WMiggUPst-Q&list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP&index=2
只是为了能够 do.he 正在使用 LWJGL,我是 PyOpengl。我注意到他的一些方法(glgenVertexArray
、gldeleteVertexArray
...ex)是在没有参数的情况下使用的,即使文档另有说明。虽然我在 python 中写了相同的代码,但它说
glGenVertexArrays requires 1 arguments (n, arrays), received 0: ()
它需要我为同一方法提供一个参数。这不是问题(我认为)给 1 但是当它到达 glDeleteVertexArrays
如果我不给 1 和我保留 vao 的列表,vbo ids 它会引发这个
Traceback (most recent call last): File "C:\Users\TheUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\OpenGL\latebind.py", line 43, in call return self._finalCall( *args, **named ) TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/TheUser/Desktop/MyPytonDen/ThinMatrixOpenGl/engineTester/MainGameLoop.py", line 22, in Loader.CleanUP() File "C:\Users\TheUser\Desktop\MyPytonDen\ThinMatrixOpenGl\renderEngine\Loader.py", line 12, in CleanUP glDeleteVertexArrays() File "C:\Users\TheUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\OpenGL\latebind.py", line 47, in call return self._finalCall( *args, **named ) File "C:\Users\TheUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\OpenGL\wrapper.py", line 689, in wrapperCall pyArgs = tuple( calculate_pyArgs( args )) File "C:\Users\TheUser\AppData\Local\Programs\Python\Python38-32\lib\site-packages\OpenGL\wrapper.py", line 436, in calculate_pyArgs raise ValueError( ValueError: glDeleteVertexArrays requires 2 arguments (n, arrays), received 0: ()
我按我说的处理,但我认为它不合适。 所以我问它到底想从我这里得到什么(文档对我来说不够明确)以及为什么它需要 PyOpenGl 而不是 LWJGL
这是文件:
from ThinMatrixOpenGl.renderEngine.RawModel import RawModel
from OpenGL.GL import *
import numpy as np
VAOs = []
VBOs = []
def CleanUP():
print(VAOs, VBOs)
for vao in VAOs:
glDeleteVertexArrays(int(vao), VAOs)
for vbo in VBOs:
glDeleteBuffers(int(vbo), VBOs)
def LoadToVao(positions):
global VAOs
VAO_ID = CreateVao()
VAOs.append(VAO_ID)
storeDataInAttribList(0, positions)
unbindVao()
return RawModel(vao_id=VAO_ID, vertex_count=(len(positions) / 3))
def CreateVao():
VAO_ID = glGenVertexArrays(1)
glBindVertexArray(VAO_ID)
return VAO_ID
def storeDataInAttribList(attrib_number: int, data: float):
global VBOs
VBO_id = glGenBuffers(1)
VBOs.append(VBO_id)
glBindBuffer(GL_ARRAY_BUFFER, VBO_id)
buffer = StoreDataInFloatBuffer(data)
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW)
glVertexAttribPointer(attrib_number, 3, GL_FLOAT, GL_FALSE, 0, None)
glBindBuffer(GL_ARRAY_BUFFER, 0)
def unbindVao():
glBindVertexArray(0)
def StoreDataInFloatBuffer(data: float):
buffer = np.array(data, dtype=np.float32)
return buffer
见OpenGL 4.6 API Core Profile Specification - 10.3.1 Vertex Array Objects
void DeleteVertexArrays( sizei n, const uint *arrays );
参见 PyOpneGL - glDeleteVertexArrays
:
Signature
glDeleteVertexArrays( GLsizei ( n ) , const GLuint *( arrays ) )-> void def glDeleteVertexArrays( n , arrays )
第二个参数必须是元素类型为“unit”的数组:
def CleanUP():
np_vaos = np.array([vao], dtype="uint")
glDeleteVertexArrays(np_vaos.size, np_vaos)
但是,在较新的 PyOpenGL 版本中,第二个参数也可以是列表:
def CleanUP():
glDeleteVertexArrays(len(VAOs), VAOs)
使用 LWJGL 时,大小参数 (n) 是从 Java 数组对象中推导出来的。不同语言的不同库为 OpenGL API 函数提供不同的重载。如果函数行为异常并且与 OpenGL 规范不同,您必须查阅库的 API 文档。