From f8b92ce3aa08b1445c9f956d8166830946562d12 Mon Sep 17 00:00:00 2001 From: navewindre Date: Wed, 3 Sep 2025 20:10:09 +0200 Subject: a --- src/render/gl_3d.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/render/gl_3d.h (limited to 'src/render/gl_3d.h') diff --git a/src/render/gl_3d.h b/src/render/gl_3d.h new file mode 100644 index 0000000..531c3a3 --- /dev/null +++ b/src/render/gl_3d.h @@ -0,0 +1,69 @@ +#pragma once +#include "gl_batch.h" +#include "../util/matrix.h" + +// magic number sue me. yes this float is representable exactly. +const F32 SCREEN_INVALID_POS = -2137000.f; + +struct VERTEX3D { + VEC3 pos; + VEC2 uv; + CLR clr; + U8 sampler; +}; + +using GL_BATCH3D = GL_BATCH; +struct GL_3D : GL_SHADER_PROGRAM { + F32 aspect; + MAT4 projmat; + + VEC2 winsize; +}; + +// shader init ----------------------------------------------------------- +extern GL_3D* gl_3d_init( GL_DATA* gl, VEC2 screensize, const char* shadername ); +// sets up projection matrix and sends it to the gpu ------------------------------------------------------------ +extern void gl_3d_projection_setup( GL_SHADER_PROGRAM* gl3d, VEC3 pos, F32 fov_deg, F32 yaw, F32 pitch, F32 near, F32 far, VEC2 winsize ); +extern void gl_3d_batch_setup( GL_BATCH3D* batch ); + +// takes a triangle fan not set of triangles +extern void gl_3d_polygon( + GL_SHADER_PROGRAM* gl3d, + VERTEX3D* vertices, + U32 vertices_count, + GL_TEX2D* tex +); + +// calculates triangle set from triangle fan before sending to batch +extern void gl_3d_polygon_fan( + GL_BATCH3D* batch, + VERTEX3D* vertices, + U32 vertices_count, + GL_TEX2D* tex +); + +// draws a set of triangles +extern void gl_3d_polygon( + GL_BATCH3D* batch, + VERTEX3D* vertices, + U32 vertices_count, + GL_TEX2D* tex +); + +extern void gl_3d_plane( + GL_SHADER_PROGRAM* gl3d, + VEC3 pos, + VEC2 size, + VEC2 rot, + GL_TEX2D* tex, + CLR col = CLR::WHITE() +); + +extern void gl_3d_plane( + GL_BATCH3D* batch, + VEC3 pos, + VEC2 size, + VEC2 rot, + GL_TEX2D* tex, + CLR col = CLR::WHITE() +); -- cgit v1.2.3