资源简介
D3D11_Pick.rar
代码片段和文件信息
#include“BitMapClass.h“
BitmapClass::BitmapClass()
{
md3dVertexBuffer=NULL; //顶点缓存
md3dIndexBuffer=NULL; //索引缓存
mVertexCount = 0;
mIndexCount = 0;
}
BitmapClass::BitmapClass(const BitmapClass& other)
{
}
BitmapClass::~BitmapClass()
{
}
bool BitmapClass::Initialize(ID3D11Device* d3dDevice int ScrrenWidth int ScrrenHeight int BitmapWidth int BitmapHeight)
{
bool result;
//初始化屏幕长宽,纹理长宽,坐标点
mScrrenWidth = ScrrenWidth;
mScrrenHeight = ScrrenHeight;
mBitmapWidth = BitmapWidth;
mBitmapHeight = BitmapHeight;
mPreviousPosX = -1;
mPreviousPosY = -1;
//初始化顶点缓存,索引缓存
result = InitializeBuffer(d3dDevice);
if (!result)
{
MessageBox(NULL L“Initialize Buffer failure“ L“ERROR“ MB_OK);
return false;
}
return true;
}
void BitmapClass::Shutdown()
{
BitmapClass();
}
bool BitmapClass::Render(ID3D11DeviceContext* d3dDeviceContext int positionX int positionY)
{
bool result;
result = UpdateBuffers(d3dDeviceContext positionX positionY);
if (!result)
{
return false;
}
//设置渲染管线的顶点缓存和索引缓存(IA阶段)
RenderBuffers(d3dDeviceContext);
return true;
}
bool BitmapClass::InitializeBuffer(ID3D11Device* d3dDevice)
{
Vertex* vertexs=NULL;
WORD*indices=NULL; //一个字为两个字节
mVertexCount = 6;
mIndexCount = 6;
//创建顶点数组
vertexs = new Vertex[mVertexCount];
if (!vertexs)
return false;
//创建索引数组
indices = new WORD[mIndexCount];
if (!indices)
return false;
//初始化顶点数组为0
memset(vertexs 0 sizeof(Vertex)*mVertexCount);
//赋予索引数组数据
//注意用左手定则判定是不是背面
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
indices[3] = 3;
indices[4] = 4;
indices[5] = 5;
//第一填充(顶点)缓存形容结构体和子资源数据结构体并创建顶点缓存(这里用的是动态缓存)
D3D11_BUFFER_DESC vertexBufferDesc;
vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
vertexBufferDesc.ByteWidth = sizeof(Vertex) * mVertexCount;
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
vertexBufferDesc.MiscFlags = 0;
vertexBufferDesc.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA vertexData;
vertexData.pSysMem = vertexs;
vertexData.SysMemPitch = 0;
vertexData.SysMemSlicePitch = 0;
HR(d3dDevice->CreateBuffer(&vertexBufferDesc &vertexData &md3dVertexBuffer));
//第二填充(索引)缓存形容结构体和子资源数据结构体并创建索引缓存
D3D11_BUFFER_DESC indexBufferDesc;
indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = sizeof(WORD) * mIndexCount;
indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
indexBufferDesc.MiscFlags = 0;
indexBufferDesc.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA indexData;
indexData.pSysMem = indices;
indexData.SysMemPitch = 0;
indexData.SysMemSlicePitch = 0;
HR(d3dDevice->CreateBuffer(&indexBufferDesc &indexData &md3dIndexBuffer));
//释放顶点数组和索引数组(这时数据已经载入缓存不需要这些数组了)
delete[]vertexs;
vertexs = NULL;
delete[]indices;
indices = NULL;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 735 2016-11-15 00:24 PickRayClass.h
文件 6133 2016-11-15 01:34 SystemClass.cpp
文件 1196 2016-09-27 11:56 SystemClass.h
文件 9304 2016-11-14 20:48 TextClass.cpp
文件 1776 2016-10-06 19:32 TextClass.h
文件 7125 2016-10-12 01:24 Texture2DShaderClass.cpp
文件 1428 2016-10-11 21:08 Texture2DShaderClass.h
文件 540 2016-10-05 00:46 TextureClass.cpp
文件 474 2016-10-05 00:46 TextureClass.h
文件 466 2016-09-27 11:37 源.cpp
文件 1561 2016-10-03 02:09 MyShader\ColorShader.fx
文件 1045 2016-10-06 02:00 MyShader\FontShader.fx
文件 881 2016-11-14 23:22 MyShader\Texture2DShader.fx
文件 4224 2012-09-01 23:37 Texture\blue.dds
文件 65664 2009-09-24 14:45 Texture\font.dds
文件 4224 2012-09-02 15:39 Texture\mouse.dds
文件 2946 2016-10-06 01:55 Txt\font.txt
文件 1093129 2016-11-14 21:58 Txt\sphere.txt
文件 5963 2016-11-14 23:17 BitMapClass.cpp
文件 1246 2016-11-14 23:16 BitMapClass.h
文件 2969 2016-10-06 20:34 CameraClass.h
文件 9049 2016-11-14 21:36 ColorShaderClass.cpp
文件 1975 2016-10-03 20:10 ColorShaderClass.h
文件 13920 2016-11-14 23:02 D3DClass.cpp
文件 2262 2016-10-05 22:51 D3DClass.h
文件 1134 2016-10-05 21:26 FontClass.h
文件 3652 2016-10-06 20:28 FontlClass.cpp
文件 8694 2016-11-14 20:46 FontShaderClass.cpp
文件 1556 2016-10-06 01:28 FontShaderClass.h
文件 11465 2016-11-16 02:31 GraphicsClass.cpp
............此处省略15个文件信息
- 上一篇:D3D11教程2源码
- 下一篇:DSP视频及学习资料
评论
共有 条评论