将 4 个角转换为矩阵,以便 OpenGL 到 Direct3D 精灵转换
我正在为滚动游戏开发套件编写代码。该程序的旧版本 (2.0) 基于 DirectX,并使用 Direct3D Sprite 对象来绘制所有图形。它使用 sprite 对象的 Transform 属性来指定纹理矩形在输出到显示器时如何进行转换。当前版本 (2.1) 是对 OpenGL 的转换,并使用 GL TexCoord2 和 GL Vertex2 调用来发送用于绘制精灵的源和输出矩形的坐标。现在有人说他们的显卡与 DirectX 配合得很好,但他们的 OpenGL 驱动程序不支持使用 NPOTS 纹理所必需的 GL_ARB(非常基本)。所以我尝试回到 DirectX,而不将所有内容恢复到 2.0。不幸的是,给定一个矩阵得到 4 个点似乎比给定 4 个点得到一个矩阵容易得多。我已经取消了 2.1 版本中的所有矩阵信息,因此当调用在显示器上绘制图像的函数时,我只剩下 4 个角点。有没有办法使用 4 个角信息来转换 Direct3D Sprite?
另外,有人知道为什么 DirectX 能够做一些 OpenGL 不能做的事情吗?某些显卡驱动程序是否那么糟糕,DirectX 支持 NPOTS 纹理,而 OpenGL 不支持?
I am working on code for Scrolling Game Development Kit. An old release (2.0) of this program was based on DirectX and was using Direct3D Sprite objects to draw all the graphics. It used the Transform property of the sprite object to specify how the texture rectangle would be transformed as it was being output to the display. The current release (2.1) was a conversion to OpenGL and is using GL TexCoord2 and GL Vertex2 calls to send coordinates of the source and output rectangles for drawing sprites. Now someone says that their video card worked great with DirectX, but their OpenGL drivers do not support GL_ARB necessary to use NPOTS textures (pretty basic). So I'm trying to go back to DirectX without reverting everything back to 2.0. Unfortunately it seems it's much easier to get 4 points given a matrix than it is to get a matrix given 4 points. I have done away with all the matrix info in version 2.1 so I only have the 4 corner points left when calling the function that draws images on the display. Is there any way to use the 4 corner information to transform a Direct3D Sprite?
Alternatively does anybody know why DirectX would be able to do something than OpenGL can't -- are some video cards' drivers just that bad where DirectX supports NPOTS textures but OpenGL doesn't?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能值得阅读一下他们如何进行凹凸贴图。请参阅此网站。最终得到一个切线空间矩阵,它从世界空间映射到切线空间(相对于当前面的空间)。其目的是在世界空间中获取一个向量,通常是来自光的向量,并将其转换为切线空间中的向量,即纹理定义表面法线的空间。
无论如何,如果你反转该矩阵,你就会d 有一个从切线空间到世界空间的映射。我认为这就是你想要的?该教程中生成的映射纯粹针对方向向量,但扩展到 4x4 并将原点锚定在有意义的地方应该不难。
It's probably worth reading up on how they do bump mapping. See e.g. this site. You end up with a tangent space matrix, which maps from world space to tangent space (the space relative to the current face). The purpose of that is taking a vector in world space, generally a vector from a light, and converting it into a vector in tangent space, that being the space that your texture defines surface normals in.
Anyway, if you inverted that matrix you'd have a mapping from tangent space to world space. Which I think is what you want? The mapping produced in that tutorial is purely for direction vectors, but expanding out to a 4x4 and anchoring the origin somewhere meaningful shouldn't be difficult.