Pyglet OpenGL 设置雾颜色

Pyglet OpenGL Setting Fog Color

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

我在 documentation, but I found 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 个浮点数的数组,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