在Directx中加载纹理

问题描述:

我正在尝试在Directx中加载纹理以绘制纹理四边形。

Im Trying to load textures in directx to draw a textured quad.

但是D3DXCreateTextureFromFile永远不会返回D3D_OK...。

but the D3DXCreateTextureFromFile never returns D3D_OK ....

这是我的代码,用于加载纹理。...

here is my code to load the texture....

FeralTexture(string Name,FeralVector2 Position,IDirect3DDevice9 *device)
    {
        FileName = Name;
        m_pDevice = device;
        x= Position.x;
        y= Position.y;
        if(D3DXCreateTextureFromFile(m_pDevice,FileName.c_str(),&m_pTextureFile) != D3D_OK)
        {
            TextureCreated = false;
            m_pTextureFile = NULL;
            D3DXCreateTextureFromFile(m_pDevice,FileName.c_str(),&m_pTextureFile);
        }
        else
        {
            if(D3DXGetImageInfoFromFile(FileName.c_str(),&ImageInfo) == D3D_OK)
            {
                TextureCreated = true;
                Width = ImageInfo.Width;
                Height = ImageInfo.Height;
                MinVector = FeralVector2(x,y);
                MaxVector = FeralVector2(x+Width,y+Height);
                //BoundingRect = FeralRect2(MinVector,MaxVector);
            }
            else
            {
                Width = 0;
                Height = 0;
            }
        }
    }

我放置了图像的副本在我的项目的调试文件夹和项目的主文件夹中……
都不起作用...。

i placed copies of the image in both the debug folder of my project and in the main folder of my project... neither works....

任何输入将不胜感激....

Any input will be greatly appreciated ....

始终检查错误代码!

此处是一个辅助宏,用于将错误代码转换为人类可读的错误消息:

Here is a helper macro to transform error codes to human-readable error message:

#include <dxerr.h>

#if defined(DEBUG) | defined(_DEBUG)
#ifndef HR
#define HR(x)                                          \
    {                                                  \
        HRESULT hr = x;                                \
        if (FAILED(hr))                                \
        {                                              \
        DXTrace(__FILE__, __LINE__, hr, #x, TRUE);     \
        }                                              \
    }
#endif

#else
#ifndef HR
#define HR(x) x;
#endif
#endif 

和用法:

HR(D3DXCreateTextureFromFile(...))