Exemple #1
0
    def __init__(self,
                 name: str,
                 width: int,
                 height: int,
                 resizable: bool = False,
                 game: BaseGame = None,
                 data: BaseData = None):
        super(Window, self).__init__(width, height, resizable=resizable)

        glEnable(GL_DEPTH_TEST)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glClearColor(0, 0, 0, 1)

        # glEnable(GL_CULL_FACE)

        self.name = name
        self.num_frames = 0
        self.start_time = datetime.now()
        self.frame_start_time = datetime.now()

        self.projection_matrix = identity()

        if game is None:
            game = BaseGame()
        self.game = game
        self.game.init()

        if data is None:
            data = BaseData()
        self.data = data
Exemple #2
0
 def draw(self, additional_uniforms):
     self.texture.bind()
     found_model = list(
         filter(lambda u: u.name == "u_Model", additional_uniforms))
     if not found_model:
         additional_uniforms.append(Uniform("u_Model", identity()))
     super().draw(additional_uniforms)
     self.texture.unbind()
Exemple #3
0
    def render(self, data: game_engine.game.BaseData):
        LOG.info("Rendering", data)

        projection = Uniform("u_Projection", data.projection_matrix)
        view = Uniform("u_View", data.camera.get_view_matrix())
        uniforms = [projection, view]

        self.image.model_matrix = identity()
        translate(self.image.model_matrix, vec3(0, 10, 0))

        self.image.draw(uniforms)
        self.video.draw(uniforms)
Exemple #4
0
    def __init__(self, points: List[vec3], colors: List[vec3]):
        attributes = [
            VertexAttribute('a_Position', 3, 6, 0),
            VertexAttribute('a_Color', 3, 6, 3)
        ]
        uniforms = [Uniform("u_Model", identity())]
        super().__init__(attributes, uniforms)
        data = []
        for point, color in zip(points, colors):
            data += point.to_list()
            data += color.to_list()
        self.vertex_buffer = array_buffer(data, 6)

        global COLOR_MESH_SHADER
        if COLOR_MESH_SHADER is None:
            dir_name = get_current_directory()
            COLOR_MESH_SHADER = Shader(f"{dir_name}/color.vert",
                                       f"{dir_name}/color.frag")
            LOG.info("Loaded color mesh shader")
        self.shader = COLOR_MESH_SHADER
Exemple #5
0
 def __init__(self, path):
     texture = load_image_from_file(path)
     points, uvs = get_points_and_uvs(texture.width, texture.height)
     self.surface = TextureMeshSurface(points, uvs, texture)
     self.model_matrix = identity()
Exemple #6
0
    def draw(self, uniforms: List[Uniform]):
        self.get_next_frame()
        self.model_matrix = identity()

        uniforms.append(Uniform("u_Model", self.model_matrix))
        self.surface.draw(uniforms)
Exemple #7
0
 def get_view_matrix(self) -> mat4:
     view_matrix = identity()
     translate(view_matrix, self.position * -1)
     rotate(view_matrix, self.rotation)
     return view_matrix
Exemple #8
0
 def __init__(self):
     self.frame_time = 0
     self.mouse = Mouse()
     self.keyboard = Keyboard()
     self.window = WindowData()
     self.projection_matrix = identity()