openGL 用于矩阵堆栈
我有一个 win32 应用程序,我想在其中使用 openGL 仅用于其矩阵堆栈,而不是用于任何渲染。也就是说,我想使用 openGL 来指定相机、视口等,这样我就不必再次进行数学计算。创建场景时,我只想使用 gluProject 投影点并使用它。投影点被传递到另一个库,该库为我创建场景,所有窗口句柄都是由库本身创建的,我无权访问它。
问题是,Windows 需要设备上下文来进行初始化。但是,由于我没有使用 openGL 进行任何渲染,有没有办法在没有任何窗口句柄的情况下使用 openGL?
如果没有任何显式初始化,当我使用 glGet 读回矩阵时,它会返回垃圾。有想过如何解决它吗?
I have a win32 application, in which I want to use openGL just for its matrix stack not for any rendering. That is, I want to use openGL to specify the camera, viewport etc so that I dont have to do the maths again. While creating the scene, I just want to project the points using gluProject and use it. The projected points are passed to another library which creates the scene for me, all the windows handles are created by library itself and I dont have access to that.
The problem is, windows needs a device context for initialization. But, since I am not using openGL for any rendering, is there a way to use openGL without any Window handle at all?
Without any explicit initialization, when I read back the matrices using glGet, it returns a garbage. Any thought on how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这不是 OpenGL 的目的。 OpenGL 是一个绘图/渲染 API,不是一个数学库。实际上,出于这个原因,整个矩阵数学内容已从最新的 OpenGL 版本(OpenGL-3 核心及更高版本)中剥离。
而且,做这个矩阵数学的事情非常简单,你可以用不到 1k 行的 C 代码把它写下来。为此滥用 OpenGL 绝对没有任何好处。
That's not what OpenGL is meant for. OpenGL is a drawing/rendering API, not a math library. Actually the whole matrix math stuff has been stripped away from the latest OpenGL versions (OpenGL-3 core and later), for that very reason.
Also doing this matrix math stuff is so simple, you can write it down in less than 1k lines of C code. There's absolutely no benefit in abusing OpenGL for this.
在您的实现中,Matrix 堆栈可能存在于图形硬件上。因此,OpenGL 坚持要求您拥有 OpenGL 上下文以便能够使用此类功能,这是相当合理的。这是因为创建上下文的行为可能包括设置存储矩阵堆栈所需的必要实现机制。
即使在纯粹基于软件的 OpenGL 实现中,人们仍然期望创建上下文的行为来调用与 malloc 等效的函数来保护堆栈的存储空间。如果您碰巧发现不需要创建上下文的 OpenGL 实现,我仍然会避免依赖该行为,因为它很可能是未定义的,并且可能会在该实现的下一个版本中被破坏。
如果是 C++,如果您没有将 OpenGL 用于除此以外的任何用途,我只会将
std::stack
与您最喜欢的线性代数包中的Matrix
类一起使用。The Matrix stack could potentially live on graphics hardware in your implementation. OpenGL is quite reasonable therefore in insisting you have an OpenGL context in order to be able to use such functions. This is because the act of creating a context probably includes setting up the necessary implementation mechanics required to store the matrix stack.
Even in a purely software based OpenGL implementation one would still expect the act of creating a context to call some equivalent to
malloc
to secure the storage space for the stack. If you happened to find an OpenGL implementation where creating a context wasn't necessary I'd still keep clear of relying on that behavior since it's most likely undefined and could be broken in the next release of that implementation.If it's C++ I'd just use
std::stack
with theMatrix
class from your favorite linear algebra package if you're not using OpenGL for anything other than that.我向您展示我完整的(开源)矩阵类。享受。
https://github.com/TheBuzzSaw/paroxysm/blob/master /newsource/CGE/Matrix4x4.h
I present to you my complete (open source) matrix class. Enjoy.
https://github.com/TheBuzzSaw/paroxysm/blob/master/newsource/CGE/Matrix4x4.h
我建议您尝试自己实现这些调用。我曾为我编写的 Palm 应用程序 tinyGL 做过一次。我了解到,文档基本上以纯文本形式告诉您做了什么。
即
tglFrustum
和tglOrth
的逐字代码是(请注意,我使用定点数学来获得一些性能)将它们与 glFrustum 和 glOrtho
I can recommend trying to implement those calls yourself. I did that once for a Palm app I wrote, tinyGL. What I learnt was that the documentation basically tells you in plain text what is done.
i.e the verbatim code for
tglFrustum
andtglOrth
are (note that I was using fix point math to get some performance)Compare those with the man pages for glFrustum and glOrtho