File: shader_includes.py

package info (click to toggle)
python-moderngl-window 2.4.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 69,220 kB
  • sloc: python: 11,387; makefile: 21
file content (32 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Example showing the use of #include in shaders.
This can be used to include reusable library functions.

We include a library doing different blend types
and render each quadrant of the screen with different blend types
"""
from pathlib import Path
import moderngl_window as mglw
from moderngl_window import geometry


class ShaderInclude(mglw.WindowConfig):
    title = "Shader Include"
    resource_dir = (Path(__file__) / '../../resources').resolve()
    aspect_ratio = 1

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.program = self.load_program('programs/blend_include.glsl')
        self.texture_0 = self.load_texture_2d('textures/cubemaps/yokohama/negx.jpg')
        self.texture_1 = self.load_texture_2d('textures/cubemaps/yokohama/negz.jpg')
        self.quad_fs = geometry.quad_fs()

    def render(self, time, frame_time):
        self.texture_0.use(location=0)
        self.texture_1.use(location=1)
        self.quad_fs.render(self.program)


if __name__ == '__main__':
    mglw.run_window_config(ShaderInclude)