Alternatives to glPushMatrix() & co. in Pyglet 2.0?

huangapple go评论74阅读模式
英文:

Alternatives to glPushMatrix() & co. in Pyglet 2.0?

问题

我正在使用Pyglet 2.0。

我发现Pyglet 2.0已经删除了许多OpenGL函数,比如glPushMatrix()。在这个新版本中,我们应该使用什么替代方法?用于管理旋转、平移、缩放等的替代技术是什么?

英文:

I am using Pyglet 2.0

I've found that Pyglet 2.0 has removed a lot of OpenGL functions such as glPushMatrix(). What should we be doing instead in this new version? What is the alternative technique for managing rotations, translations, scaling, etc?

答案1

得分: 1

免责声明:我自己从未使用过pyglet。

看起来pyglet已经移除了旧式的“立即模式”OpenGL 1.x的功能,而期望用户改用通常称为“现代OpenGL”的方式。在现代OpenGL中,你确实没有矩阵辅助函数,矩阵状态由驱动程序处理,而你需要使用其他库来在CPU上设置和处理矩阵。对于在GPU上处理矩阵,你需要使用GLSL着色器。

如果没有别的选择,Python至少有numpy,它非常适合进行矩阵运算,尽管它更多地是一个通用工具,而不是专门用于3D图形。还有似乎有https://pypi.org/project/PyGLM/,它是与现代OpenGL一起使用的常用GLM库的绑定,当使用C++时常常一起使用(或者在使用纯C时使用cglm)。

我建议你查看一些关于现代OpenGL编程的教程,然后尝试使用pyglet重新创建那里的概念。

英文:

Disclaimer: I have never used pyglet myself.

It seems that pyglet has removed functionality for the old school 'immediate mode' OpenGL 1.x, and expects the user to instead use what is commonly known as 'modern OpenGL'. In modern OpenGL you indeed don't have the matrix helper functions with the matrix state handled by the driver, instead you are expected to use some other library for setting up and wrangling matrices on the CPU. For matrix handling on the GPU you use GLSL shaders.

If nothing else, python at least has numpy which is perfectly capable of matrix math, though it's more a general purpose tool and not specific to 3D graphics. There also seems to be https://pypi.org/project/PyGLM/ , a binding to the popular GLM library which is commonly used together with modern OpenGL when using C++ (or cglm when using plain C).

I recommend that you check out some tutorial on modern OpenGL programming, and then try to recreate the concepts there with pyglet.

答案2

得分: 0

With Pyglet 2.0OpenGL 3.3+),你应该使用矩阵Pyglet现在通过 `pyglet.math.Mat4` 内置支持它们通过 `window.view``window.projection`,窗口可以访问这些矩阵

例如

平移:`glTranslatef(x, y, z)` 变为 `window.view = window.view.translate((x, y, z))`

缩放:`glScalef(zoom, zoom, 1)` 变为 `window.view = window.view.scale((zoom, zoom, 1))`

正交投影
```python
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.glOrtho(0, width, 0, height, -255, 255)
gl.glMatrixMode(gl.GL_MODELVIEW)

变为:

window.projection = pyglet.math.Mat4.orthogonal_projection(
    0, width, 0, height, -255, 255
)

<details>
<summary>英文:</summary>

With Pyglet 2.0 (OpenGL 3.3+) you should be using Matrixes. Pyglet offers them built in now via `pyglet.math.Mat4`. The window has these matrices accessible via `window.view` and `window.projection`

For example:

Translation	: `glTranslatef(x, y, z)` becomes `window.view = window.view.translate((x, y, z))`

Scaling : `glScalef(zoom, zoom, 1)` becomes `window.view = window.view.scale((zoom, zoom, 1))`

Orth Projection:

gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.glOrtho(0, width, 0, height, -255, 255)
gl.glMatrixMode(gl.GL_MODELVIEW)

Becomes:

window.projection = pyglet.math.Mat4.orthogonal_projection(
0, width, 0, height, -255, 255
)


</details>



huangapple
  • 本文由 发表于 2023年5月30日 06:27:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76360639.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定