Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #197802

gl.gl_xxx → gl.xx, GL.GL_XXX → GL.XXX

Path csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From Lawrence D’Oliveiro <ldo@nz.invalid>
Newsgroups comp.lang.python
Subject gl.gl_xxx → gl.xx, GL.GL_XXX → GL.XXX
Date Sat, 13 Jun 2026 05:37:27 -0000 (UTC)
Organization A noiseless patient Spider
Lines 39
Message-ID <110iqam$2nbfk$1@dont-email.me> (permalink)
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Sat, 13 Jun 2026 05:37:27 +0000 (UTC)
Injection-Info dont-email.me; logging-data="2862580"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ETQiYG8ZJvenwkWJUMd4H"; posting-host="658e5ae187a292a06abb93e11316dd9d"
User-Agent Pan/0.165 (Kostiantynivka)
Cancel-Lock sha1:VOxqSF/wKTLc1g3JdhpA+2vnX/k= sha256:8dGJOUW1CUQfnsPqgeVrZk5L9XdnR1Z/ZJvEwhezTJI= sha1:UNnoisgpkG3V/2MVcW0vEmD6rrk=
Xref csiph.com comp.lang.python:197802

Show key headers only | View raw


import types
import OpenGL
import OpenGL.GL
import OpenGL.GLU

def gen_gl() :
    # Funny thing: the OpenGL specs document all routines and
    # constants *without* “gl” and “GL_” prefixes. It makes
    # sense to add these in a language that does not have
    # namespaces, like C. In Python, it does not. So this
    # routine takes apart the contents of the PyOpenGL modules
    # into separate pieces, with those unnecessary prefixes
    # stripped. So instead  of calling OpenGL.GL.glClear(), say,
    # you can call gl.Clear(). And instead of referring to
    # OpenGL.GL.GL_ACCUM, you can use GL.ACCUM instead.
    # Much more concise all round.
    gl = types.ModuleType("gl", doc = "OpenGL routines")
    GL = types.ModuleType("GL", doc = "OpenGL constants")
    glu = types.ModuleType("glu", doc = "OpenGL utility routines")
    GLU = types.ModuleType("GLU", doc = "OpenGL utility constants")
    for prefix, src, dest in \
        (
            ("gl", OpenGL.GL, gl),
            ("GL_", OpenGL.GL, GL),
            ("glu", OpenGL.GLU, glu),
            ("GLU_", OpenGL.GLU, GLU),
        ) \
    :
        for name in dir(src) :
            if name.startswith(prefix) :
                setattr(dest, name[len(prefix):], getattr(src, name))
            #end if
        #end for
    #end for
    return \
        gl, GL, glu, GLU
#end gen_gl
gl, GL, glu, GLU = gen_gl()
del gen_gl # your work is done

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

gl.gl_xxx → gl.xx, GL.GL_XXX → GL.XXX Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-13 05:37 +0000

csiph-web