不是直接使用 opengl, 而是 glumpypython
Glumpy is organized around three main modules:app
The Application layer (app) package is responsible for opening a window and handling user events such as mouse and keyboard interactions. The OpenGL object oriented layer (gloo) package is responsible for handling shader programs and syncing CPU/GPU data through the numpy interface. The Graphic layer (graphics) package provides higher-level common objects such as text, collections and widgets. Those modules will help us writing any OpenGL program quite easily.ide
from glumpy import app, gloo, gl vertex = """ attribute vec2 position; void main(){ gl_Position = vec4(position, 0.0, 1.0); } """ fragment = """ void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); } """ # Create a window with a valid GL context window = app.Window() # Build the program and corresponding buffers (with 4 vertices) quad = gloo.Program(vertex, fragment, count=4) # Upload data into GPU quad['position'] = (-1,+1), (+1,+1), (-1,-1), (+1,-1) # Tell glumpy what needs to be done at each redraw @window.event def on_draw(dt): window.clear() quad.draw(gl.GL_TRIANGLE_STRIP) # Run the app app.run()
報錯的地點在ui
"/home/user/anaconda3/lib/python3.6/site-packages/glumpy/ext/glfw.py", line 482, in glfwCreateWindow title = title.encode("ascii")
這裏,程序是使用 ascii 來 encode,可是對於 python3 來講,系統會默認是 utf-8 來進行 encode,所以會產生矛盾從而報錯spa
source:http://in355hz.iteye.com/blog/1860787code
這裏作法比較危險,直接修改 GLFW3 的源程序。擔憂後面所以還會出現bug,特此記錄blog
line482: title = title.encode("ascii") -> title.encode("utf-8")