add texture mapping

This commit is contained in:
2025-11-12 15:08:57 +01:00
parent a39f37ac4e
commit 4910894bef
3 changed files with 34 additions and 18 deletions
+16
View File
@@ -1,13 +1,29 @@
#include "Material.h"
#include "Utilities.h"
#include "WICTextureLoader9.h"
using namespace DirectX;
UINT Material::init(IDirect3DDevice9* pD3DDevice, LPCWSTR textureFileName)
{
// load texture
HRESULT hr = CreateWICTextureFromFile(pD3DDevice, textureFileName, &_pTexture, 0, WIC_LOADER_MIP_AUTOGEN);
CheckFailed(hr, 600);
return 0;
}
void Material::render(IDirect3DDevice9* pD3DDevice)
{
// set texture
pD3DDevice->SetTexture(0, _pTexture);
// set sampler state
pD3DDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
pD3DDevice->SetSamplerState(0, D3DSAMP_BORDERCOLOR, D3DCOLOR_XRGB(255, 0, 255));
pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
pD3DDevice->SetSamplerState(0, D3DSAMP_MAXMIPLEVEL, 0);
}
void Material::deInit()
+1 -1
View File
@@ -9,6 +9,6 @@ public:
void deInit();
private:
IDirect3DTexture9* _texture = {};
IDirect3DTexture9* _pTexture = {};
};
+17 -17
View File
@@ -31,12 +31,12 @@ void Mesh::update(FLOAT dt)
static FLOAT x = 0.0f;
static FLOAT y = 0.0f;
static FLOAT z = 0.0f;
static FLOAT pitch = XM_PIDIV4;
static FLOAT pitch = 0.0f;
static FLOAT yaw = 0.0f;
static FLOAT roll = XM_PIDIV4;
static FLOAT roll = 0.0f;
static FLOAT scale = 1.0f;
yaw += 1.0f * dt;
//yaw += 1.0f * dt;
FLOAT move = 1.0f * dt;
@@ -123,10 +123,10 @@ UINT Mesh::createVertexBuffer(IDirect3DDevice9* pD3DDevice)
//// quad with trianglefan
//// quad with trianglelist & index buffer
//pVertices[0] = Vertex(-0.5f, 0.5f, 0.0f);
//pVertices[1] = Vertex(0.5f, 0.5f, 0.0f);
//pVertices[2] = Vertex(0.5f, -0.5f, 0.0f);
//pVertices[3] = Vertex(-0.5f, -0.5f, 0.0f);
pVertices[0] = Vertex(-0.5f, 0.5f, 0.0f, 0.0f, 0.0f);
pVertices[1] = Vertex(0.5f, 0.5f, 0.0f, 1.0f, 0.0f);
pVertices[2] = Vertex(0.5f, -0.5f, 0.0f, 1.0f, 1.0f);
pVertices[3] = Vertex(-0.5f, -0.5f, 0.0f, 0.0f, 1.0f);
//// cube with color
//// front
@@ -142,17 +142,17 @@ UINT Mesh::createVertexBuffer(IDirect3DDevice9* pD3DDevice)
//pVertices[7] = Vertex(0.5f, -0.5f, 0.5f, 200, 200, 200);
// cube with uv
// front
pVertices[0] = Vertex(-0.5f, 0.5f, -0.5f, 0.0f, 0.0f);
pVertices[1] = Vertex(0.5f, 0.5f, -0.5f, 1.0f, 0.0f);
pVertices[2] = Vertex(0.5f, -0.5f, -0.5f, 1.0f, 1.0f);
pVertices[3] = Vertex(-0.5f, -0.5f, -0.5f, 0.0f, 1.0f);
//// front
//pVertices[0] = Vertex(-0.5f, 0.5f, -0.5f, 0.0f, 0.0f);
//pVertices[1] = Vertex(0.5f, 0.5f, -0.5f, 1.0f, 0.0f);
//pVertices[2] = Vertex(0.5f, -0.5f, -0.5f, 1.0f, 1.0f);
//pVertices[3] = Vertex(-0.5f, -0.5f, -0.5f, 0.0f, 1.0f);
// back
pVertices[4] = Vertex(0.5f, 0.5f, 0.5f, 0.0f, 0.0f);
pVertices[5] = Vertex(-0.5f, 0.5f, 0.5f, 1.0f, 0.0f);
pVertices[6] = Vertex(-0.5f, -0.5f, 0.5f, 1.0f, 1.0f);
pVertices[7] = Vertex(0.5f, -0.5f, 0.5f, 0.0f, 1.0f);
//// back
//pVertices[4] = Vertex(0.5f, 0.5f, 0.5f, 0.0f, 0.0f);
//pVertices[5] = Vertex(-0.5f, 0.5f, 0.5f, 1.0f, 0.0f);
//pVertices[6] = Vertex(-0.5f, -0.5f, 0.5f, 1.0f, 1.0f);
//pVertices[7] = Vertex(0.5f, -0.5f, 0.5f, 0.0f, 1.0f);
hr = _pVertexBuffer->Unlock();
CheckFailed(hr, 320);