在Directx中加载纹理 [英] Loading Textures in Directx

查看:180
本文介绍了在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(...))

这篇关于在Directx中加载纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆