|
| 1 | +# pyopengltk |
| 2 | + |
1 | 3 | Tkinter - OpenGL Frame using ctypes |
2 | 4 |
|
| 5 | +* [pyopengltk on Github](https://github.com/jonwright/pyopengltk) |
| 6 | +* [pyopengltk on PyPI](https://pypi.org/project/pyopengltk/) |
| 7 | + |
3 | 8 | An opengl frame for pyopengl-tkinter based on ctypes (no togl compilation) |
4 | 9 |
|
5 | 10 | Collected together by Jon Wright, Jan 2018. |
6 | 11 |
|
7 | | -Based on the work of others |
| 12 | +## Basic Example |
| 13 | + |
| 14 | +This example creates a window containing an `OpenGLFrame` |
| 15 | +filling the entire window. We configure it to animate |
| 16 | +(constantly redraw) clearing the screen using a green color. |
| 17 | +A simple framerate counter is included. |
| 18 | +The context information is printed to the terminal. |
| 19 | + |
| 20 | +```python |
| 21 | +import time |
| 22 | +import tkinter |
| 23 | +from OpenGL import GL |
| 24 | +from pyopengltk import OpenGLFrame |
| 25 | + |
| 26 | +class AppOgl(OpenGLFrame): |
| 27 | + |
| 28 | + def initgl(self): |
| 29 | + """Initalize gl states when the frame is created""" |
| 30 | + GL.glViewport(0, 0, self.width, self.height) |
| 31 | + GL.glClearColor(0.0, 1.0, 0.0, 0.0) |
| 32 | + self.start = time.time() |
| 33 | + self.nframes = 0 |
| 34 | + |
| 35 | + def redraw(self): |
| 36 | + """Render a single frame""" |
| 37 | + GL.glClear(GL.GL_COLOR_BUFFER_BIT) |
| 38 | + tm = time.time() - self.start |
| 39 | + self.nframes += 1 |
| 40 | + print("fps",self.nframes / tm, end="\r" ) |
| 41 | + |
| 42 | + |
| 43 | +if __name__ == '__main__': |
| 44 | + root = tkinter.Tk() |
| 45 | + app = AppOgl(root, width=320, height=200) |
| 46 | + app.pack(fill=tkinter.BOTH, expand=tkinter.YES) |
| 47 | + app.animate = 1 |
| 48 | + app.after(100, app.printContext) |
| 49 | + app.mainloop() |
| 50 | +``` |
| 51 | + |
| 52 | +The repository on Github also contains more examples. |
| 53 | + |
| 54 | +## Install |
| 55 | + |
| 56 | +From PyPI: |
| 57 | + |
| 58 | +``` |
| 59 | +pip install pyopengltk |
| 60 | +``` |
| 61 | + |
| 62 | +From source: |
| 63 | + |
| 64 | +``` |
| 65 | +git clone https://github.com/jonwright/pyopengltk |
| 66 | +cd pyopengltk |
| 67 | +pip install . |
| 68 | +``` |
| 69 | + |
| 70 | +## Attributions |
| 71 | + |
| 72 | +Based on the work of others. |
| 73 | + |
| 74 | +### C + Tcl/Tk example: |
| 75 | + |
| 76 | +* Project URL : http://github.com/codeplea/opengl-tcltk/ (zlib license) |
| 77 | +* Article at : https://codeplea.com/opengl-with-c-and-tcl-tk |
8 | 78 |
|
9 | | -C + Tcl/Tk example: |
10 | | - http://github.com/codeplea/opengl-tcltk/ |
11 | | - (zlib license) |
12 | | - Article at: |
13 | | - https://codeplea.com/opengl-with-c-and-tcl-tk |
| 79 | +### Python + Tkinter (no pyopengl) example: |
14 | 80 |
|
15 | | -Python + Tkinter (no pyopengl) example: |
16 | | - http://github.com/arcanosam/pytkogl/ |
17 | | - (The Code Project Open License) |
18 | | - Article at |
19 | | - http://www.codeproject.com/Articles/1073475/OpenGL-in-Python-with-TKinter |
| 81 | +* Project URL : http://github.com/arcanosam/pytkogl/ (The Code Project Open License) |
| 82 | +* Article at: http://www.codeproject.com/Articles/1073475/OpenGL-in-Python-with-TKinter |
20 | 83 |
|
21 | | -Large regions of code copied from pyopengl/Tk/__init__.py |
| 84 | +### pyopengl |
22 | 85 |
|
| 86 | +* Large regions of code copied from `pyopengl/Tk/__init__.py`. |
0 commit comments