#include "Initd3d.h"
bool initD3D(D3DDEVTYPE DeviceType, HWND hwnd)
{
IDirect3D9 * d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
// 填充主显示设备的能力( D3DCAPS9结构)
D3DCAPS9 caps;
d3d9->GetDeviceCaps(
D3DADAPTER_DEFAULT, // 主显示设备
DeviceType, // 设备类型,一般是D3DDEVTYPE_HAL.
&caps); // 返回填充后的D3DCAPS9 结构,包含主显示设备的能力
// 是否可以使用硬件顶点处理?
int vp = 0;
if (caps.DevCaps& D3DDEVCAPS_HWTRANSFORMANDLIGHT)
{
// 是,支持硬件顶点处理
vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
}
else
{
// 不,只能用软件顶点处理
vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
d3dpp.BackBufferWidth = 0;
d3dpp.BackBufferHeight = 0;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; //像素格式
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hwnd;
d3dpp.Windowed = true; // fullscreen
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // depth format
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
int hr = d3d9->CreateDevice(
D3DADAPTER_DEFAULT, //primary adapter
D3DDEVTYPE_HAL,//devicetype
hwnd,//window associated withdevice
D3DCREATE_HARDWARE_VERTEXPROCESSING, //vertexprocessing type
&d3dpp,//presentparameters
&Initd3d);//returned created device
if (FAILED(hr))
{
::MessageBox(0, "CreateDevice() -FAILED", 0, 0);
return 0;
}
else
{
return 1;
}
}
void Map()
{
Initd3d->CreateVertexBuffer(4 * sizeof(Vertex), D3DUSAGE_WRITEONLY, Vertex::FVF, D3DPOOL_MANAGED, &Map_v, 0);
Initd3d->CreateIndexBuffer(6 * sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &Map_i, 0);
Vertex *Mapv_b = 0;
Map_v->Lock(0, 0, (void **)&Mapv_b, 0);
Mapv_b[0] = Vertex(3.0f, 0.0f, 3.0f, 0.0f, 0.0f);
Mapv_b[1] = Vertex(3.0f, 0.0f, -3.0f, 1.0f, 0.0f);
Mapv_b[2] = Vertex(-3.0f, 0.0f, -3.0f, 1.0f, 1.0f);
Mapv_b[3] = Vertex(-3.0f, 0.0f, 3.0f, 0.0f, 1.0f);
Map_v->Unlock();
WORD *Mapi_b = 0;
Map_i->Lock(0, 0, (void **)&Mapi_b, 0);
Mapi_b[0] = 0;
Mapi_b[1] = 1;
Mapi_b[2] = 2;
Mapi_b[3] = 0;
Mapi_b[4] = 2;
Mapi_b[5] = 3;
Map_i->Unlock();
D3DXCreateTextureFromFile(Initd3d, "3.png", &Map_tex);
Initd3d->SetTexture(0, Map_tex);
Initd3d->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
Initd3d->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
Initd3d->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
D3DXVECTOR3 position(0.0f, 2.0f, -5.0f);
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMATRIX V;
D3DXMatrixLookAtLH(&V, &position, &target, &up);
Initd3d->SetTransform(D3DTS_VIEW, &V);
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI * 0.5f, // 90 - degree
(float)Width / (float)Height,
1.0f,
1000.0f);
Initd3d->SetTransform(D3DTS_PROJECTION, &proj);
Initd3d->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
Initd3d->SetStreamSource(0, Map_v, 0, sizeof(Vertex));
Initd3d->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
Initd3d->SetIndices(Map_i);
}
void Display()
{
Initd3d->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,0xffffff, 1.0f, 0);
Initd3d->BeginScene();
Initd3d->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);
Initd3d->EndScene();
Initd3d->Present(0, 0, 0, 0);
}
表面有 但是纹理没有 求老哥帮我看看哪里的问题 图片在源文件目录
5 个解决方案
#1
百度搜相关网络教程。
#2
关网络什么事啊?
#3
此处“网络教程”,不是指网上有关网络的教程;而是指网络上有关DirectX9纹理的教程。
#4
就是找不到结果才来问的的。。。。。
#1
百度搜相关网络教程。
#2
关网络什么事啊?
#3
此处“网络教程”,不是指网上有关网络的教程;而是指网络上有关DirectX9纹理的教程。
#4
就是找不到结果才来问的的。。。。。