The following code should draw a cube each time it is called error code:
draw=False
block_VBO=0
block_EBO=0
block_VAO=0
block_EBO_buffer_len=0
def print_blocks(sx:int,sy:int,sz:int):
global draw,block_VAO,block_EBO,block_VBO,block_EBO_buffer_len
if not draw:
block_point_buffer=[]
block_color_buffer=[]
block_EBO_buffer=[]
block_point_buffer+=[x-0.5,y+0.5,z-0.5,#V0
x+0.5,y+0.5,z-0.5,#V1
x+0.5,y-0.5,z-0.5,#V2
x-0.5,y-0.5,z-0.5,#V3
x-0.5,y+0.5,z+0.5,#V4
x+0.5,y+0.5,z+0.5,#V5
x+0.5,y-0.5,z+0.5,#V6
x-0.5,y-0.5,z+0.5]#V7
block_EBO_buffer+=[0,1,5,4,
3,2,6,7,
0,3,7,4,
1,2,6,5,
0,1,2,3,
4,5,6,7]
block_VBO=glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER,block_VBO)
a=numpy.array(block_point_buffer,dtype='float32')
glBufferData(GL_ARRAY_BUFFER,sys.getsizeof(a),a,GL_STATIC_DRAW)
block_EBO=glGenBuffers(1)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,block_EBO)
a=numpy.array(block_EBO_buffer,dtype='float32')
glBufferData(GL_ELEMENT_ARRAY_BUFFER,sys.getsizeof(a),a,GL_STATIC_DRAW)
block_EBO_buffer_len=len(a)
block_VAO=glGenVertexArrays(1)
glBindVertexArray(block_VAO)
glBindBuffer(GL_ARRAY_BUFFER,block_VBO)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,block_EBO)
glVertexPointer(3,GL_FLOAT,0,None)
glEnableClientState(GL_VERTEX_ARRAY)
glBindVertexArray(0)
draw=True
glBindVertexArray(block_VAO)
glDrawElements(GL_QUADS,block_EBO_buffer_len,GL_UNSIGNED_INT,None)
glBindVertexArray(0)
print_blocks is in the mainloop. If I use glBegin and glEnd, it can be drawn normally.But after I use VBO, no graphics will be displayed. I don't want to use shaders, I don't need them.Also, how can I bind colors array to VAO?
The type of the indices in the element buffer needs to be integral. It has to match the type specified in the draw call (GL_UNSIGNED_INT
):
a=numpy.array(block_EBO_buffer,dtype='float32')
a= numpy.array(block_EBO_buffer, dtype = 'uint32')