I was searching for a solution for a day now, I'm trying to make a renderer in Python using ModernGL, PyGLFW and PyGLM. A red cube should be rendered on the screen, but there's just a blue background. The only thing I found out was, that the cube doesn't render, because the shader is written to too much, but I have to do it to make the FPS camera system work.
class Mesh:
def __init__(self,engine):
vertices,indices = self.get_vertex_data()
self.vbo = self.ctx.buffer(vertices.to_bytes())
self.ibo = self.ctx.buffer(indices.to_bytes())
self.vao = self.ctx.vertex_array(
engine.shader.program,
self.vbo,
"inPosition",
index_buffer=self.ibo,
index_element_size=4
)
self.update_shaders()
@staticmethod
def get_data(vertices, indices):
data = [vertices[ind] for triangle in indices for ind in triangle]
return glm.array(*data)
def get_vertex_data(self):
pass
def update_shaders(self):
self.engine.shader.program["projectionMatrix"].write(self.engine.current_camera.projection_matrix)
self.engine.shader.program["viewMatrix"].write(self.engine.current_camera.view_matrix)
self.engine.shader.program["modelMatrix"].write(self.transform.to_matrix())
def update(self):
self.update_shaders()
def render(self):
self.vao.render()
def release(self):
self.vbo.release()
self.ibo.release()
self.vao.release()
(I didn't add the get_vertex_data method, because it's too long, basically, it just creates two PyGLM arrays, one contains vec3's for a cube and second are indices for the said cube.)