{"id":6004,"library":"moderngl","title":"ModernGL","description":"ModernGL is a high-performance Python wrapper over OpenGL Core, simplifying the creation of graphics applications like scientific simulations, games, or user interfaces. It aims to provide a more Pythonic and less boilerplate-heavy API compared to direct OpenGL bindings like PyOpenGL. The current stable version is 5.12.0, with releases occurring periodically, often including breaking changes.","status":"active","version":"5.12.0","language":"python","source_language":"en","source_url":"https://github.com/moderngl/moderngl/","tags":["graphics","opengl","rendering","gpu","visualization","shader","glsl","3d"],"install":[{"cmd":"pip install moderngl","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"moderngl","correct":"import moderngl"},{"symbol":"create_context","correct":"from moderngl import create_context"},{"symbol":"get_context","correct":"from moderngl import get_context"},{"note":"Constants like BLEND, DEPTH_TEST, etc., were moved from the top-level module to the Context object in version 5.9.0.","wrong":"moderngl.BLEND","symbol":"BLEND","correct":"ctx.BLEND"}],"quickstart":{"code":"import moderngl\n\n# Create a headless context or attach to an existing one\n# For a windowed application, ctx = moderngl.create_context()\n# after a window is created by a library like Pygame, GLFW, etc.\nctx = moderngl.create_context(standalone=True)\n\n# Create a buffer on the GPU\nbuf = ctx.buffer(b\"Hello ModernGL World!\")\n\n# Read data back from the buffer\nprint(buf.read())\n\n# Release resources (important for standalone contexts)\n# For windowed contexts, resource management is often handled by the windowing library.\nctx.release()","lang":"python","description":"This quickstart demonstrates creating a ModernGL context (headless in this example), allocating a buffer on the GPU, writing data to it, and reading it back. For graphical applications, `moderngl.create_context()` would typically be called after setting up a window with an OpenGL-capable library."},"warnings":[{"fix":"Upgrade Python to version 3.8 or higher.","message":"Python 3.7 support was removed in ModernGL 5.9.0. Ensure your environment uses Python 3.8 or newer.","severity":"breaking","affected_versions":">=5.9.0"},{"fix":"Access these constants directly from the `Context` instance, e.g., `ctx.BLEND` instead of `moderngl.BLEND`.","message":"Global constants (e.g., `moderngl.BLEND`, `moderngl.DEPTH_TEST`, `moderngl.CULL_FACE`) were moved to the `Context` object in version 5.9.0. Direct access to these from the `moderngl` module will raise an `AttributeError`.","severity":"breaking","affected_versions":">=5.9.0"},{"fix":"If integrating with a window, ensure `create_context()` is called after the window's OpenGL context is active. For headless use, always pass `standalone=True`. Consider `moderngl-window` for simplified window management.","message":"ModernGL context creation (`moderngl.create_context()`) requires an existing OpenGL context (e.g., from a windowing library) or the `standalone=True` flag for headless rendering. Incorrect setup is a common source of errors.","severity":"gotcha","affected_versions":"All"},{"fix":"When creating a context, explicitly require the necessary OpenGL version, e.g., `ctx = moderngl.create_context(standalone=True, require=430)` for compute shaders. Check shader source for syntax errors.","message":"Shader compilation errors, especially with compute shaders, can sometimes lead to silent crashes without clear Python exceptions. This can be due to insufficient OpenGL version support or driver issues.","severity":"gotcha","affected_versions":"All"},{"fix":"Allocate all ModernGL objects at program startup or when resources are first needed, and store references for reuse. Release them when no longer required or at program termination.","message":"OpenGL resources (buffers, textures, programs) should be created once during initialization and reused. Creating them repeatedly (e.g., in a rendering loop) leads to severe performance degradation and memory leaks.","severity":"gotcha","affected_versions":"All"},{"fix":"Sort transparent objects by depth before rendering. Consider alternative blending techniques if sorting is not feasible for complex scenes.","message":"When rendering transparent objects with depth testing and blending enabled, objects must be drawn in a specific order (typically back-to-front relative to the camera) to ensure correct blending results. Incorrect order leads to visual artifacts.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"search_vec":"'3d':67 '5.12.0':51 'aim':27 'api':38 'applic':18 'bind':43 'boilerpl':36 'boilerplate-heavi':35 'break':58 'chang':59 'compar':39 'core':12 'creation':15 'current':47 'direct':41 'game':22 'glsl':66 'gpu':63 'graphic':17,60 'heavi':37 'high':6 'high-perform':5 'includ':57 'interfac':25 'less':34 'like':19,44 'moderngl':1,2 'occur':54 'often':56 'opengl':11,42,61 'perform':7 'period':55 'provid':29 'pyopengl':45 'python':8,32 'releas':53 'render':62 'scientif':20 'shader':65 'simplifi':13 'simul':21 'stabl':48 'user':24 'version':49 'visual':64 'wrapper':9","created_at":"2026-04-14T18:37:47.931842+00:00","updated_at":"2026-04-16T16:38:32.775576+00:00","problems":[{"fix":"Install the library using `pip install moderngl` and ensure the import statement uses lowercase: `import moderngl`.","cause":"The 'moderngl' package is either not installed in the current Python environment, or there's a capitalization mismatch in the import statement.","error":"ModuleNotFoundError: No module named 'moderngl'"},{"fix":"Ensure you are using the correct `moderngl` (lowercase) import and are accessing `create_context` directly from `moderngl`. For constants, access them via a created context object, e.g., `ctx.BLEND` instead of `moderngl.BLEND`.","cause":"This error often indicates a version incompatibility, specifically when transitioning from older ModernGL versions (e.g., ModernGL4) where the module might have been capitalized, or if global constants like `moderngl.BLEND` are accessed directly instead of through the context object.","error":"AttributeError: module 'moderngl' has no attribute 'create_context'"},{"fix":"If using a windowing library, ensure its OpenGL context is created and active before calling `moderngl.create_context()`. For headless rendering, create a standalone context: `ctx = moderngl.create_context(standalone=True)`.","cause":"ModernGL requires an active OpenGL context to perform operations. This error occurs when `moderngl.create_context()` is called without an existing OpenGL context (e.g., from a windowing library like Pygame or GLFW) being active, or when attempting headless rendering without specifying `standalone=True`.","error":"Exception: cannot detect OpenGL context"},{"fix":"Thoroughly review your GLSL shader code for any syntax errors. Verify that the `#version` directive in your shader (e.g., `#version 330`) is supported by your system's OpenGL drivers. You might need to explicitly request a specific OpenGL version when creating the context, for example: `ctx = moderngl.create_context(require=430)`.","cause":"This error signals a problem within the GLSL shader code itself, such as syntax errors, attempting to use an OpenGL Shading Language version not supported by the system's graphics drivers, or issues with shader linking.","error":"moderngl.error.Error: GLSL Compiler failed"},{"fix":"Ensure that every attribute and uniform declared in your GLSL shader code is actually used somewhere in the shader's computations or output. If an attribute or uniform is optional, either make sure it has a usage path in the shader or handle its potential absence gracefully in your Python code.","cause":"GLSL compilers often optimize out (remove) shader attributes or uniforms that are declared but not actively used within the shader's logic. When ModernGL then tries to bind data to these optimized-out variables, it cannot find them, leading to this error.","error":"moderngl.error.Error: content[0][3] must be an attribute not NoneType"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"5.12.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/moderngl/moderngl","docs":"https://moderngl.readthedocs.io/","changelog":null,"pypi":"https://pypi.org/project/moderngl/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}