def create_standalone_context(require=None, share=False, **settings) -> 'Context': ''' Create a standalone ModernGL context. Example:: # Create a context with highest possible supported version ctx = moderngl.create_context() # Require at least OpenGL 4.3 ctx = moderngl.create_context(require=430) Keyword Arguments: require (int): OpenGL version code. Returns: :py:class:`Context` object ''' if require is None: require = 330 mode = 'share' if share is True else 'standalone' ctx = Context.__new__(Context) ctx.mglo, ctx.version_code = mgl.create_context(glversion=require, mode=mode, **settings) ctx._screen = None ctx.fbo = None ctx._info = None ctx.extra = None if require is not None and ctx.version_code < require: raise ValueError('Requested OpenGL version {}, got version {}'.format( require, ctx.version_code)) return ctx
def create_context(require=None, standalone=False, share=False, **settings) -> Context: ''' Create a ModernGL context by loading OpenGL functions from an existing OpenGL context. An OpenGL context must exists. If rendering is done without a window please use the :py:func:`create_standalone_context` instead. Example:: # Accept the current context version ctx = moderngl.create_context() # Require at least OpenGL 4.3 ctx = moderngl.create_context(require=430) Keyword Arguments: require (int): OpenGL version code. Returns: :py:class:`Context` object ''' if require is None: require = 330 mode = 'standalone' if standalone is True else 'detect' if share is True: mode = 'share' import moderngl.mgl as mgl ctx = Context.__new__(Context) ctx.mglo, ctx.version_code = mgl.create_context(glversion=require, mode=mode, **settings) ctx._info = None ctx.extra = None if ctx.version_code < require: raise ValueError('Requested OpenGL version {}, got version {}'.format( require, ctx.version_code)) if standalone: ctx._screen = None ctx.fbo = None else: ctx._screen = ctx.detect_framebuffer(0) ctx.fbo = ctx.detect_framebuffer() ctx.mglo.fbo = ctx.fbo.mglo return ctx
def create_standalone_context(require=None, **settings) -> 'Context': ''' Create a standalone ModernGL context. Example:: # Create a context with highest possible supported version ctx = moderngl.create_context() # Require at least OpenGL 4.3 ctx = moderngl.create_context(require=430) Keyword Arguments: require (int): OpenGL version code. Returns: :py:class:`Context` object ''' if require is None: require = 0 backend = os.environ.get('MODERNGL_BACKEND') if backend is not None: settings['backend'] = backend ctx = Context.__new__(Context) ctx.mglo, ctx.version_code = mgl.create_context(None, True, require) ctx._screen = None ctx.fbo = None ctx._info = None ctx.extra = None if require is not None and ctx.version_code < require: raise ValueError('Requested OpenGL version {}, got version {}'.format( require, ctx.version_code)) return ctx