diff options
| -rw-r--r-- | API.md | 10 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | docgen.lua | 26 | ||||
| -rw-r--r-- | examples/bunnymark/main.lua | 4 | ||||
| -rw-r--r-- | examples/events/main.lua | 2 | ||||
| -rw-r--r-- | examples/free_camera3d/main.lua | 2 | ||||
| -rw-r--r-- | examples/gui/main.lua | 2 | ||||
| -rw-r--r-- | examples/image_draw/main.lua | 6 | ||||
| -rw-r--r-- | examples/pixelated/main.lua | 8 | ||||
| -rw-r--r-- | examples/point_triangle_collision/main.lua | 2 | ||||
| -rw-r--r-- | examples/pong/main.lua | 6 | ||||
| -rw-r--r-- | examples/pong_vec/main.lua | 6 | ||||
| -rw-r--r-- | examples/ray/main.lua | 2 | ||||
| -rw-r--r-- | examples/resources/lib/gui.lua | 2 | ||||
| -rw-r--r-- | examples/snake/main.lua | 2 | ||||
| -rw-r--r-- | src/lua_core.c | 12 | ||||
| -rw-r--r-- | src/rgui.c | 14 | ||||
| -rw-r--r-- | src/rlgl.c | 8 |
18 files changed, 62 insertions, 54 deletions
@@ -45,6 +45,16 @@ This function will be called on program close. Cleanup could be done here. Arguments are stored in 'RL.arg' array. +## Default objects + +> RL.defaultFont + +Default Font object + +> RL.defaultMaterial + +Default Material object + ## Types Raylib structs in Lua @@ -60,7 +60,7 @@ end function RL.draw() RL.ClearBackground( RL.RAYWHITE ) - RL.DrawText( 0, "Congrats! You created your first window!", textPos, 20, 2, textColor ) + RL.DrawText( RL.defaultFont, "Congrats! You created your first window!", textPos, 20, 2, textColor ) end ``` @@ -25,15 +25,11 @@ local function getParamType( param ) if param == "Color" or param == "Vector2" or param == "Vector3" or param == "Vector4" or param == "Quaternion" or param == "Matrix" or param == "Rectangle" then return "table" - elseif param == "float" then - return "number" - elseif param == "int" then - return "integer" - elseif param == "string" then - return "string" - elseif param == "bool" then - return "boolean" - else + elseif param == "float" then return "number" + elseif param == "int" then return "integer" + elseif param == "string" then return "string" + elseif param == "bool" then return "boolean" + else return "any" end end @@ -124,9 +120,21 @@ luaApiFile:write( luaApiFile:write( "---"..FUNC_DESC.exit.."\nfunction RL.exit() end\n" ) +-- Arguments. + apiFile:write( "\n## Arguments\n" ) apiFile:write( "\nArguments are stored in 'RL.arg' array.\n" ) +-- Default objects. + +apiFile:write( "\n## Default objects\n" ) +apiFile:write( "\n> RL.defaultFont\n\nDefault Font object\n" ) +apiFile:write( "\n> RL.defaultMaterial\n\nDefault Material object\n" ) + +-- luaApiFile:write( "\n--Default objects\n\n" ) +-- luaApiFile:write( "--Default Font object\nRL.defaultFont = RL.GetFontDefault()\n" ) +-- luaApiFile:write( "--Default Material object\nRL.defaultMaterial\n" ) + -- Types. apiFile:write( "\n## Types\n\ diff --git a/examples/bunnymark/main.lua b/examples/bunnymark/main.lua index 8274327..9f877e6 100644 --- a/examples/bunnymark/main.lua +++ b/examples/bunnymark/main.lua @@ -83,7 +83,7 @@ function RL.draw() end RL.DrawRectangle( { 0, 0, screenWidth, 40 }, RL.BLACK) - RL.DrawText( 0, "bunnies: " .. #bunnies, { 120, 10 }, 20, 2, RL.GREEN ) - RL.DrawText( 0, "batched draw calls: " .. math.ceil( 1 + #bunnies / MAX_BATCH_ELEMENTS ), { 320, 10 }, 20, 2, RL.RED ) + RL.DrawText( RL.defaultFont, "bunnies: " .. #bunnies, { 120, 10 }, 20, 2, RL.GREEN ) + RL.DrawText( RL.defaultFont, "batched draw calls: " .. math.ceil( 1 + #bunnies / MAX_BATCH_ELEMENTS ), { 320, 10 }, 20, 2, RL.RED ) RL.DrawFPS( { 10, 10 } ) end diff --git a/examples/events/main.lua b/examples/events/main.lua index f03ae70..8a8fb34 100644 --- a/examples/events/main.lua +++ b/examples/events/main.lua @@ -100,5 +100,5 @@ function RL.draw() RL.ClearBackground( RL.RED ) end - RL.DrawText( 0, text, textPos, 20, 2, RL.BLACK ) + RL.DrawText( RL.defaultFont, text, textPos, 20, 2, RL.BLACK ) end diff --git a/examples/free_camera3d/main.lua b/examples/free_camera3d/main.lua index be3195c..6478ebb 100644 --- a/examples/free_camera3d/main.lua +++ b/examples/free_camera3d/main.lua @@ -68,5 +68,5 @@ function RL.draw() text = text.."\nPress T to toggle target visible.\nVisible: "..tostring( targetVisible ) - RL.DrawText( 0, text, { 16, 16 }, 30, 4, RL.WHITE ) + RL.DrawText( RL.defaultFont, text, { 16, 16 }, 30, 4, RL.WHITE ) end diff --git a/examples/gui/main.lua b/examples/gui/main.lua index 3db60bb..01e063e 100644 --- a/examples/gui/main.lua +++ b/examples/gui/main.lua @@ -26,7 +26,7 @@ function RL.init() local mSize = RL.GetMonitorSize( monitor ) local winSize = { 1920, 1080 } - RL.GuiSetFont( 0 ) + RL.GuiSetFont( RL.defaultFont ) RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowSize( winSize ) diff --git a/examples/image_draw/main.lua b/examples/image_draw/main.lua index 8c1ea82..ac8e7e6 100644 --- a/examples/image_draw/main.lua +++ b/examples/image_draw/main.lua @@ -13,7 +13,7 @@ function RL.init() RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) - image = RL.GenImageColor( winSize[1], winSize[2], RL.WHITE ) + image = RL.GenImageColor( winSize, RL.WHITE ) -- Test changing working directory. RL.ChangeDirectory( RL.GetBasePath().."../resources" ) catImage = RL.LoadImage( RL.GetWorkingDirectory().."/images/cat.png" ) @@ -24,14 +24,14 @@ function RL.init() RL.ImageDrawRectangle( image, { 120, 64, 32, 64 }, RL.BLUE ) RL.ImageDrawRectangleLines( image, { 160, 64, 32, 64 }, 2.0, RL.BLUE ) RL.ImageDraw( image, catImage, { 143, 25, 230, 250 }, { 200, 200, 230, 250 }, RL.WHITE ) - RL.ImageDrawTextEx( image, 0, "Hello", { 300, 32 }, 48.0, 1.0, RL.WHITE ) + RL.ImageDrawTextEx( image, RL.defaultFont, "Hello", { 300, 32 }, 48.0, 1.0, RL.WHITE ) local src = { 80, 70, 96, 96 } catCopy = RL.ImageFromImage( catImage, src ) RL.ImageDraw( image, catCopy, src, { 600, 200, src[3], src[4] }, RL.WHITE ) - textImage = RL.ImageText( 0, "Cat", 10, 4, RL.WHITE ) + textImage = RL.ImageText( RL.defaultFont, "Cat", 10, 4, RL.WHITE ) local imageSize = RL.GetImageSize( textImage ) RL.ImageDraw( image, textImage, { 0, 0, imageSize[1], imageSize[2] }, { 250, 40, imageSize[1], imageSize[2] }, RL.WHITE ) diff --git a/examples/pixelated/main.lua b/examples/pixelated/main.lua index 75a9045..3d79ccd 100644 --- a/examples/pixelated/main.lua +++ b/examples/pixelated/main.lua @@ -4,7 +4,8 @@ local speed = 60.0 local monitor = 0 local mPos = RL.GetMonitorPosition( monitor ) local mSize = RL.GetMonitorSize( monitor ) -local framebuffer = -1 +local framebuffer = nil +local framebufferTex = nil local res = { 320, 180 } local scale = 5 local winSize = { res[1] * scale, res[2] * scale } @@ -17,6 +18,7 @@ function RL.init() tex = RL.LoadTexture( RL.GetBasePath().."../resources/images/cat.png" ) -- Create framebuffer. framebuffer = RL.LoadRenderTexture( res ) + framebufferTex = RL.GetRenderTextureTexture( framebuffer ) end function RL.process( delta ) @@ -46,9 +48,9 @@ function RL.draw() RL.DrawLine( { 120, 100 }, { 140, 150 }, 2.4, { 255, 150, 255 } ) RL.DrawRectangle( { 200, 120, 40, 50 }, { 100, 170, 255 } ) RL.DrawTexturePro( tex, { 166, 138, 128, 128 }, { pos[1], pos[2], 128, 128 }, { 16, 16 }, 0.0, RL.WHITE ) - RL.DrawText( 0, "Cat MIAU!!", { 16, 32 }, 10, 1, { 255, 180, 155 } ) + RL.DrawText( RL.defaultFont, "Cat MIAU!!", { 16, 32 }, 10, 1, { 255, 180, 155 } ) RL.DrawTriangle( { 0, 32 }, { 32, 16 }, { 0, 0 }, RL.RED ) RL.EndTextureMode() - RL.DrawTexturePro( framebuffer, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, { 255, 255, 255 } ) + RL.DrawTexturePro( framebufferTex, { 0, 0, res[1], -res[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, { 255, 255, 255 } ) end diff --git a/examples/point_triangle_collision/main.lua b/examples/point_triangle_collision/main.lua index ec837d0..9a302dc 100644 --- a/examples/point_triangle_collision/main.lua +++ b/examples/point_triangle_collision/main.lua @@ -116,5 +116,5 @@ function RL.draw() RL.DrawSphereWires( point.pos, point.radius, 3, 8, point.color ) RL.EndMode3D() - RL.DrawText( 0, debugText, { 10, 10 }, 30, 4, RL.WHITE ) + RL.DrawText( RL.defaultFont, debugText, { 10, 10 }, 30, 4, RL.WHITE ) end diff --git a/examples/pong/main.lua b/examples/pong/main.lua index cc980ea..80c4346 100644 --- a/examples/pong/main.lua +++ b/examples/pong/main.lua @@ -121,7 +121,7 @@ function RL.draw() RL.DrawCircle( ball.pos, ball.radius, RL.WHITE ) -- Draw scire - RL.DrawText( 0, playerLeft.score, { 50, 10 }, 40, 2, RL.WHITE ) - local rightTextSize = RL.MeasureText( 0, playerRight.score, 40, 2 ) - RL.DrawText( 0, playerRight.score, { winSize[1] - 50 - rightTextSize[1], 10 }, 40, 2, RL.WHITE ) + RL.DrawText( RL.defaultFont, playerLeft.score, { 50, 10 }, 40, 2, RL.WHITE ) + local rightTextSize = RL.MeasureText( RL.defaultFont, playerRight.score, 40, 2 ) + RL.DrawText( RL.defaultFont, playerRight.score, { winSize[1] - 50 - rightTextSize[1], 10 }, 40, 2, RL.WHITE ) end diff --git a/examples/pong_vec/main.lua b/examples/pong_vec/main.lua index cf8e86c..0b8ff62 100644 --- a/examples/pong_vec/main.lua +++ b/examples/pong_vec/main.lua @@ -126,7 +126,7 @@ function RL.draw() RL.DrawCircle( ball.pos, ball.radius, RL.WHITE ) -- Draw score. - RL.DrawText( 0, tostring( playerLeft.score ), { 50, 10 }, 40, 2, RL.WHITE ) - local rightTextSize = Vec2:new( RL.MeasureText( 0, tostring( playerRight.score ), 40, 2 ) ) - RL.DrawText( 0, tostring( playerRight.score ), { winSize.x - 50 - rightTextSize.x, 10 }, 40, 2, RL.WHITE ) + RL.DrawText( RL.defaultFont, tostring( playerLeft.score ), { 50, 10 }, 40, 2, RL.WHITE ) + local rightTextSize = Vec2:new( RL.MeasureText( RL.defaultFont, tostring( playerRight.score ), 40, 2 ) ) + RL.DrawText( RL.defaultFont, tostring( playerRight.score ), { winSize.x - 50 - rightTextSize.x, 10 }, 40, 2, RL.WHITE ) end diff --git a/examples/ray/main.lua b/examples/ray/main.lua index 9e09683..6bee146 100644 --- a/examples/ray/main.lua +++ b/examples/ray/main.lua @@ -53,7 +53,7 @@ function RL.draw() RL.DrawGrid( 8, 1 ) RL.DrawRay( ray, { 255, 100, 100 } ) - RL.DrawMesh( sphereMesh, 0, RL.MatrixIdentity() ) + RL.DrawMesh( sphereMesh, RL.defaultMaterial, RL.MatrixIdentity() ) RL.DrawSphereWires( rayCol.point, 0.05, 4, 8, RL.BLUE ) RL.DrawLine3D( rayCol.point, RL.Vector3Add( rayCol.point, rayCol.normal ), RL.GREEN ) RL.EndMode3D() diff --git a/examples/resources/lib/gui.lua b/examples/resources/lib/gui.lua index 8bec529..bca87bd 100644 --- a/examples/resources/lib/gui.lua +++ b/examples/resources/lib/gui.lua @@ -40,7 +40,7 @@ Gui = { }, mouseButton = RL.MOUSE_BUTTON_LEFT, - font = 0, + font = RL.defaultFont, fontSize = 20, padding = 2, spacing = 4, diff --git a/examples/snake/main.lua b/examples/snake/main.lua index 53eb287..2465d1e 100644 --- a/examples/snake/main.lua +++ b/examples/snake/main.lua @@ -215,7 +215,7 @@ function RL.draw() drawApple() if gameState == STATE.OVER then - RL.DrawText( 0, "Press Enter to\nrestart", { 10, 10 }, 10, 2, RL.WHITE ) + RL.DrawText( RL.defaultFont, "Press Enter to\nrestart", { 10, 10 }, 10, 2, RL.WHITE ) end RL.EndTextureMode() diff --git a/src/lua_core.c b/src/lua_core.c index 6d54d27..236bdd1 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -35,7 +35,6 @@ static void defineBuffer() { /* Image */ static int gcImage( lua_State *L ) { Image *image = luaL_checkudata ( L, 1, "Image" ); - printf( "gcImage\n" ); UnloadImage( *image ); } @@ -53,7 +52,6 @@ static void defineImage() { /* Texture */ static int gcTexture( lua_State *L ) { Texture *texture = luaL_checkudata ( L, 1, "Texture" ); - printf( "gcTexture\n" ); UnloadTexture( *texture ); } @@ -71,7 +69,6 @@ static void defineTexture() { /* RenderRexture. */ static int gcRenderTexture( lua_State *L ) { RenderTexture *renderTexture = luaL_checkudata ( L, 1, "RenderTexture" ); - printf( "gcRenderTexture\n" ); UnloadRenderTexture( *renderTexture ); } @@ -107,7 +104,6 @@ static void defineCamera3D() { /* Shader. */ static int gcShader( lua_State *L ) { Shader *shader = luaL_checkudata ( L, 1, "Shader" ); - printf( "gcShader\n" ); UnloadShader( *shader ); } @@ -125,7 +121,6 @@ static void defineShader() { /* Font. */ static int gcFont( lua_State *L ) { Font *font = luaL_checkudata ( L, 1, "Font" ); - printf( "gcFont\n" ); UnloadFont( *font ); } @@ -143,7 +138,6 @@ static void defineFont() { /* Wave. */ static int gcWave( lua_State *L ) { Wave *wave = luaL_checkudata ( L, 1, "Wave" ); - printf( "gcWave\n" ); UnloadWave( *wave ); } @@ -161,7 +155,6 @@ static void defineWave() { /* Sound. */ static int gcSound( lua_State *L ) { Sound *sound = luaL_checkudata ( L, 1, "Sound" ); - printf( "gcSound\n" ); UnloadSound( *sound ); } @@ -179,7 +172,6 @@ static void defineSound() { /* Music. */ static int gcMusic( lua_State *L ) { Music *music = luaL_checkudata ( L, 1, "Music" ); - printf( "gcMusic\n" ); UnloadMusicStream( *music ); } @@ -206,7 +198,6 @@ static void defineLight() { /* Material. */ static int gcMaterial( lua_State *L ) { Material *material = luaL_checkudata ( L, 1, "Material" ); - printf( "gcMaterial\n" ); // int MAX_MATERIAL_MAPS = 12; @@ -238,7 +229,6 @@ static void defineMaterial() { /* Mesh. */ static int gcMesh( lua_State *L ) { Mesh *mesh = luaL_checkudata ( L, 1, "Mesh" ); - printf( "gcMesh\n" ); UnloadMesh( *mesh ); } @@ -256,7 +246,6 @@ static void defineMesh() { /* Model. */ static int gcModel( lua_State *L ) { Model *model = luaL_checkudata ( L, 1, "Model" ); - printf( "gcModel\n" ); UnloadModel( *model ); // UnloadModelKeepMeshes( *model ); @@ -275,7 +264,6 @@ static void defineModel() { /* ModelAnimation. */ static int gcModelAnimation( lua_State *L ) { ModelAnimation *modelAnimation = luaL_checkudata ( L, 1, "ModelAnimation" ); - printf( "gcModelAnimation\n" ); UnloadModelAnimation( *modelAnimation ); } @@ -335,7 +335,7 @@ Toggle Button control, returns true when active */ int lguiGuiToggle( lua_State *L ) { Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - bool checked = lua_toboolean( L, 3 ); + bool checked = uluaGetBoolean( L, 3 ); lua_pushboolean( L, GuiToggle( bounds, luaL_checkstring( L, 2 ), checked ) ); @@ -367,7 +367,7 @@ Check Box control, returns true when active */ int lguiGuiCheckBox( lua_State *L ) { Rectangle bounds = uluaGetRectangleIndex( L, 1 ); - bool checked = lua_toboolean( L, 3 ); + bool checked = uluaGetBoolean( L, 3 ); lua_pushboolean( L, GuiCheckBox( bounds, luaL_checkstring( L, 2 ), checked ) ); @@ -403,7 +403,7 @@ int lguiGuiTextBox( lua_State *L ) { // char text[ STRING_LEN ] = { '\0' }; char text[ textSize + 1 ]; strcpy( text, luaL_checkstring( L, 2 ) ); - bool editMode = lua_toboolean( L, 4 ); + bool editMode = uluaGetBoolean( L, 4 ); lua_pushboolean( L, GuiTextBox( bounds, text, textSize, editMode ) ); lua_pushstring( L, text ); @@ -424,7 +424,7 @@ int lguiGuiTextBoxMulti( lua_State *L ) { // char text[ STRING_LEN ] = { '\0' }; char text[ textSize + 1 ]; strcpy( text, luaL_checkstring( L, 2 ) ); - bool editMode = lua_toboolean( L, 4 ); + bool editMode = uluaGetBoolean( L, 4 ); lua_pushboolean( L, GuiTextBoxMulti( bounds, text, textSize, editMode ) ); lua_pushstring( L, text ); @@ -444,7 +444,7 @@ int lguiGuiSpinner( lua_State *L ) { int value = luaL_checkinteger( L, 3 ); int minValue = luaL_checkinteger( L, 4 ); int maxValue = luaL_checkinteger( L, 5 ); - bool editMode = lua_toboolean( L, 6 ); + bool editMode = uluaGetBoolean( L, 6 ); lua_pushboolean( L, GuiSpinner( bounds, luaL_checkstring( L, 2 ), &value, minValue, maxValue, editMode ) ); lua_pushinteger( L, value ); @@ -464,7 +464,7 @@ int lguiGuiValueBox( lua_State *L ) { int value = luaL_checkinteger( L, 3 ); int minValue = luaL_checkinteger( L, 4 ); int maxValue = luaL_checkinteger( L, 5 ); - bool editMode = lua_toboolean( L, 6 ); + bool editMode = uluaGetBoolean( L, 6 ); lua_pushboolean( L, GuiValueBox( bounds, luaL_checkstring( L, 2 ), &value, minValue, maxValue, editMode ) ); lua_pushinteger( L, value ); @@ -554,7 +554,7 @@ Dropdown Box control, returns selected item int lguiGuiDropdownBox( lua_State *L ) { Rectangle bounds = uluaGetRectangleIndex( L, 1 ); int active = luaL_checkinteger( L, 3 ); - bool editMode = lua_toboolean( L, 4 ); + bool editMode = uluaGetBoolean( L, 4 ); lua_pushboolean( L, GuiDropdownBox( bounds, luaL_checkstring( L, 2 ), &active, editMode ) ); lua_pushinteger( L, active ); @@ -929,7 +929,7 @@ Load a vertex buffer attribute */ int lrlglLoadVertexBuffer( lua_State *L ) { Buffer *buffer = luaL_checkudata( L, 1, "Buffer" ); - bool dynamic = luaL_checkinteger( L, 2 ); + bool dynamic = uluaGetBoolean( L, 2 ); lua_pushinteger( L, rlLoadVertexBuffer( buffer->data, buffer->size, dynamic ) ); @@ -945,7 +945,7 @@ Load a new attributes element buffer */ int lrlglLoadVertexBufferElement( lua_State *L ) { Buffer *buffer = luaL_checkudata( L, 1, "Buffer" ); - bool dynamic = luaL_checkinteger( L, 2 ); + bool dynamic = uluaGetBoolean( L, 2 ); lua_pushinteger( L, rlLoadVertexBufferElement( buffer->data, buffer->size, dynamic ) ); @@ -1013,7 +1013,7 @@ int lrlglSetVertexAttribute( lua_State *L ) { int index = luaL_checkinteger( L, 1 ); int compSize = luaL_checkinteger( L, 2 ); int type = luaL_checkinteger( L, 3 ); - bool normalized = lua_toboolean( L, 4 ); + bool normalized = uluaGetBoolean( L, 4 ); int stride = luaL_checkinteger( L, 5 ); int pointer = luaL_checkinteger( L, 6 ); @@ -1151,7 +1151,7 @@ Load depth texture/renderbuffer (to be attached to fbo) */ int lrlglLoadTextureDepth( lua_State *L ) { Vector2 size = uluaGetVector2Index( L, 1 ); - bool useRenderBuffer = lua_toboolean( L, 2 ); + bool useRenderBuffer = uluaGetBoolean( L, 2 ); lua_pushinteger( L, rlLoadTextureDepth( size.x, size.y, useRenderBuffer ) ); |
