work towards DeferredCommandDraw being universal, support for DeferredCommandDepthRange, rework of cirlce mesh (has a bug still), get_quad_element_buffer() now more general, as it should be with gl_any

This commit is contained in:
2024-10-17 21:01:35 +03:00
parent aa3cab87d2
commit 7e409fc14a
5 changed files with 174 additions and 146 deletions

View File

@ -1,4 +1,3 @@
#include "twn_util.h"
#include "twn_engine_context_c.h"
#include "twn_draw_c.h"
#include "twn_draw.h"
@ -24,22 +23,15 @@ void draw_circle(Vec2 position, float radius, Color color) {
void create_circle_geometry(Vec2 position,
Color color,
float radius,
size_t num_vertices,
SDL_Vertex vertices[],
int indices[])
Vec2 vertices[])
{
/* the angle (in radians) to rotate by on each iteration */
float seg_rotation_angle = (360.0f / (float)num_vertices) * ((float)M_PI / 180);
vertices[0].position.x = (float)position.x;
vertices[0].position.y = (float)position.y;
vertices[0].color.r = color.r;
vertices[0].color.g = color.g;
vertices[0].color.b = color.b;
vertices[0].color.a = color.a;
vertices[0].tex_coord = (SDL_FPoint){ 0, 0 };
vertices[0].x = (float)position.x;
vertices[0].y = (float)position.y;
/* this point will rotate around the center */
float start_x = 0.0f - radius;
@ -48,34 +40,13 @@ void create_circle_geometry(Vec2 position,
for (size_t i = 1; i < num_vertices + 1; ++i) {
float final_seg_rotation_angle = (float)i * seg_rotation_angle;
vertices[i].position.x =
cosf(final_seg_rotation_angle) * start_x -
sinf(final_seg_rotation_angle) * start_y;
vertices[i].position.y =
cosf(final_seg_rotation_angle) * start_y +
sinf(final_seg_rotation_angle) * start_x;
float c, s;
sincosf(final_seg_rotation_angle, &s, &c);
vertices[i].position.x += position.x;
vertices[i].position.y += position.y;
vertices[i].x = c * start_x - s * start_y;
vertices[i].y = c * start_y + s * start_x;
vertices[i].color.r = color.r;
vertices[i].color.g = color.g;
vertices[i].color.b = color.b;
vertices[i].color.a = color.a;
vertices[i].tex_coord = (SDL_FPoint){ 0, 0 };
size_t triangle_offset = 3 * (i - 1);
/* center point index */
indices[triangle_offset] = 0;
/* generated point index */
indices[triangle_offset + 1] = (int)i;
size_t index = (i + 1) % num_vertices;
if (index == 0)
index = num_vertices;
indices[triangle_offset + 2] = (int)index;
vertices[i].x += position.x;
vertices[i].y += position.y;
}
}