From 6470789977ebd50245bf03d4e9b39c5c2a25113a Mon Sep 17 00:00:00 2001 From: David Hackbarth Date: Wed, 12 Nov 2025 13:49:37 +0100 Subject: [PATCH] add vertex color add time calculation --- GDP/D3D9/Mesh.cpp | 16 ++++++++-------- GDP/D3D9/Vertex.h | 9 ++++++--- GDP/D3D9/main.cpp | 1 + 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/GDP/D3D9/Mesh.cpp b/GDP/D3D9/Mesh.cpp index 6e82147..e365f17 100644 --- a/GDP/D3D9/Mesh.cpp +++ b/GDP/D3D9/Mesh.cpp @@ -130,16 +130,16 @@ UINT Mesh::createVertexBuffer(IDirect3DDevice9* pD3DDevice) // cube // front - pVertices[0] = Vertex(-0.5f, 0.5f, -0.5f); - pVertices[1] = Vertex(0.5f, 0.5f, -0.5f); - pVertices[2] = Vertex(0.5f, -0.5f, -0.5f); - pVertices[3] = Vertex(-0.5f, -0.5f, -0.5f); + pVertices[0] = Vertex(-0.5f, 0.5f, -0.5f, 255, 0, 0); + pVertices[1] = Vertex(0.5f, 0.5f, -0.5f, 0, 255, 0); + pVertices[2] = Vertex(0.5f, -0.5f, -0.5f, 0, 0, 255); + pVertices[3] = Vertex(-0.5f, -0.5f, -0.5f, 255, 0, 255); // back - pVertices[4] = Vertex(0.5f, 0.5f, 0.5f); - pVertices[5] = Vertex(-0.5f, 0.5f, 0.5f); - pVertices[6] = Vertex(-0.5f, -0.5f, 0.5f); - pVertices[7] = Vertex(0.5f, -0.5f, 0.5f); + pVertices[4] = Vertex(0.5f, 0.5f, 0.5f, 255, 255, 0); + pVertices[5] = Vertex(-0.5f, 0.5f, 0.5f, 0, 255, 255); + pVertices[6] = Vertex(-0.5f, -0.5f, 0.5f, 0, 0, 0); + pVertices[7] = Vertex(0.5f, -0.5f, 0.5f, 200, 200, 200); hr = _pVertexBuffer->Unlock(); CheckFailed(hr, 320); diff --git a/GDP/D3D9/Vertex.h b/GDP/D3D9/Vertex.h index 2b87067..04f4bf6 100644 --- a/GDP/D3D9/Vertex.h +++ b/GDP/D3D9/Vertex.h @@ -1,7 +1,7 @@ #pragma once #include -#define FVF D3DFVF_XYZ +#define FVF D3DFVF_XYZ | D3DFVF_DIFFUSE struct Vertex { @@ -9,6 +9,9 @@ struct Vertex FLOAT y; FLOAT z; - Vertex() : x(0.0f), y(0.0f), z(0.0f) {} - Vertex(FLOAT _x, FLOAT _y, FLOAT _z) : x(_x), y(_y), z(_z) {} + D3DCOLOR color; + + Vertex() : x(0.0f), y(0.0f), z(0.0f), color(0xFFFFFFFF) {} + Vertex(FLOAT _x, FLOAT _y, FLOAT _z) : x(_x), y(_y), z(_z), color(0xFFFFFFFF) {} + Vertex(FLOAT _x, FLOAT _y, FLOAT _z, UINT r, UINT g, UINT b) : x(_x), y(_y), z(_z), color(D3DCOLOR_XRGB(r, g, b)) {} }; \ No newline at end of file diff --git a/GDP/D3D9/main.cpp b/GDP/D3D9/main.cpp index d02d33a..e2dc330 100644 --- a/GDP/D3D9/main.cpp +++ b/GDP/D3D9/main.cpp @@ -34,6 +34,7 @@ int WINAPI WinMain( // set render states d3d.getDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); + d3d.getDevice()->SetRenderState(D3DRS_LIGHTING, FALSE); // 3. create a mesh Mesh mesh = {};