Skip to main content

Requirements

  • Python 2.7

Features

  • glut window

  • tkinter’s togl widget

  • wxPython’s GLCanvas widget

  • pyQt4’s qgl widget

  • win32api wgl

Controller convention

you should inherit glglue.BaseController and implement follow methods.

  • onUpdate

  • onLeftDown

  • onLeftUp

  • onMiddleDown

  • onMiddleUp

  • onRightDown

  • onRightUp

  • onMotion

  • onResize

  • onWheel

  • onKeyDown

  • draw

see SampleController in glglue/sample/__init__.py

Samples

glut

requrie pyOpenGL

import glglue.sample
import glglue.glut

if __name__=="__main__":
    controller=glglue.sample.SampleController()
    glglue.glut.mainloop(controller)

tkinter

requrie pyOpenGL + togl install

Togl install on Windows

  • download Togl2.0-8.4-Windows.zip

  • copy Togl2.0-8.4-Windows/lib/Togl2.0 to C:/PythonXX/tcl/Togl2.0

import sys
import Tkinter as tkinter
import glglue.togl
import glglue.sample
class Frame(tkinter.Frame):
    def __init__(self, width, height, master=None, **kw):
        #super(Frame, self).__init__(master, **kw)
        tkinter.Frame.__init__(self, master, **kw)
        # setup opengl widget
        self.controller=glglue.sample.SampleController()
        self.glwidget=glglue.togl.Widget(
                self, self.controller, width=width, height=height)
        self.glwidget.pack(fill=tkinter.BOTH, expand=True)
        # event binding(require focus)
        self.bind('<Key>', self.onKeyDown)
        self.bind('<MouseWheel>', lambda e: self.glworld.onWheel(-e.delta) and self.glwidget.onDraw())

    def onKeyDown(self, event):
        key=event.keycode
        if key==27:
            # Escape
            sys.exit()
        if key==81:
            # q
            sys.exit()
        else:
            print("keycode: %d" % key)

f = Frame(width=600, height=600)
f.pack(fill=tkinter.BOTH, expand=True)
f.focus_set()
f.mainloop()

wxPython

require pyOpenGL + wxPython

import wx
import glglue.sample
import glglue.wxglcanvas
class Frame(wx.Frame):
    def __init__(self, parent, **kwargs):
        super(Frame, self).__init__(parent, **kwargs)
        # setup opengl widget
        self.controller=glglue.sample.SampleController()
        self.glwidget=glglue.wxglcanvas.Widget(self, self.controller)
        # packing
        sizer=wx.BoxSizer(wx.HORIZONTAL)
        self.SetSizer(sizer)
        sizer.Add(self.glwidget, 1, wx.EXPAND)

app = wx.App(False)
frame=Frame(None, title='glglue')
frame.Show()
app.MainLoop()

pyQt4

require pyOpenGL + pyQt4

from PyQt4 import Qt
import glglue.sample
import glglue.qgl
class Window(Qt.QWidget):
    def __init__(self, parent=None):
        Qt.QWidget.__init__(self, parent)
        # setup opengl widget
        self.controller=glglue.sample.SampleController()
        self.glwidget=glglue.qgl.Widget(self, self.controller)
        # packing
        mainLayout = Qt.QHBoxLayout()
        mainLayout.addWidget(self.glwidget)
        self.setLayout(mainLayout)

import sys
app = Qt.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())

pyGame

require pyOpenGL + pyGame

import pygame
from pygame.locals import *
import glglue.sample

if __name__=="__main__":
    pygame.init()
    size=(640, 480)
    screen = pygame.display.set_mode(size,
            HWSURFACE | OPENGL | DOUBLEBUF)

    controller=glglue.sample.SampleController()
    controller.onResize(*size)

    clock = pygame.time.Clock()
    is_running=True
    while is_running:
        # event handling
        for event in pygame.event.get():
            if event.type == QUIT:
                is_running=False
            if event.type == KEYUP and event.key == K_ESCAPE:
                is_running=False
        pressed = pygame.key.get_pressed()

        time_passed = clock.tick()

        # Show the screen
        controller.draw()
        pygame.display.flip()

win32api

require pyOpenGL(experimental…)

import glglue.sample
import glglue.wgl

if __name__=="__main__":
    factory=glglue.wgl.WindowFactory()
    window=factory.create(glglue.wgl.Window, title="sample")
    window.createGLContext(16)
    window.controller=glglue.sample.SampleController()
    window.show()
    import sys
    sys.exit(factory.loop())

short smaple

import glglue.sample
import glglue.wgl

if __name__=="__main__":
    controller=glglue.sample.SampleController()
    glglue.wgl.mainloop(controller, width=640, height=480, title="sample")

History

  • 20120114 0.1.0 implement wxglcanvas mouse event and keyboard event handling

  • 20120113 0.0.9 fix wxglcanvas

  • 20120112 0.0.8 fix lacking of README.rst

  • 20111230 0.0.7 add wgl.mainloop, implement wgl mouse callback

  • 20111230 0.0.4 fix SetWindowLongPtr

  • 20111229 0.0.3 include glglue.sample. add wgl

Download files

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

Source Distribution

glglue-0.1.0.zip (18.5 kB view details)

Uploaded Source

File details

Details for the file glglue-0.1.0.zip.

File metadata

  • Download URL: glglue-0.1.0.zip
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for glglue-0.1.0.zip
Algorithm Hash digest
SHA256 c34318c08d52d7875bd958f085b84461e544362bec9c8acf88c5d9389c772f49
MD5 7aca47c61dc01cfa00d3083cdcde83e7
BLAKE2b-256 94a7815a02c3783dcb68b2cfe153af8b1739276d75b02219ff40c03c4860275d

See more details on using hashes here.

Release history Release notifications | RSS feed

2.5.0

1 file

2.4.0

1 file

2.3.0

1 file

2.1.0

1 file

2.0.0

2 files

1.13.0

2 files

1.12.1

2 files

1.12.0

2 files

1.11.0

2 files

1.10.0

2 files

1.9.0

2 files

1.8.5

2 files

1.8.4

2 files

1.8.3

2 files

1.8.2

2 files

1.8.1

2 files

1.8.0

2 files

1.7.0

2 files

1.6.0

2 files

1.5.5

2 files

1.5.4

2 files

1.5.3

2 files

1.5.2

2 files

1.5.1

2 files

1.5.0

2 files

1.4.2

2 files

1.4.1

2 files

1.4.0

2 files

1.3.1

2 files

1.3.0

2 files

1.2.1

2 files

1.1.0

1 file

1.0.0

1 file

0.3.1

1 file

0.3.0

1 file

0.2.6

1 file

0.2.5

1 file

0.2.4

1 file

0.2.1

1 file

0.2.0

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

This release

0.1.0 This release

1 file

0.0.9

1 file

0.0.8

1 file

0.0.7

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page