-
Notifications
You must be signed in to change notification settings - Fork 619
Trash. LowLevelAPI
Notes about the low-level API
This layer is an object-oriented wrapper around OpenGL 2. It implements the most common features. It is meant to be lightweight, simple and easy-to-use. Only the programmable pipeline is available.
NOTE: this object may not be necessary at first.
The Context is an object containing all OpenGL objects used to render the
screen. It also implements the logic of the scene. OpenGL objects are added
with the add
method. Then, the Context object provides three methods that
can be called from an OpenGL canvas (with Qt, wx, SDL, GLUT, etc.):
initialize
, paint
, resize
. These functions can also be overriden for
customization. In Python, the Context provides decorator to simplify
this process.
Higher-level interfaces may not need to use the Context. All the functionality should be implemented in the child objects, the Context being just a handy tool when using the low-level interface directly.
-
Context.add(*args, **kwargs)
: add one or several objects to the context. The objects can be unnamed (then the variable name or an automatically generic numbered named is used) or named (keyword argument). -
Context.initialize()
: initialize the context. By default, initialize all objects included in the context. -
Context.paint()
: paint all objects. -
Context.resize(width, height)
: resize the context.
This object allows to specify various rendering options: antialiasing, depth buffer, etc., to clear the screen, etc.
Renderer.set_antialiasing(options)
Renderer.set_depth(options)
Renderer.set_blend(options)
Renderer.enable(glname)
Renderer.clear(buffers)
The GLObject is a base class for all objects that can be added to the context.
The Shaders objects allows to specify the shaders codes, to compile them, activate/deactivate them.
Shaders.set_vertex_shader(code)
Shaders.set_fragment_shader(code)
-
Shaders.add_uniform(name, dtype, size=None)
:dtype
is [I]VEC[234] -
Shaders.set_uniform(name, value)
: set a value for a uniform. -
Shaders.add_attribute(name, vertex_buffer)
: link a shader attribute to a VertexBuffer object. Shaders.initialize()
Shaders.activate()
Shaders.deactivate()
Shaders.cleanup()
The VertexBuffer defines a vertex buffer which can be accessed as an attribute in the vertex shader.
VertexBuffer.set_dtype(dtype)
VertexBuffer.set_data(data)
VertexBuffer.initialize()
VertexBuffer.activate()
VertexBuffer.deactivate()
VertexBuffer.cleanup()
The IndexBuffer defines an index buffer.
IndexBuffer.set_data(data)
IndexBuffer.initialize()
IndexBuffer.activate()
IndexBuffer.deactivate()
IndexBuffer.cleanup()
The Texture defines a texture buffer which can be accessed as an sampler in the fragment shader.
-
Texture.set_info(ndim, dtype, params, index)
: set the texture information for the specified texture index (used for multi texturing) ndim is the number of dimensions of the texture (between 1 and 3). Generally dtype=UINT8. params is a TextureParams object with various information about the texture: filtering options, mipmapping, clamp options, etc. Texture.set_data(data, shape, index)
Texture.initialize()
-
Texture.activate(index)
: bind the texture. -
Texture.deactivate()
: unbind the texture. -
Texture.cleanup()
: release all resources.
The Painter allows to render a vertex buffer.
Painter.set_info(ptype, offset, size)
Painter.paint()
The PainterMulti allows to render multiple primitives from a single vertex buffer.
PainterMulti.set_info(ptype, first, count, primcount)
PainterMulti.paint()
The PainterIndexed allows to render from a vertex buffer and an index buffer.
PainterIndexed.set_info(ptype, size)
PainterIndexed.paint()