How to use the moderngl.create_context function in moderngl

To help you get started, we’ve selected a few moderngl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github moderngl / moderngl / examples / qtmoderngl.py View on Github external
def paintGL(self):
        self.ctx = moderngl.create_context()
        self.screen = self.ctx.detect_framebuffer(self.defaultFramebufferObject())
        self.init()
        self.render()
        self.paintGL = self.render
github Contraz / demosys-py / demosys / context / glfw / window.py View on Github external
print("Frame buffer size:", self.buffer_width, self.buffer_height)
        print("Actual window size:", glfw.get_window_size(self.window))

        glfw.make_context_current(self.window)

        # The number of screen updates to wait from the time glfwSwapBuffers
        # was called before swapping the buffers and returning
        if self.vsync:
            glfw.swap_interval(1)

        glfw.set_key_callback(self.window, self.key_event_callback)
        glfw.set_cursor_pos_callback(self.window, self.mouse_event_callback)
        glfw.set_window_size_callback(self.window, self.window_resize_callback)

        # Create mederngl context from existing context
        self.ctx = moderngl.create_context(require=self.gl_version.code)
        context.WINDOW = self
        self.fbo = self.ctx.screen
        self.set_default_viewport()
github amb / blender-texture-tools / inactive / old.py View on Github external
def _pl(self, image, context):
            import moderngl
            import numpy as np

            # default: false, false, 3000, 1.00, 0.3, 0.05, 0.06, 0.9
            ctx = moderngl.create_context()

            prog = ctx.program(
                vertex_shader="""
                    #version 330

                    in vec2 in_vert;
                    out vec2 vert_pos;

                    void main() {
                        vert_pos = 0.5 * (in_vert + 1.0);
                        gl_Position = vec4(in_vert, 0.0, 1.0);
                    }
                """,
                fragment_shader="""
                    #version 330
github airalcorn2 / strike-with-a-pose / strike_with_a_pose / scene.py View on Github external
def __init__(self):
        self.CTX = moderngl.create_context()
        self.PROG = self.CTX.program(
            vertex_shader="""
                #version 330

                uniform float x;
                uniform float y;
                uniform float z;

                uniform mat3 R_obj;
                uniform mat3 R_light;
                uniform vec3 DirLight;
                uniform mat4 VP;
                uniform int mode;

                in vec3 in_vert;
                in vec3 in_norm;
github moderngl / moderngl / examples / buffer_creation.py View on Github external
import moderngl
import numpy as np

ctx = moderngl.create_context(standalone=True)

# reserving a buffer with 500 bytes
buf1 = ctx.buffer(reserve=500)
print(buf1.size)

# reserving 1KB using a human readable format
buf2 = ctx.buffer(reserve='1KB')
print(buf2.size)

# reserving 2MB using a human readable format
buf3 = ctx.buffer(reserve='2MB')
print(buf3.size)

# creating a buffer using a numpy array
# make sure the array contains floats and not doubles
buf4 = ctx.buffer(np.array([
github moderngl / moderngl / extras / gltraces / example.py View on Github external
import struct

import numpy as np

import gltraces
import moderngl

ctx = moderngl.create_context(standalone=True, debug=True)

mglprocs = moderngl.glprocs(ctx)
gltraces.glprocs[:] = mglprocs
mglprocs[:] = gltraces.gltraces

prog = ctx.program(
    vertex_shader='''
        #version 130

        in vec2 in_vert;
        out vec2 v_vert;

        void main() {
            v_vert = in_vert;
            gl_Position = vec4(0.0, 0.0, 0.0, 0.0);
        }
github moderngl / moderngl / examples / window / pyglet / window.py View on Github external
width=self.width, height=self.height,
            caption=self.title,
            resizable=self.resizable,
            vsync=self.vsync,
            fullscreen=self.fullscreen,
        )
        self.window.set_mouse_visible(self.cursor)

        self.window.event(self.on_key_press)
        self.window.event(self.on_key_release)
        self.window.event(self.on_mouse_motion)
        self.window.event(self.on_resize)
        self.window.event(self.on_mouse_press)
        self.window.event(self.on_mouse_release)

        self.ctx = moderngl.create_context(require=self.gl_version_code)
        self.set_default_viewport()
        self.print_context_info()
github moderngl / moderngl / examples / old-examples / texture_array_and_indirect_draw.py View on Github external
import GLWindow
import moderngl
from PIL import Image, ImageDraw, ImageFont
import numpy as np

wnd = GLWindow.create_window()
ctx = moderngl.create_context()

prog = ctx.program(
    vertex_shader='''
        #version 330

        in vec2 in_vert;
        in vec3 in_text;

        out vec3 v_text;

        void main() {
            v_text = in_text;
            gl_Position = vec4(in_vert, 0.0, 1.0);
        }
    ''',
    fragment_shader='''