128 lines
3.5 KiB
C
128 lines
3.5 KiB
C
/**
|
|
* Copyright (c) 2025 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "quad.h"
|
|
#include "assert/assert.h"
|
|
|
|
mesh_t QUAD_MESH_SIMPLE;
|
|
meshvertex_t QUAD_MESH_SIMPLE_VERTICES[QUAD_VERTEX_COUNT] = {
|
|
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } },
|
|
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f } },
|
|
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } },
|
|
|
|
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } },
|
|
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } },
|
|
{ { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f } }
|
|
};
|
|
|
|
void quadInit() {
|
|
meshInit(
|
|
&QUAD_MESH_SIMPLE,
|
|
QUAD_PRIMITIVE_TYPE,
|
|
QUAD_VERTEX_COUNT,
|
|
QUAD_MESH_SIMPLE_VERTICES
|
|
);
|
|
}
|
|
|
|
void quadBuffer(
|
|
meshvertex_t *vertices,
|
|
const float_t minX,
|
|
const float_t minY,
|
|
const float_t maxX,
|
|
const float_t maxY,
|
|
const color_t color,
|
|
const float_t u0,
|
|
const float_t v0,
|
|
const float_t u1,
|
|
const float_t v1
|
|
) {
|
|
const float_t z = 0.0f; // Z coordinate for 2D rendering
|
|
assertNotNull(vertices, "Vertices cannot be NULL");
|
|
|
|
// First triangle
|
|
vertices[0] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ u0, v0 }, // UV
|
|
{ minX, minY, z } // Position
|
|
};
|
|
vertices[1] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ u1, v0 }, // UV
|
|
{ maxX, minY, z } // Position
|
|
};
|
|
vertices[2] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ u1, v1 }, // UV
|
|
{ maxX, maxY, z } // Position
|
|
};
|
|
|
|
// Second triangle
|
|
vertices[3] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ u0, v0 }, // UV
|
|
{ minX, minY, z } // Position
|
|
};
|
|
vertices[4] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ u1, v1 }, // UV
|
|
{ maxX, maxY, z } // Position
|
|
};
|
|
vertices[5] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ u0, v1 }, // UV
|
|
{ minX, maxY, z } // Position
|
|
};
|
|
}
|
|
|
|
void quadBuffer3D(
|
|
meshvertex_t *vertices,
|
|
const vec3 min,
|
|
const vec3 max,
|
|
const color_t color,
|
|
const vec2 uvMin,
|
|
const vec2 uvMax
|
|
) {
|
|
assertNotNull(vertices, "Vertices cannot be NULL");
|
|
assertNotNull(min, "Min vector cannot be NULL");
|
|
assertNotNull(max, "Max vector cannot be NULL");
|
|
assertNotNull(uvMin, "UV Min vector cannot be NULL");
|
|
assertNotNull(uvMax, "UV Max vector cannot be NULL");
|
|
|
|
// First triangle
|
|
vertices[0] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ uvMin[0], uvMin[1] }, // UV
|
|
{ min[0], min[1], min[2] } // Position
|
|
};
|
|
vertices[1] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ uvMax[0], uvMin[1] }, // UV
|
|
{ max[0], min[1], min[2] } // Position
|
|
};
|
|
vertices[2] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ uvMax[0], uvMax[1] }, // UV
|
|
{ max[0], max[1], min[2] } // Position
|
|
};
|
|
|
|
// Second triangle
|
|
vertices[3] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ uvMin[0], uvMin[1] }, // UV
|
|
{ min[0], min[1], min[2] } // Position
|
|
};
|
|
vertices[4] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ uvMax[0], uvMax[1] }, // UV
|
|
{ max[0], max[1], min[2] } // Position
|
|
};
|
|
vertices[5] = (meshvertex_t) {
|
|
{ color.r, color.g, color.b, color.a }, // Color
|
|
{ uvMin[0], uvMax[1] }, // UV
|
|
{ min[0], max[1], min[2] } // Position
|
|
};
|
|
} |