python - Pyglet OpenGL 设置雾颜色

标签 python python-3.x opengl ctypes pyglet

我想知道如何使用 pyglet.gl 设置雾颜色。

我在 documentation 中找不到有关雾颜色的信息,但我发现this有用。然而我写的代码

pyglet.gl.glFogfv(gl.GL_FOG_COLOR, (0.5, 0.7, 1.0, 1.0))

产生错误:ctypes.ArgumentError: argument 2: <class 'TypeError'>: expected LP_c_float instance instead of tuple

我不确定如何从我的颜色元组中给它一个 LP_c_float,因为它在 pyglet.gl 或上述文档中找不到。

最佳答案

第二个参数 pyglet.gl.glFogfv 是一个 4 个 float 的数组,sp 你必须通过 (GLfloat * 4) 创建一个 ctypes 数组,参见 pyglet.gl.glFogfv :

pyglet.gl.glFogfv(gl.GL_FOG_COLOR, (GLfloat * 4)(0.5, 0.7, 1.0, 1.0))

参见 ctypes — A foreign function library for Python - Arrays:

Arrays are sequences, containing a fixed number of instances of the same type.

The recommended way to create array types is by multiplying a data type with a positive integer:

TenPointsArrayType = POINT * 10

关于python - Pyglet OpenGL 设置雾颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53133993/

相关文章:

python - Gtk3:设置固定的窗口大小(小于子部件请求的大小)

c - 无法渲染颜色立方体

python - Zbar + python,导入时崩溃(OSX 10.9.1)

python - 为什么这种使用函数参数的方式不起作用?

python-3.x - Pycharm:如何从字典内部重构代码

python - 根据类型过滤类的属性

linux - 带有 NVIDIA 驱动程序的 Mesa header (linux)

opengl - 如何将多重采样深度缓冲区解析为深度纹理?

python - 正则表达式在特定字符前面移动子字符串

python - NumPy:使用 'np.save()' 和 'allow_pickle=False' 的后果