0
嘿,大家可以幫助我在Direct3D C++中使用紋理映射。我已經創建了一個基本的遊戲,並想要構建環境。我已經看過大量的在線教程,但沒有運氣到目前爲止Direct3D C++紋理映射
我創造了我的繪製代碼自定義的頂點:
struct CUSTOMVERTEX
{
FLOAT x, y, z; // The position for the vertex
DWORD color; // The vertex color
};
這是我怎麼會畫一個正方形:
CUSTOMVERTEX g_Vertices[] =
{
{-1.0f,-1.0f,-1.0f,0xFF0000FF},{-1.0f, 1.0f,-1.0f,0xFF0000FF},
{ 1.0f, 1.0f,-1.0f,0xFF0000FF}, { 1.0f, 1.0f,-1.0f,0xFF0000FF},
{ 1.0f,-1.0f,-1.0f,0xFF0000FF},{-1.0f,-1.0f,-1.0f,0xFF0000FF},
};
這裏是緩衝:
//*************************** Vertex Buffer ****************************
if(FAILED(g_pd3dDevice->CreateVertexBuffer(numberOfVertecies*sizeof(CUSTOMVERTEX),
0 /* Usage */, D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED, &g_pVB, NULL)))
MessageBox(hwnd,"Vertex Buffer problem",NULL,NULL);
VOID* pVertices;
if(FAILED(g_pVB->Lock(0, sizeof(g_Vertices), (void**)&pVertices, 0)))
MessageBox(hwnd,"Vertex Lock Problem",NULL,NULL);
memcpy(pVertices, g_Vertices, sizeof(g_Vertices));
g_pVB->Unlock();
,這裏是廣場:
g_pd3dDevice->SetTransform(D3DTS_WORLD, &g_matWorld);
g_pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX));
g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 20);
我只想看看如何紋理的正方形,所以我可以去紋理我的整個環境?