added mesh rendering

This commit is contained in:
2025-05-28 14:36:57 +03:00
parent 60fa98e240
commit b83078553e
53 changed files with 1436 additions and 363 deletions

View File

@@ -1,5 +1,5 @@
#include "baseentity.h"
#include "rendering.h"
class C_Light: public C_BaseEntity
{
@@ -7,7 +7,9 @@ public:
virtual void Precache ( void ) override;
virtual void Spawn( void ) override;
virtual void Destroy( void ) override;
virtual void Think( float fDelta ) override;
virtual void Think( float fDelta ) override;
IVertexBuffer *vertexBuffer;
IMesh *mesh;
};
void C_Light::Precache()
@@ -17,6 +19,56 @@ void C_Light::Precache()
void C_Light::Spawn()
{
float cubeVertices[] = {
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
};
vertexBuffer = IRenderer::CreateVertexBuffer(sizeof(cubeVertices));
void *pTriangles = vertexBuffer->Map();
V_memcpy(pTriangles, cubeVertices, sizeof(cubeVertices));
vertexBuffer->Unmap();
mesh = IMeshRenderer::CreateMesh();
mesh->SetVertexBuffer(vertexBuffer);
};
void C_Light::Destroy()
@@ -25,7 +77,9 @@ void C_Light::Destroy()
}
void C_Light::Think( float fDelta )
{
IRenderer::SetMaterial(0);
mesh->SetMatrix(pEntity->m_matrix);
mesh->Draw();
};
LINK_CLIENT_ENTITY(C_Light, CLight)