https://github.com/tianzhuqiao/glsurface
show 2d/3d data with wxpython and pyopengl
https://github.com/tianzhuqiao/glsurface
opengl pyopengl wxpython
Last synced: 4 months ago
JSON representation
show 2d/3d data with wxpython and pyopengl
- Host: GitHub
- URL: https://github.com/tianzhuqiao/glsurface
- Owner: tianzhuqiao
- License: mit
- Created: 2018-03-20T04:25:18.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-03-01T00:00:03.000Z (over 1 year ago)
- Last Synced: 2025-09-10T22:32:15.937Z (9 months ago)
- Topics: opengl, pyopengl, wxpython
- Language: Python
- Homepage:
- Size: 8.33 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# glsurface
**glsurface** is a python class to show 2d/3d data with [wxPython](https://wxpython.org/) and [PyOpenGL](https://pyopengl.sourceforge.net/).
## Installation
```shell
$ pip install glsurface
```
## Usage
1. Create a class from `TrackingSurface`
```python
class Surface(TrackingSurface):
def __init__(self, *args, **kwargs):
TrackingSurface.__init__(self, *args, **kwargs)
...
```
2. Create an instance, and set data (optional)
```python
class SurfacePanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
...
self.x = np.linspace(0, 2 * np.pi, 30).reshape((1, 30))
z = np.cos(self.x).T * np.sin(self.x)
self.canvas = Surface(self, {'z': z})
...
```
3. Update the data
1. Add new frame data to the current frame buffer
```python
self.canvas.NewFrameArrive(z, silent=False)
```
2. Or reset the frame buffer with new data
```python
self.canvas.SetFrames(points, reset_buf_len=True, silent=False)
```
Check `gltest.py` for details.
## Known issues
1. On Linux, it may show the following error.
```bash
OpenGL.error.Error: Attempt to retrieve context when no valid context
```
In this case, try different OpenGL platform, e.g.,
```bash
$ export PYOPENGL_PLATFORM='egl'
```
All supported platforms can be found here `/path/to/python/site-packages/OpenGL/__init__.py`
2. For EGL Surface, you may need to call `CreateSurface`, as mentioned [here](https://docs.wxpython.org/wx.glcanvas.GLCanvas.html#wx.glcanvas.GLCanvas.CreateSurface)