medfall

A super great game engine
Log | Files | Refs

commit cd2ba73fb94b59ec2caedec6358a6b594a663d1e
parent 29d82397c3acd244519c7d92bd59914eb9209dbb
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Apr 30 02:21:05 +0300

Add normals to the immediate renderer

Diffstat:
immediate.cc | 8+++++---
immediate.h | 1+
text_renderer.cc | 4++++
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/immediate.cc b/immediate.cc @@ -15,11 +15,12 @@ void immediate_init( ImmediateContext * ctx, ImmediateTriangle * memory, u32 max void immediate_triangle( ImmediateContext * ctx, v3 p1, v3 p2, v3 p3, v4 colour ) { ASSERT( ctx->num_triangles < ctx->max_triangles - 1 ); + v3 normal = normalize( cross( p3 - p1, p2 - p1 ) ); v2 uv( 0, 0 ); ImmediateTriangle triangle = { { - { p1, colour, uv }, - { p2, colour, uv }, - { p3, colour, uv }, + { p1, normal, colour, uv }, + { p2, normal, colour, uv }, + { p3, normal, colour, uv }, } }; ctx->triangles[ ctx->num_triangles++ ] = triangle; @@ -233,6 +234,7 @@ void immediate_render( const ImmediateContext * ctx, const RenderState & render_ mesh_config.unified_buffer = vb; mesh_config.stride = sizeof( ImmediateVertex ); mesh_config.positions_offset = checked_cast< u32 >( offsetof( ImmediateVertex, pos ) ); + mesh_config.normals_offset = checked_cast< u32 >( offsetof( ImmediateVertex, normal ) ); mesh_config.colours_offset = checked_cast< u32 >( offsetof( ImmediateVertex, colour ) ); mesh_config.num_vertices = ctx->num_triangles * 3; if( render_state.textures[ 0 ] != 0 ) { diff --git a/immediate.h b/immediate.h @@ -5,6 +5,7 @@ struct ImmediateVertex { v3 pos; + v3 normal; v4 colour; v2 uv; }; diff --git a/text_renderer.cc b/text_renderer.cc @@ -122,21 +122,25 @@ void draw_text( const char * str, float x, float y, float pixel_size ) { ImmediateVertex tl = { v3( left + scale * ( q.x0 - left ), top + scale * ( q.y0 - y ), 0 ), + v3( 0 ), white, v2( q.s0, q.t0 ), }; ImmediateVertex tr = { v3( left + scale * ( q.x1 - left ), top + scale * ( q.y0 - y ), 0 ), + v3( 0 ), white, v2( q.s1, q.t0 ), }; ImmediateVertex bl = { v3( left + scale * ( q.x0 - left ), top + scale * ( q.y1 - y ), 0 ), + v3( 0 ), white, v2( q.s0, q.t1 ), }; ImmediateVertex br = { v3( left + scale * ( q.x1 - left ), top + scale * ( q.y1 - y ), 0 ), + v3( 0 ), white, v2( q.s1, q.t1 ), };