如何在 DirectX 上加载纹理?
我使用此代码加载纹理:
HRESULT hr = D3DXCreateTextureFromFile(d3ddev, "test.bmp", &g_texture);
但它总是返回 D3DXERR_INVALIDDATA
错误!
我正在渲染的三角形工作得很好,所以程序的其余部分正在工作,除了纹理加载。
我错过了什么?该文件肯定存在。我也尝试过使用 jpg 和 png,以及尺寸为 256x256 的较小图像。该图像对我来说效果很好......所以它不能是无效数据,即使它这么说。
Im using this code to load a texture:
HRESULT hr = D3DXCreateTextureFromFile(d3ddev, "test.bmp", &g_texture);
But it always returns D3DXERR_INVALIDDATA
error!
The triangle i am rendering works just fine, so rest of the program is working, except texture loading.
What i have missed? the file exists for sure. i tried with jpg and png as well, and with smaller image with size 256x256. the image works just fine with me.. so it cant be invalid data, even though it says so.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最有可能的是,即使该文件可用,但它并不位于程序访问的正确路径中。
如果您在 Visual Studio 中运行程序,请确保工作目录指向包含
test.bmp
的文件夹。不幸的是,这个设置的位置在不同版本的 VS 之间变化很大,但在 VS 2005 中它是Project->Properties->Debugging->Working Directory
。确保调试和发布模式具有相同的设置。您可以通过代码使用 GetCurrentDirectory。
Most likely, even though the file is available, it is not in the correct path for the program to access.
If you are running your program from within Visual Studio, make sure the working directory is pointing to the folder which contains your
test.bmp
. Unfortunately the location of this setting changes a lot between different versions of VS, but in VS 2005 it isProject->Properties->Debugging->Working Directory
. Make sure you have the same setting for both Debug and Release mode.You can check your current directory through code with GetCurrentDirectory.