• 大小: 296KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-03
  • 语言: 其他
  • 标签: D3D11  纹理  

资源简介

该示例用于演示D3D11中纹理的基础使用,包括完整的框架源代码及可执行程序。如果可执行程序运行有问题,请自行手动编译程序,有关操作请参考附带的使用说明。程序有任何问题或不解之处,欢迎提出~

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

//定义顶点结构:
// 1. 位置
// 2. 法线
// 3. 纹理坐标
struct Vertex
{
XMFLOAT3 pos;
XMFLOAT3 normal;
XMFLOAT2 tex;
};

class TextureDemo: public WinApp
{
public:
TextureDemo(HINSTANCE hInst std::wstring title = L“D3D11学习 纹理使用“ int width = 640 int height = 480);
~TextureDemo();

bool Init();
bool Update(float delta);
bool Render();

//鼠标控制
void onmousedown(WPARAM btnState int x int y);
void onmouseup(WPARAM btnState int x int y);
void onmousemove(WPARAM btnState int x int y);

private:
bool BuildFX();
bool BuildInputLayout();
bool BuildBuffers();
bool BuildTexture();

private:
ID3D11InputLayout *m_inputLayout;

ID3D11Buffer *m_VB;
ID3D11Buffer *m_IB;

ID3DX11Effect *m_fx;
//针对Effect中的全局变量,在C++中的一对一相应的变量,用于修改Effect变量
ID3DX11EffectShaderResourceVariable *m_fxTex;
ID3DX11EffectMatrixVariable *m_fxWorldViewProj;
ID3DX11EffectMatrixVariable *m_fxWorldInvTranspose;
ID3DX11EffectMatrixVariable *m_fxWorld;
ID3DX11EffectVariable *m_fxSpotLight;
ID3DX11EffectVariable *m_fxMaterial;
ID3DX11EffectVariable *m_fxEyePos;

ID3D11ShaderResourceView *m_texView;
GeoGen::MeshData m_box;
Lights::SpotLight m_spotLight;
Lights::Material m_material;
XMFLOAT3 m_eyePos;

//是否使用光照(聚光灯)
bool m_useLight;

//鼠标控制参数
float m_theta m_phy;
float m_radius;
POINT m_lastPos;
};

TextureDemo::TextureDemo(HINSTANCE hInst std::wstring title int width int height):WinApp(hInsttitlewidthheight)
m_inputLayout(NULL)
m_VB(NULL)
m_IB(NULL)
m_fx(NULL)
m_fxTex(NULL)
m_fxWorldViewProj(NULL)
m_texView(NULL)
m_useLight(false)
m_theta(XM_PI*1.5f)
m_phy(XM_PI*0.5f)
m_radius(6.f)
{
m_spotLight.ambient = XMFLOAT4(0.f0.f0.f1.f);
m_spotLight.diffuse = XMFLOAT4(0.5f0.5f0.5f1.f);
m_spotLight.specular = XMFLOAT4(0.3f0.3f0.3f1.f);
m_spotLight.pos = XMFLOAT3(m_radius*sin(m_phy)*cos(m_theta)m_radius*cos(m_phy)m_radius*sin(m_phy)*sin(m_theta));
m_spotLight.range = 100.f;
m_spotLight.theta = XMConvertToRadians(30.f);
XMStoreFloat3(&m_spotLight.dir
XMVector3Normalize(XMVectorSet(-m_radius*sin(m_phy)*cos(m_theta)
-m_radius*cos(m_phy)
-m_radius*sin(m_phy)*sin(m_theta)0.f)));
m_spotLight.att = XMFLOAT3(0.2f0.f0.f);
m_spotLight.spot =60.f;

m_material.ambient = XMFLOAT4(0.f0.f0.f1.f);
m_material.diffuse = XMFLOAT4(0.6f0.6f0.6f1.f);
m_material.specular = XMFLOAT4(0.3f0.3f0.3f60.f);
}

TextureDemo::~TextureDemo()
{
SafeRelease(m_texView);
SafeRelease(m_fx);
SafeRelease(m_inputLayout);
SafeRelease(m_IB);
SafeRelease(m_VB);
}

bool TextureDemo::BuildFX()
{
ifstream fxFile(“FX/BasicTex.fxo“ios::binary);
if(!fxFile)
{
return false;
}

fxFi

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-12-26 08:16  D3D11纹理基础\
     目录           0  2012-12-26 08:11  D3D11纹理基础\Common\
     文件          24  2012-12-22 20:53  D3D11纹理基础\Common\AppUtil.cpp
     文件        1004  2012-12-24 07:29  D3D11纹理基础\Common\AppUtil.h
     文件       14007  2012-12-24 23:00  D3D11纹理基础\Common\GeometryGens.cpp
     文件        1529  2012-12-23 03:08  D3D11纹理基础\Common\GeometryGens.h
     文件        1148  2012-12-24 23:57  D3D11纹理基础\Common\Lights.h
     文件        2458  2012-12-13 22:20  D3D11纹理基础\Common\Timer.cpp
     文件         908  2012-12-13 21:41  D3D11纹理基础\Common\Timer.h
     文件       11395  2012-12-23 07:32  D3D11纹理基础\Common\WinApp.cpp
     文件        2337  2012-12-23 07:36  D3D11纹理基础\Common\WinApp.h
     目录           0  2012-12-26 08:03  D3D11纹理基础\FX\
     文件        2100  2012-12-26 08:00  D3D11纹理基础\FX\Basic.fx
     文件         575  2012-12-23 08:29  D3D11纹理基础\FX\BasicColor.fx
     文件       37159  2012-12-24 23:36  D3D11纹理基础\FX\BasicLight.cod
     文件       14603  2012-12-24 23:37  D3D11纹理基础\FX\BasicLight.fxo
     文件       21214  2012-12-26 00:56  D3D11纹理基础\FX\BasicTex.cod
     文件        1990  2012-12-26 07:57  D3D11纹理基础\FX\BasicTex.fx
     文件      113889  2012-12-26 00:56  D3D11纹理基础\FX\BasicTex.fxo
     文件        4587  2012-12-26 08:01  D3D11纹理基础\FX\Light.fx
     文件       10374  2012-12-26 07:50  D3D11纹理基础\Main.cpp
     文件         880  2012-12-25 19:39  D3D11纹理基础\Texture.sln
     文件        6402  2012-12-26 08:14  D3D11纹理基础\Texture.vcxproj
     文件        2421  2012-12-26 08:14  D3D11纹理基础\Texture.vcxproj.filters
     文件      269312  2012-12-26 07:52  D3D11纹理基础\TextureDemo.exe
     目录           0  2012-12-26 08:03  D3D11纹理基础\texture\
     文件      349680  2007-11-23 18:14  D3D11纹理基础\texture\Wood.dds
     文件         551  2012-12-26 08:15  D3D11纹理基础\操作说明.txt

评论

共有 条评论