i am learning opengl with python.and following this course
https://www.youtube.com/watch?v=WMiggUPst-Q&list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP&index=2
just to be able to do.he is using LWJGL, i am PyOpengl. i noticed some of his methods (glgenVertexArray
, gldeleteVertexArray
...ex) is used without parameters even docs says otherwise. while i wrote same code in python it's says
glGenVertexArrays requires 1 arguments (n, arrays), received 0: ()
it' wants a parameter from me for the same method. it's not a problem here(i think) give 1 but when its come to glDeleteVertexArrays
if i dont give 1 and the list that i am keeping vao,vbo ids its raises this
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: ()
i handle this as i say but i dont think its appropriate. so i am asking what its acctuly want from me (docs wasn't explicit enough for me) and why it's wants for PyOpenGl but not LWJGL
and this is the file:
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
See the OpenGL 4.6 API Core Profile Specification - 10.3.1 Vertex Array Objects
void DeleteVertexArrays( sizei n, const uint *arrays );
See PyOpneGL - glDeleteVertexArrays
:
Signature
glDeleteVertexArrays( GLsizei ( n ) , const GLuint *( arrays ) )-> void def glDeleteVertexArrays( n , arrays )
The 2nd argument must be an array with the element type "unit":
def CleanUP():
np_vaos = np.array([vao], dtype="uint")
glDeleteVertexArrays(np_vaos.size, np_vaos)
In newer PyOpenGL versions, however, the second argument can also be a list:
def CleanUP():
glDeleteVertexArrays(len(VAOs), VAOs)
When using LWJGL, the size argument (n) is deduced from the Java array object. Different libraries in different languages provide different overloads for the OpenGL API functions. If a function behaves unexpectedly and differs from the OpenGL specification, you must consult the API documentation for the libraries.