SDL_Surface 到 IDirect3DTexture
任何人都可以帮助将 SDL_Surface 对象(从文件加载的纹理)转换为 IDirect3DTexture9 对象吗?
Can anybody help with converting an SDL_Surface object, a texture loaded from a file, into an IDirect3DTexture9 object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,我不知道你为什么想要这样做。由于各种原因,这听起来确实是一个可怕的想法,所以请告诉我们您为什么要这样做,以便我们可以说服您不要这样做;)。
同时,快速概述一下您将如何进行操作:
这将创建具有 SDL_Surface 的大小和格式的实际纹理。您必须自己填写用法,具体取决于您想要如何使用它(请参阅 D3DUSAGE)。您还必须自己确定格式 - 您不能直接将 SDL_PixelFormat 映射到 D3DFORMAT。这并不容易,除非您确切知道 SDL_Surface 是什么像素格式。
现在,您需要将数据写入纹理中。您不能在这里直接使用 memcpy,因为 SDL_Surface 和实际纹理可能有不同的步长。以下是一些未经测试的代码,可以为您执行此操作:
I honestly don't know why you would ever want to do this. It sounds like a truly horrible idea for a variety of reasons, so please tell us why you want to do this so we can convince you not to ;).
In the meanwhile, a quick overview of how you'd go about it:
This creates the actual texture with the size and format of the SDL_Surface. You'll have to fill in the usage on your own, depending on how you want to use it (see D3DUSAGE). You'll also have to figure out the format on your own - you can't directly map a SDL_PixelFormat to a D3DFORMAT. This won't be easy, unless you know exactly what pixel format your SDL_Surface is.
Now, you need to write the data into the texture. You can't use straight memcpy here, since the SDL_Surface and the actual texture may have different strides. Here's some untested code that may do this for you: