Skip to main content

Intuitive OpenGL wrappers

Project description

Intuitive OpenGL 3 wrappers.

Code example

The following code creates a window displaying a rotating quad:

from math import cos, sin
from glitter import VertexArray, get_default_program
from glitter.contexts.glut import GlutWindow, main_loop, get_elapsed_time

vertices = ((0, 0, 0), (-1, 1, 0), (1, 1, 0), (1, -1, 0), (-1, -1, 0))
colors = ((1, 1, 1), (0, 1, 0), (0, 0, 1), (0, 1, 1), (1, 0, 0))
indices = ((0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 1))

def display():
    window.clear()
    vao.draw()
    window.swap_buffers()

def timer():
    phi = get_elapsed_time()
    shader.modelview_matrix = (
                    ( cos(phi), sin(phi), 0, 0),
                    (-sin(phi), cos(phi), 0, 0),
                    (        0,        0, 1, 0),
                    (        0,        0, 0, 2)
            )
    window.add_timer(10, timer)
    window.post_redisplay()

if __name__ == "__main__":
    window = GlutWindow(double=True, multisample=True)
    window.display_callback = display
    shader = get_default_program()
    vao = VertexArray([vertices, colors], elements=indices)
    timer()
    with shader:
        main_loop()

Design principles

  • Glitter wraps the OpenGL 3 core profile only. This allows for a pythonic representation of (eventually) the complete OpenGL API, while any nuts and bolts are readily supplied by Python and numpy.

  • Inituitive use is chosen over performance (no premature optimization; make it run, then make it fast). Users do not need to (nor should they) use raw GL functions at any time.

  • OpenGL objects (e.g., textures, buffers, or shader programs) are represented by Python objects.

  • All GL state changes go through either a context object or a responsible object, for example:

    • Vertex attribute pointer bindings are performed by vertex array objects.

    • Settings for draw buffers other than the screen are performed by framebuffer objects.

    • Texture bindings are performed by shader programs. An available texture unit is chosen automatically.

  • Array data (e.g. texture images or vertex buffer data) is represented in numpy.

  • Glitter has a focus on GPGPU computing, but typical use for rendering should be as easy.

  • Platform independence is be sought for, although Linux/GLX is currently the primary target. Any experiences with other platforms are very welcome.

Dependencies

Build instructions

  • installing: sudo python setup.py install

  • docs: epydoc –html -v -o docs glitter examples tests

  • tests: nosetests tests

OpenGL 3 notes

The distribution includes the official OpenGL 3 header file from http://www.opengl.org/registry/api/gl3.h, with the following bugfixes applied:

The following functions are not part of the core profile and have been removed:

GLAPI void APIENTRY glVertexP2ui (GLenum type, GLuint value);
GLAPI void APIENTRY glVertexP2uiv (GLenum type, const GLuint *value);
GLAPI void APIENTRY glVertexP3ui (GLenum type, GLuint value);
GLAPI void APIENTRY glVertexP3uiv (GLenum type, const GLuint *value);
GLAPI void APIENTRY glVertexP4ui (GLenum type, GLuint value);
GLAPI void APIENTRY glVertexP4uiv (GLenum type, const GLuint *value);
GLAPI void APIENTRY glTexCoordP1ui (GLenum type, GLuint coords);
GLAPI void APIENTRY glTexCoordP1uiv (GLenum type, const GLuint *coords);
GLAPI void APIENTRY glTexCoordP2ui (GLenum type, GLuint coords);
GLAPI void APIENTRY glTexCoordP2uiv (GLenum type, const GLuint *coords);
GLAPI void APIENTRY glTexCoordP3ui (GLenum type, GLuint coords);
GLAPI void APIENTRY glTexCoordP3uiv (GLenum type, const GLuint *coords);
GLAPI void APIENTRY glTexCoordP4ui (GLenum type, GLuint coords);
GLAPI void APIENTRY glTexCoordP4uiv (GLenum type, const GLuint *coords);
GLAPI void APIENTRY glMultiTexCoordP1ui (GLenum texture, GLenum type, GLuint coords);
GLAPI void APIENTRY glMultiTexCoordP1uiv (GLenum texture, GLenum type, const GLuint *coords);
GLAPI void APIENTRY glMultiTexCoordP2ui (GLenum texture, GLenum type, GLuint coords);
GLAPI void APIENTRY glMultiTexCoordP2uiv (GLenum texture, GLenum type, const GLuint *coords);
GLAPI void APIENTRY glMultiTexCoordP3ui (GLenum texture, GLenum type, GLuint coords);
GLAPI void APIENTRY glMultiTexCoordP3uiv (GLenum texture, GLenum type, const GLuint *coords);
GLAPI void APIENTRY glMultiTexCoordP4ui (GLenum texture, GLenum type, GLuint coords);
GLAPI void APIENTRY glMultiTexCoordP4uiv (GLenum texture, GLenum type, const GLuint *coords);
GLAPI void APIENTRY glNormalP3ui (GLenum type, GLuint coords);
GLAPI void APIENTRY glNormalP3uiv (GLenum type, const GLuint *coords);
GLAPI void APIENTRY glColorP3ui (GLenum type, GLuint color);
GLAPI void APIENTRY glColorP3uiv (GLenum type, const GLuint *color);
GLAPI void APIENTRY glColorP4ui (GLenum type, GLuint color);
GLAPI void APIENTRY glColorP4uiv (GLenum type, const GLuint *color);
GLAPI void APIENTRY glSecondaryColorP3ui (GLenum type, GLuint color);
GLAPI void APIENTRY glSecondaryColorP3uiv (GLenum type, const GLuint *color);

The following constants are missing and have been defined:

#define GL_POLYGON_MODE                   0x0B40

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glitter-0.1.1.tar.gz (83.2 kB view details)

Uploaded Source

File details

Details for the file glitter-0.1.1.tar.gz.

File metadata

  • Download URL: glitter-0.1.1.tar.gz
  • Upload date:
  • Size: 83.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for glitter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 76c558d9b631e0a26f6d9c1f6d7fe7a4cdd6ff22c11db42493a2f8ae7cd1f558
MD5 78e85f600e4bdcf5015bd535522b1d7d
BLAKE2b-256 fe493680827c784c3e30152a767fc98e3f4e4699f00fcb1d3a7ba61a49a4dcc3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page