From db957a8181497a25e52328882e6e0f98d6551d0b Mon Sep 17 00:00:00 2001 From: jussi Date: Mon, 6 Feb 2023 23:03:39 +0200 Subject: [PATCH] RL_LoadFontEx. --- .vscode/launch.json | 2 +- API.md | 14 +++++++++--- changelog | 2 ++ examples/dungeon_crawler/main.lua | 19 ++++++++-------- examples/resources/images/ui_border.png | Bin 1170 -> 6014 bytes include/text.h | 1 + src/core.c | 2 +- src/lua_core.c | 1 + src/models.c | 27 +++++++++++++++------- src/text.c | 29 ++++++++++++++++++++++++ 10 files changed, 75 insertions(+), 22 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index fd73ad6..9e453e5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/ReiLua", - "args": ["/examples/image_draw/"], + "args": ["/examples/instancing/"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], diff --git a/API.md b/API.md index 81e365f..514c5cb 100644 --- a/API.md +++ b/API.md @@ -3698,6 +3698,15 @@ Load font from file into GPU memory ( VRAM ) --- +> font = RL_LoadFontEx( string fileName, int fontSize ) + +Load font from file with extended parameters. Loading the default character set + +- Failure return -1 +- Success return int + +--- + > font = RL_LoadFontFromImage( Image image, Color key, int firstChar ) Load font from Image ( XNA style ) @@ -3926,10 +3935,9 @@ Draw a plane XZ --- -> success = RL_DrawQuad3DTexture( texture, Vector3{} vertices, Vector2{} texCoords, Color color ) +> success = RL_DrawQuad3DTexture( texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors ) -Draw 3D quad texture using vertices and texture coordinates. Texture coordinates opengl style 0.0 - 1.0. -Note! Could be replaced something like "DrawPlaneTextureRec" +Draw 3D textured quad. ( Texture coordinates opengl style 0.0 - 1.0 ). - Failure return false - Success return true diff --git a/changelog b/changelog index e6798c9..6084c4d 100644 --- a/changelog +++ b/changelog @@ -11,6 +11,7 @@ KEY CHANGES: - ADDED: ReiLuaGui. - ADDED: ReiLuaGui Examples. - ADDED: Draw Mesh Instanced Example. + - CHANGED: RL_DrawQuad3DTexture now takes vertex colors instead of just single color. Detailed changes: ADDED: Help argument. @@ -24,3 +25,4 @@ FIXED: RL_DrawEllipse and RL_DrawEllipseLines expecting wrong arguments. ADDED: RL_IsPathFile. ADDED: RL_SetMaterialShader. ADDED: RL_GetFileLength. +ADDED: RL_LoadFontEx. diff --git a/examples/dungeon_crawler/main.lua b/examples/dungeon_crawler/main.lua index 546c8ef..bfc98e1 100644 --- a/examples/dungeon_crawler/main.lua +++ b/examples/dungeon_crawler/main.lua @@ -9,6 +9,7 @@ local winScale = 4 local framebuffer = -1 local TILE_SIZE = 32 +local TILE_VERTEX_COLORS = { WHITE, WHITE, WHITE, WHITE } local FLOOR = 1 local CEILING = 2 @@ -105,22 +106,22 @@ function draw() -- Floor and ceiling. for x = 0, 3 do for y = 0, 10 do - RL_DrawQuad3DTexture( texture, getTileVer( x, y, FLOOR ), getTexCoords( 1, 0 ), WHITE ) - RL_DrawQuad3DTexture( texture, getTileVer( x, y, CEILING ), getTexCoords( 2, 0 ), WHITE ) + RL_DrawQuad3DTexture( texture, getTileVer( x, y, FLOOR ), getTexCoords( 1, 0 ), TILE_VERTEX_COLORS ) + RL_DrawQuad3DTexture( texture, getTileVer( x, y, CEILING ), getTexCoords( 2, 0 ), TILE_VERTEX_COLORS ) end end -- Walls. - RL_DrawQuad3DTexture( texture, getTileVer( 0, 0, WALL_N ), getTexCoords( 0, 0 ), WHITE ) - RL_DrawQuad3DTexture( texture, getTileVer( 1, 0, WALL_N ), getTexCoords( 0, 2 ), WHITE ) - RL_DrawQuad3DTexture( texture, getTileVer( 2, 0, WALL_N ), getTexCoords( 2, 2 ), WHITE ) - RL_DrawQuad3DTexture( texture, getTileVer( 3, 0, WALL_N ), getTexCoords( 0, 0 ), WHITE ) + RL_DrawQuad3DTexture( texture, getTileVer( 0, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL_DrawQuad3DTexture( texture, getTileVer( 1, 0, WALL_N ), getTexCoords( 0, 2 ), TILE_VERTEX_COLORS ) + RL_DrawQuad3DTexture( texture, getTileVer( 2, 0, WALL_N ), getTexCoords( 2, 2 ), TILE_VERTEX_COLORS ) + RL_DrawQuad3DTexture( texture, getTileVer( 3, 0, WALL_N ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) for x = 0, 3 do - RL_DrawQuad3DTexture( texture, getTileVer( x, 10, WALL_S ), getTexCoords( 0, 0 ), WHITE ) + RL_DrawQuad3DTexture( texture, getTileVer( x, 10, WALL_S ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) end for y = 0, 10 do - RL_DrawQuad3DTexture( texture, getTileVer( 0, y, WALL_W ), getTexCoords( 0, 0 ), WHITE ) - RL_DrawQuad3DTexture( texture, getTileVer( 3, y, WALL_E ), getTexCoords( 0, 0 ), WHITE ) + RL_DrawQuad3DTexture( texture, getTileVer( 0, y, WALL_W ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) + RL_DrawQuad3DTexture( texture, getTileVer( 3, y, WALL_E ), getTexCoords( 0, 0 ), TILE_VERTEX_COLORS ) end drawSprites() diff --git a/examples/resources/images/ui_border.png b/examples/resources/images/ui_border.png index 85936fc0689defd93dbf3d3cd83ac44a9185ee9a..785a8f5c4bd7f69f6db1a0bf57972f31daa5587f 100644 GIT binary patch literal 6014 zcmeHKdpJ~U7vJOF98OY7QH>#?Ggrf0%(&ksMk+^yvS(%wBW9+V!4QSRDVORbN##iC zDitbni$cYrq>@rnIHeJaJm1sveBXb~JbUJS*Sps5UF)~jyY}8GUY@R6 z$T>&=0JNBHPRrnbJbdYCsKLKglk4vSfU19tx36>=7=;pvg*<*3gpx*!AQU9y^8i40 z=eVzb){v>@+gs+mDK1JXe?5r4@;E5Vc7bh12lL9X^u$1iZ~PwxNwut=nhgsle@k<8 zd-U6(Y)*ja^<#@!-fbm;P<3U)$?>s_>M5fOspTAPN8|BavysWE<&|a~^H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Y*a2zy@Y$`13T9}+<6ZaG45en<5-;j>cmn}ioh}-xuFdldFoKfx%l-JO z)zRHRZKklNEVbwPA&<4_mwT$ZHykZgEX>4Tx04R}tkv&MmKpe$iQ?(*h2Rn#3 zWT;LSK}8&E6^c+H)C#RSm|XfHG-*guTpR`0f`cE6RRvR{6nr^B9}t04KQ-dqXG@G>j(dX-`!e;$q6qhoB%ps9Oq*M z2<-xmn&W&QJ5J*S2tET>ddpv_12dnb*IHWi24lRq6&fI0QzEl)dKj?h)?x-u^w)?C%F}X>z4X0p>iD UofI+%2M+`jzhFdQv)2@-0vf2ltpET3 diff --git a/include/text.h b/include/text.h index 523d9d0..3754a33 100644 --- a/include/text.h +++ b/include/text.h @@ -4,6 +4,7 @@ bool validFont( size_t id ); /* Loading. */ int ltextLoadFont( lua_State *L ); +int ltextLoadFontEx( lua_State *L ); int ltextLoadFontFromImage( lua_State *L ); int ltextUnloadFont( lua_State *L ); /* Drawing. */ diff --git a/src/core.c b/src/core.c index a4bff1a..1cd9b80 100644 --- a/src/core.c +++ b/src/core.c @@ -1247,7 +1247,7 @@ int lcoreSetShaderValue( lua_State *L ) { } int uniformType = lua_tointeger( L, -1 ); lua_pop( L, 1 ); - + /* Read values. */ size_t valueCount = uluaGetTableLen( L ); float floats[ valueCount ]; diff --git a/src/lua_core.c b/src/lua_core.c index 1033c74..7056f40 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1062,6 +1062,7 @@ void luaRegister() { /* Text. */ /* Loading. */ lua_register( L, "RL_LoadFont", ltextLoadFont ); + lua_register( L, "RL_LoadFontEx", ltextLoadFontEx ); lua_register( L, "RL_LoadFontFromImage", ltextLoadFontFromImage ); lua_register( L, "RL_UnloadFont", ltextUnloadFont ); /* Drawing. */ diff --git a/src/models.c b/src/models.c index f2f7f2e..6258f81 100644 --- a/src/models.c +++ b/src/models.c @@ -558,27 +558,39 @@ int lmodelsDrawPlane( lua_State *L ) { } /* -> success = RL_DrawQuad3DTexture( texture, Vector3{} vertices, Vector2{} texCoords, Color color ) +> success = RL_DrawQuad3DTexture( texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors ) -Draw 3D quad texture using vertices and texture coordinates. Texture coordinates opengl style 0.0 - 1.0. -Note! Could be replaced something like "DrawPlaneTextureRec" +Draw 3D textured quad. ( Texture coordinates opengl style 0.0 - 1.0 ). - Failure return false - Success return true */ int lmodelDrawQuad3DTexture( lua_State *L ) { if ( !lua_isnumber( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) { - TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawQuad3DTexture( texture, Vector3{} vertices, Vector2{} texCoords, Color color )" ); + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawQuad3DTexture( texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )" ); lua_pushboolean( L, false ); return 1; } - Color color = uluaGetColor( L ); + + /* Colors. */ + Color colors[4] = { 0 }; + + int t = lua_gettop( L ), i = 0; + lua_pushnil( L ); + + while ( lua_next( L, t ) != 0 ) { + if ( lua_istable( L, -1 ) && i < 4 ) { + colors[i] = uluaGetColor( L ); + } + i++; + lua_pop( L, 1 ); + } lua_pop( L, 1 ); /* TexCoords. */ Vector2 texcoords[4] = { 0 }; - int t = lua_gettop( L ), i = 0; + t = lua_gettop( L ), i = 0; lua_pushnil( L ); while ( lua_next( L, t ) != 0 ) { @@ -621,10 +633,9 @@ int lmodelDrawQuad3DTexture( lua_State *L ) { rlSetTexture( texturesGetSourceTexture( texId )->id ); rlBegin( RL_QUADS ); - rlColor4ub( color.r, color.g, color.b, color.a ); - for ( i = 0; i < 4; ++i ) { rlTexCoord2f( texcoords[i].x, texcoords[i].y ); + rlColor4ub( colors[i].r, colors[i].g, colors[i].b, colors[i].a ); rlVertex3f( vertices[i].x, vertices[i].y, vertices[i].z ); } rlEnd(); diff --git a/src/text.c b/src/text.c index 564204d..50a12b4 100644 --- a/src/text.c +++ b/src/text.c @@ -62,6 +62,35 @@ int ltextLoadFont( lua_State *L ) { return 1; } +/* +> font = RL_LoadFontEx( string fileName, int fontSize ) + +Load font from file with extended parameters. Loading the default character set + +- Failure return -1 +- Success return int +*/ +int ltextLoadFontEx( lua_State *L ) { + if ( !lua_isstring( L, -2 ) || !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadFontEx( string fileName, int fontSize )" ); + lua_pushinteger( L, -1 ); + return 1; + } + int i = 0; + + for ( i = 0; i < state->fontCount; i++ ) { + if ( state->fonts[i] == NULL ) { + break; + } + } + state->fonts[i] = malloc( sizeof( Font ) ); + *state->fonts[i] = LoadFontEx( lua_tostring( L, -2 ), lua_tointeger( L, - 1 ), NULL, 0 ); + lua_pushinteger( L, i ); + checkFontRealloc( i ); + + return 1; +} + /* > font = RL_LoadFontFromImage( Image image, Color key, int firstChar )