Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VAO and VBO not working.
#1
class cube():
    def __init__(self,vertexcount,VAOid):
        self.vertexcount=vertexcount
        self.VAOid=VAOid

    def draw(self):
        GL.glBindVertexArray(self.VAOid)
        GL.glEnableVertexAttributeArray(0)
        GL.glDrawArrays(GL_TRIANGLES,0,self.vertexcount)
        GL.glDisableVertexAttribArray(0)
        GL.glBindVertexArray(0)


#########################################################################################################
class VAO():
    def __init__(self,VAOid,VBOid,attributenum,positions=[],VAOS=[],VBOS=[]):
        self.VAOid,self.VBOid=VAOid,VBOid
        self.positions=positions
        self.attributenum=attributenum
        self.VAOS,self.VBOS=VAOS,VBOS

    def create(self):
        self.VAOid=GL.glGenVertexArrays()
        self.VAOS.append(self.VAOid)
        GL.glBindVertexArray(self.VAOid)
        return self.VAOid

    def store(self,attributenum,data):
        self.VBOid=GL.glGenBuffers()
        self.VBOS.append(self.VBOid)
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER,self.VBOid)

        GL.glBufferData(GL.GL_ARRAY_BUFFER,data,GL.GL_STATIC_DRAW)
        GL.glVertexAttribPointer(attributenum,3,GL.GL_FLOAT,False,0,0)
        GL.glBindBuffer(GL.GL_ARRAY_BUFFER,0)
   
     def clean(self):
        for VAO in self.VAOS:
            GL.glDeleteVertexArrays(VAO)
        for VBO in self.VBOS:
            GL.glDeleteBuffers(VBO)
    def unbind(self):
        GL.glBindVertexArray(0)

    def loadtoVAO(self):
        self.VAOid=self.create()
        self.store(self.attributenum,self.positions)
        self.unbind()
        return cube(self.VAOid,len(self.positions)/3)
Note:This is not the full code just the VAO and VBO part, the part of code that calls this method is also not included.The reason i did not post the full code is because the question asking guideline from this forum says to extract the part that i thinks causes the error only,so here it is.

Error:
Traceback (most recent call last):   File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-package s\pyopengl-3.1.1a1-py3.5.egg\OpenGL\latebind.py", line 41, 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 "game.py", line 172, in <module>     game=game(True,'loading','mainmenu',False)   File "game.py", line 25, in __init__     square1=VAOcreator.loadtoVAO()   File "game.py", line 154, in loadtoVAO     self.VAOid=self.create()   File "game.py", line 132, in create     self.VAOid=GL.glGenVertexArrays()   File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-package s\pyopengl-3.1.1a1-py3.5.egg\OpenGL\latebind.py", line 45, in __call__     return self._finalCall( *args, **named )   File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-package s\pyopengl-3.1.1a1-py3.5.egg\OpenGL\wrapper.py", line 655, in wrapperCall     pyArgs = tuple( calculate_pyArgs( args ))   File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-package s\pyopengl-3.1.1a1-py3.5.egg\OpenGL\wrapper.py", line 430, in calculate_pyArgs     args ValueError: glGenVertexArrays requires 1 arguments (n, arrays), received 0: ()
This code shouldnt give a error,because i copied it(changed a bit) from a youtube tutorial
(https://www.youtube.com/watch?v=WMiggUPst-Q&t=687s)
the few things that i change are:

1)changing the class the method should be in
-the draw method should be in the renderer class(according to the video),but i put it in the cube class.

2)translating from java to python
-the tutorial is in java,so i dont know how to translate it properly,especially the bufferutil part,so i skip that part.(which i think will also work,because it is just used to convert from array\list to buffer)

3)adding constructor
-using the __init__() method in every class

any help will be appreciated. Smile
Reply
#2
Error:
File "game.py", line 132, in create self.VAOid=GL.glGenVertexArrays() [.........] ValueError: glGenVertexArrays requires 1 arguments (n, arrays), received 0: ()
So, it complains it's missing an argument, and your code indeed doesn't provide it (and your code extract doesn't include the problem code...)
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#3
But i copied it from a youtube tutorial,and it works when he run it.
he doesnt provide the argument for that function,but his code work,why?
Reply
#4
1) when some code doesn't work, the best person to ask is the author...

2) check software versions. I see two different signatures for that function (and none of them is the same as the one you use), here and there.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#5
After fixing this error ,another error occur.
the error name is NullFunctionError,it says glGenVertexArrays method is undefined,so i checked by doing
print(bool(GL.glGenVertexArrays))
and it returns false,so
i just downloaded GPU caps viewer to check my system supported version.

software
pyopengl version:3.1

gpu/hardware
gpu opengl version:4.0
glsl version:4.0
renderer:Intel® HD Graphic 4400
GPU opengl extension GL_ARB_VAO version:2.1
GPU opengl extension GL_ARB_VBO version:1.5
etc
should i uninstall pyopengl and download a lower version one?
what should i do now?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020