使用 OpenGL 遇到的 Bug - ''ascii' code encode

''ascii' codec can't encode characters'

envs:

不是直接使用 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

code:

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")
相关文章
相关标签/搜索