Giter Club home page Giter Club logo

moderngl's Introduction

preview

ModernGL

ModernGL is a Python wrapper over OpenGL Core. ModernGL simplifies the creation of graphics applications like scientific simulations, games or user interfaces. Usually, acquiring in-depth knowledge of OpenGL requires a steep learning curve. In contrast, ModernGL is easy to learn and use. ModernGL is capable of rendering with high performance and quality, with less code written.

pip install moderngl

Extras

glcontext - Headless Context Creation

pip install moderngl[headless]

moderngl-window - Window Creation and Resource Loading

pip install moderngl-window

Features

  • GPU accelerated high quality graphics
  • Rendering modern OpenGL scenes with less headache
  • Simpler and faster than PyOpenGL
  • Can render without a window
  • 100% Pythonic

Sample usage

>>> import moderngl
>>> ctx = moderngl.get_context()
>>> buf = ctx.buffer(b"Hello World!")  # allocated on the GPU
>>> buf.read()
b'Hello World!'

For complete examples please visit the Examples.

Easy to use with Pillow

>>> img = Image.open("texture.jpg").convert("RGB")
>>> ctx.texture(img.size, 3, img.tobytes())
<Texture: 1>

Easy to use with Numpy

>>> ctx.buffer(np.array([0.0, 0.0, 1.0, 1.0], dtype="f4"))
<Buffer: 1>

Compared to PyOpenGL

With PyOpenGL, using the original OpenGL API, you have to write three lines to achieve a simple task like binding a VBO:

vbo1 = GL.glGenBuffers(1)
GL.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo1)
GL.glBufferData(GL.GL_ARRAY_BUFFER, b"Hello World!", GL.GL_STATIC_DRAW)

vbo2 = GL.glGenBuffers(1)
GL.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo2)
GL.glBufferData(GL.GL_ARRAY_BUFFER, None, GL.GL_DYNAMIC_DRAW)

With ModernGL you need just one simple line per VBO to achieve the same results:

vbo1 = ctx.buffer(b"Hello World!")
vbo2 = ctx.buffer(reserve=1024, dynamic=True)

Development

git clone [email protected]:moderngl/moderngl.git
cd moderngl
python -m pip install -e .

Notes

ModernGL may be faster than other libraries providing direct OpenGL access. ModernGL is implemented in C++ and a single render call involving multiple OpenGL functions count as a single Python function call.

ModernGL require OpenGL 3.3. Compute Shaders require OpenGL 4.3. Some functionality relies on specific extensions.

ModernGL can be used anywhere where OpenGL is supported. ModernGL is also working in a headless environment.

ModernGL is responsible for calling the OpenGL API and providing a Pythonic user-friendly API instead. It is possible to integrate moderngl into any window libraries that support OpenGL. Consider moderngl-window which implements many of them, plus it also helps with resource loading.

ModernGL does not implement the full OpenGL feature set or extensions. You can interact with the ModernGL objects from OpenGL.

Citation

If you need to cite this repository in academic research:

@Online{Dombi2020,
  author = {Szabolcs Dombi},
  title = {ModernGL, high performance python bindings for OpenGL 3.3+},
  date = {2020-05-01},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/moderngl/moderngl}},
  commit = {<insert hash if needed>}
}

The commit hash can be found in the Releases.

Community

moderngl's People

Contributors

aljenci avatar antazoey avatar auxiliary avatar azmisc avatar brno32 avatar compik710 avatar correct-syntax avatar einarf avatar encukou avatar gitter-badger avatar gregorni avatar maciejhalber avatar minujeong avatar naveen521kk avatar neilgirdhar avatar nicholasbishop avatar pmp-p avatar sartek avatar shakram02 avatar simleek avatar starbuck5 avatar stuaxo avatar szabolcsdombi avatar tartley avatar toaarnio avatar vallentin avatar vpoulailleau avatar wpk- avatar yonibr avatar yoyonel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moderngl's Issues

DebugFont

DebugFontRender
DebugFontAlign
DebugFontColor

Unify Uniform functions

Uniform1f
Uniform1i
Uniform2f
Uniform2i
Uniform3f
Uniform3i
Uniform4f
Uniform4i

will be SetUniform

UniformMatrix

will be SetUniformMatrix

Docs script

add possible exceptions to docs
regenerate docs

NewAdvancedVertexArray

support [multi vbo] vao 😄
NewAdvancedVertexArray([(format, vbo, [attribute, ...]), ...], ibo)

Doesn't compile on Linux

On Ubuntu 16.04 64 bit, I get -

$ python setup.py develop
running develop
running egg_info
creating ModernGL.egg-info
writing ModernGL.egg-info/PKG-INFO
writing top-level names to ModernGL.egg-info/top_level.txt
writing dependency_links to ModernGL.egg-info/dependency_links.txt
writing manifest file 'ModernGL.egg-info/SOURCES.txt'
reading manifest file 'ModernGL.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'ModernGL.egg-info/SOURCES.txt'
running build_ext
building 'ModernGL.ModernGL' extension
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/Source
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c Source/WindowsGL.cpp -o build/temp.linux-x86_64-2.7/Source/WindowsGL.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from Source/WindowsGL.cpp:1:0:
Source/WindowsGL.hpp:3:21: fatal error: Windows.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

gl2ps backend ?

Any chance of supporting gl2ps ?

VTK manages to use this to output to pdf and svg, it would be great if ModernGL could support this for the same reason.

Implement DebugInfo

returns a dict
viewport settings
texture bindings
fbo binding
active program
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.