-5

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.)

  • 3
    [What topics can I ask about here?](https://stackoverflow.com/help/on-topic): *"Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error **and the shortest code necessary to reproduce it in the question itself.**"* – Rabbid76 Jul 20 '23 at 14:27
  • *Ahem* I can't find the code that specifically causes the problem, what if the problem is in other code than the one I provided? – HazardousDev Jul 20 '23 at 15:15

1 Answers1

-2

I found the problem, the problem was, that I was adding a vec3 with magnitude of 0 to camera's position and that for some reason screwed with camera's viewMatrix, now it works.