RL.config and InitWindow.

This commit is contained in:
jussi
2024-11-21 23:25:28 +02:00
parent d96e33bb17
commit c9ebe23d62
23 changed files with 189 additions and 221 deletions

21
API.md
View File

@@ -2,12 +2,12 @@
## Functions ## Functions
Application needs 'main.lua' or 'main' file as entry point. ReiLua executable will first look it from same directory. Alternatively, path to the folder where "main.lua" is located can be given as argument. There are five Lua functions that the framework will call, 'RL.init', 'RL.update', 'RL.draw', 'RL.event', 'RL.log', and 'RL.exit'. Application needs 'main.lua' or 'main' file as entry point. ReiLua executable will first look it from same directory. Alternatively, path to the folder where "main.lua" is located can be given as argument. There are seven Lua functions that the framework will call, 'RL.init', 'RL.update', 'RL.draw', 'RL.event', 'RL.log', 'RL.exit' and 'RL.config'.
--- ---
> function RL.init() > function RL.init()
This function will be called first when 'main.lua' is found This function will be called after window has been initialized. Should be used as the main init point.
--- ---
@@ -41,6 +41,12 @@ This function will be called on program close. Cleanup could be done here.
--- ---
> function RL.config()
This function will be called before InitWindow. Note! Only place where you should call InitWindow manually. Doesn't have OpenGL context at this point.
---
## Object unloading ## Object unloading
Some objects allocate memory that needs to be freed when object is no longer needed. By default objects like Textures are unloaded by the Lua garbage collector. It is generatty however recommended to handle this manually in more complex projects. You can change the behavior with SetGCUnload. Some objects allocate memory that needs to be freed when object is no longer needed. By default objects like Textures are unloaded by the Lua garbage collector. It is generatty however recommended to handle this manually in more complex projects. You can change the behavior with SetGCUnload.
@@ -3764,6 +3770,13 @@ assignGlobalInt = nil
--- ---
> RL.InitWindow( Vector2 size, string title )
Initialize window and OpenGL context. Note! Should be called only in RL.config.
InitWindow will still be called automatically before RL.init
---
> RL.CloseWindow() > RL.CloseWindow()
Close window and unload OpenGL context and free all resources Close window and unload OpenGL context and free all resources
@@ -3850,13 +3863,13 @@ Clear window configuration state flags (FLAG_FULLSCREEN_MODE, FLAG_WINDOW_RESIZA
> RL.ToggleFullscreen() > RL.ToggleFullscreen()
Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP) Toggle window state: fullscreen/windowed, resizes monitor to match window resolution
--- ---
> RL.ToggleBorderlessWindowed() > RL.ToggleBorderlessWindowed()
Toggle window state: borderless windowed (only PLATFORM_DESKTOP) Toggle window state: borderless windowed, resizes window to match monitor resolution
--- ---

View File

@@ -34,7 +34,7 @@ List of some MISSING features that are planned to be included. For specific func
## Usage ## Usage
Application needs 'main.lua' or 'main' file as entry point. ReiLua executable will first look it from same directory. Alternatively, path to the folder where "main.lua" is located can be given as argument. There are five Lua functions that the framework will call, 'RL.init', 'RL.update', 'RL.draw', 'RL.log' and 'RL.exit'. Application needs 'main.lua' or 'main' file as entry point. ReiLua executable will first look it from same directory. Alternatively, path to the folder where "main.lua" is located can be given as argument. There are seven Lua functions that the framework will call, 'RL.init', 'RL.update', 'RL.draw', 'RL.event', 'RL.log', 'RL.exit' and 'RL.config'.
Example of basic "main.lua" file that will show basic windows with text. Example of basic "main.lua" file that will show basic windows with text.

View File

@@ -4,7 +4,7 @@ RL={}
-- Functions. -- Functions.
---This function will be called first when 'main.lua' is found ---This function will be called after window has been initialized. Should be used as the main init point.
function RL.init() end function RL.init() end
---This function will be called every frame during execution. It will get time duration from last frame on argument 'delta' ---This function will be called every frame during execution. It will get time duration from last frame on argument 'delta'
---@param delta number ---@param delta number
@@ -20,6 +20,8 @@ function RL.event( event ) end
function RL.log( logLevel, message ) end function RL.log( logLevel, message ) end
---This function will be called on program close. Cleanup could be done here. ---This function will be called on program close. Cleanup could be done here.
function RL.exit() end function RL.exit() end
---This function will be called before InitWindow. Note! Only place where you should call InitWindow manually. Doesn't have OpenGL context at this point.
function RL.config() end
-- Defines - System/Window config flags -- Defines - System/Window config flags
@@ -1324,6 +1326,13 @@ RL.assignGlobalInt=nil
RL.assignGlobalInt=nil RL.assignGlobalInt=nil
-- Core - Window-related functions -- Core - Window-related functions
---Initialize window and OpenGL context. Note! Should be called only in RL.config.
---InitWindow will still be called automatically before RL.init
---@param size table
---@param title string
---@return any RL.InitWindow
function RL.InitWindow( size, title ) end
---Close window and unload OpenGL context and free all resources ---Close window and unload OpenGL context and free all resources
---@return any RL.CloseWindow ---@return any RL.CloseWindow
function RL.CloseWindow() end function RL.CloseWindow() end
@@ -1380,11 +1389,11 @@ function RL.SetWindowState( flag ) end
---@return any resized ---@return any resized
function RL.ClearWindowState( flag ) end function RL.ClearWindowState( flag ) end
---Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP) ---Toggle window state: fullscreen/windowed, resizes monitor to match window resolution
---@return any RL.ToggleFullscreen ---@return any RL.ToggleFullscreen
function RL.ToggleFullscreen() end function RL.ToggleFullscreen() end
---Toggle window state: borderless windowed (only PLATFORM_DESKTOP) ---Toggle window state: borderless windowed, resizes window to match monitor resolution
---@return any RL.ToggleBorderlessWindowed ---@return any RL.ToggleBorderlessWindowed
function RL.ToggleBorderlessWindowed() end function RL.ToggleBorderlessWindowed() end

View File

@@ -2,7 +2,6 @@ local raylib = {
prefix = "RLAPI", prefix = "RLAPI",
file = "raylib.h", file = "raylib.h",
blacklist = { blacklist = {
InitWindow = "Handled internally",
WindowShouldClose = "Handled internally", WindowShouldClose = "Handled internally",
GetScreenWidth = "Replaced by GetScreenSize", GetScreenWidth = "Replaced by GetScreenSize",
GetScreenHeight = "Replaced by GetScreenSize", GetScreenHeight = "Replaced by GetScreenSize",

View File

@@ -1,8 +1,9 @@
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.9.0 Using Raylib 5.5 and Forked Raygui 4.0 Release: ReiLua version 0.9.0 Using raylib 5.5 and Forked Raygui 4.0
------------------------------------------------------------------------ ------------------------------------------------------------------------
KEY CHANGES: KEY CHANGES:
- CHANGE: Switch to raylib 5.5. - CHANGE: Switch to raylib 5.5.
- CHANGE: InitWindow is not called anymore before main.lua is called, but still is before RL.init.
DETAILED CHANGES: DETAILED CHANGES:
- CHANGE: Is*Ready to Is*Valid functions. - CHANGE: Is*Ready to Is*Valid functions.
@@ -22,6 +23,9 @@ DETAILED CHANGES:
rlBindFramebuffer, rlColorMask and rlSetUniformMatrices. rlBindFramebuffer, rlColorMask and rlSetUniformMatrices.
- ADDED: Vector2Min, Vector2Max, Vector2Refract, Vector3MoveTowards, Vector3CubicHermite, - ADDED: Vector2Min, Vector2Max, Vector2Refract, Vector3MoveTowards, Vector3CubicHermite,
QuaternionCubicHermiteSpline, MatrixDecompose and Vector4* functions. QuaternionCubicHermiteSpline, MatrixDecompose and Vector4* functions.
- ADDED: RL.config function.
- ADDED: InitWindow. Can be called from RL.config. If not, will be called automatically before RL.init.
(Curiously InitWindow is function #1057. Before that it was only called automatically.)
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0 Release: ReiLua version 0.8.0 Using Raylib 5.0 and Forked Raygui 4.0

View File

@@ -1,8 +1,5 @@
Current { Current {
* Migrating to raylib 5.5. * Setup callback.
* New core functions.
* New rlgl functions.
* New raymath functions.
} }
Backlog { Backlog {
@@ -16,6 +13,8 @@ Backlog {
* Platform desktop SDL * Platform desktop SDL
* Text input not working on gui. Could this be Raylib issue? * Text input not working on gui. Could this be Raylib issue?
* Haptic functions. * Haptic functions.
* SDL3 Pen.
* SDL3 GPU?
* Audio * Audio
* AudioStream. * AudioStream.
* Models * Models
@@ -23,7 +22,6 @@ Backlog {
* CBuffer * CBuffer
* Swap endianess. * Swap endianess.
* SDL2 platform specific functions.
* Textures * Textures
* Try making atlas packer with stbrp_pack_rects. * Try making atlas packer with stbrp_pack_rects.
* Examples * Examples
@@ -37,9 +35,6 @@ Bugs {
} }
Notes { Notes {
* raylib 5.5
* DrawBillboardPro BREAKING CHANGE.
} }
Needs Testing { Needs Testing {

View File

@@ -105,15 +105,16 @@ apiFile:write( "# ReiLua API\n" )
-- Usage. -- Usage.
apiFile:write( "\n## Functions\n" ) apiFile:write( "\n## Functions\n" )
apiFile:write( "\nApplication needs 'main.lua' or 'main' file as entry point. ReiLua executable will first look it from same directory. Alternatively, path to the folder where \"main.lua\" is located can be given as argument. There are five Lua functions that the framework will call, 'RL.init', 'RL.update', 'RL.draw', 'RL.event', 'RL.log', and 'RL.exit'.\n" ) apiFile:write( "\nApplication needs 'main.lua' or 'main' file as entry point. ReiLua executable will first look it from same directory. Alternatively, path to the folder where \"main.lua\" is located can be given as argument. There are seven Lua functions that the framework will call, 'RL.init', 'RL.update', 'RL.draw', 'RL.event', 'RL.log', 'RL.exit' and 'RL.config'.\n" )
local FUNC_DESC = { local FUNC_DESC = {
init = "This function will be called first when 'main.lua' is found", init = "This function will be called after window has been initialized. Should be used as the main init point.",
update = "This function will be called every frame during execution. It will get time duration from last frame on argument 'delta'", update = "This function will be called every frame during execution. It will get time duration from last frame on argument 'delta'",
draw = "This function will be called every frame after update and it should have all rendering related functions. Note: Engine will call Raylib functions 'BeginDrawing()' before this function call and 'EndDrawing()' after it. You can still use RL.BeginDrawing() and RL.EndDrawing() manually from anywhere.", draw = "This function will be called every frame after update and it should have all rendering related functions. Note: Engine will call Raylib functions 'BeginDrawing()' before this function call and 'EndDrawing()' after it. You can still use RL.BeginDrawing() and RL.EndDrawing() manually from anywhere.",
event = "This function will be called on events input. Content of event table is determined by event type.", event = "This function will be called on events input. Content of event table is determined by event type.",
log = "This function can be used for custom log message handling.", log = "This function can be used for custom log message handling.",
exit = "This function will be called on program close. Cleanup could be done here.", exit = "This function will be called on program close. Cleanup could be done here.",
config = "This function will be called before InitWindow. Note! Only place where you should call InitWindow manually. Doesn't have OpenGL context at this point.",
} }
apiFile:write( "\n---\n> function RL.init()\n\n"..FUNC_DESC.init.."\n\n---\n" ) apiFile:write( "\n---\n> function RL.init()\n\n"..FUNC_DESC.init.."\n\n---\n" )
@@ -122,6 +123,7 @@ apiFile:write( "\n> function RL.draw()\n\n"..FUNC_DESC.draw.."\n\n---\n" )
apiFile:write( "\n> function RL.event( event )\n\n"..FUNC_DESC.event.."\n\n---\n" ) apiFile:write( "\n> function RL.event( event )\n\n"..FUNC_DESC.event.."\n\n---\n" )
apiFile:write( "\n> function RL.log( logLevel, message )\n\n"..FUNC_DESC.log.."\n\n---\n" ) apiFile:write( "\n> function RL.log( logLevel, message )\n\n"..FUNC_DESC.log.."\n\n---\n" )
apiFile:write( "\n> function RL.exit()\n\n"..FUNC_DESC.exit.."\n\n---\n" ) apiFile:write( "\n> function RL.exit()\n\n"..FUNC_DESC.exit.."\n\n---\n" )
apiFile:write( "\n> function RL.config()\n\n"..FUNC_DESC.config.."\n\n---\n" )
luaApiFile:write( "-- Put this file into your project folder to provide annotations when using Lua language server.\n\n" ) luaApiFile:write( "-- Put this file into your project folder to provide annotations when using Lua language server.\n\n" )
luaApiFile:write( "RL={}\n\n" ) luaApiFile:write( "RL={}\n\n" )
@@ -139,6 +141,8 @@ luaApiFile:write(
"---"..FUNC_DESC.log.."\n---@param logLevel integer\n---@param message string\nfunction RL.log( logLevel, message ) end\n" ) "---"..FUNC_DESC.log.."\n---@param logLevel integer\n---@param message string\nfunction RL.log( logLevel, message ) end\n" )
luaApiFile:write( luaApiFile:write(
"---"..FUNC_DESC.exit.."\nfunction RL.exit() end\n" ) "---"..FUNC_DESC.exit.."\nfunction RL.exit() end\n" )
luaApiFile:write(
"---"..FUNC_DESC.config.."\nfunction RL.config() end\n" )
-- Object unloading. -- Object unloading.

View File

@@ -15,8 +15,6 @@ local WALL_MESH_HEIGHT = math.tan( RL.DEG2RAD * ( 90 - SHADOW_FOV / 2 ) ) * LIGH
print( "WALL_MESH_HEIGHT", WALL_MESH_HEIGHT ) print( "WALL_MESH_HEIGHT", WALL_MESH_HEIGHT )
local monitor = 0 local monitor = 0
local monitorPos = Vector2:newT( RL.GetMonitorPosition( monitor ) )
local monitorSize = Vector2:newT( RL.GetMonitorSize( monitor ) )
local winScale = 1 local winScale = 1
local winSize = Vector2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale ) local winSize = Vector2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale )
@@ -87,6 +85,9 @@ local function createShadowMesh()
end end
function RL.init() function RL.init()
local monitorPos = Vector2:newT( RL.GetMonitorPosition( monitor ) )
local monitorSize = Vector2:newT( RL.GetMonitorSize( monitor ) )
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetWindowSize( winSize ) RL.SetWindowSize( winSize )

View File

@@ -10,33 +10,6 @@ Gui = require( "gui" )
Calculator = require( "calculator" ) Calculator = require( "calculator" )
FileExplorer = require( "file_explorer" ) FileExplorer = require( "file_explorer" )
-- Textures.
-- Note that textures are global.
CancelTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/cancel.png" )
BackTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/previous-button.png" )
FolderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/open-folder.png" )
FilesTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/files.png" )
BorderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_border.png" )
BgrTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_bgr.png" )
RL.GenTextureMipmaps( CancelTexture )
RL.GenTextureMipmaps( BackTexture )
RL.GenTextureMipmaps( FolderTexture )
RL.GenTextureMipmaps( FilesTexture )
RL.GenTextureMipmaps( BorderTexture )
RL.GenTextureMipmaps( BgrTexture )
RL.SetTextureFilter( CancelTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( BackTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( FolderTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( FilesTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( BorderTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( BgrTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureWrap( BorderTexture, RL.TEXTURE_WRAP_REPEAT )
RL.SetTextureWrap( BgrTexture, RL.TEXTURE_WRAP_REPEAT )
-- End of calculator definition. -- End of calculator definition.
local calculator = nil local calculator = nil
@@ -72,6 +45,32 @@ function RL.init()
RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetWindowSize( winSize ) RL.SetWindowSize( winSize )
RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
-- Textures.
-- Note that textures are global.
CancelTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/cancel.png" )
BackTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/previous-button.png" )
FolderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/open-folder.png" )
FilesTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/files.png" )
BorderTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_border.png" )
BgrTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_bgr.png" )
RL.GenTextureMipmaps( CancelTexture )
RL.GenTextureMipmaps( BackTexture )
RL.GenTextureMipmaps( FolderTexture )
RL.GenTextureMipmaps( FilesTexture )
RL.GenTextureMipmaps( BorderTexture )
RL.GenTextureMipmaps( BgrTexture )
RL.SetTextureFilter( CancelTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( BackTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( FolderTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( FilesTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( BorderTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( BgrTexture, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureWrap( BorderTexture, RL.TEXTURE_WRAP_REPEAT )
RL.SetTextureWrap( BgrTexture, RL.TEXTURE_WRAP_REPEAT )
initGui() initGui()
end end

View File

@@ -4,11 +4,7 @@ package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
Vec2 = require( "vector2" ) Vec2 = require( "vector2" )
local monitor = 0 local winSize = Vec2:new()
local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
local winSize = Vec2:newT( RL.GetScreenSize() )
local polygon = { local polygon = {
texture = -1, texture = -1,
texcoords = { texcoords = {
@@ -30,6 +26,11 @@ local polygon = {
} }
function RL.init() function RL.init()
local monitor = 0
local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
winSize = Vec2:newT( RL.GetScreenSize() )
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } )

View File

@@ -6,18 +6,16 @@ Rect = require( "rectangle" )
local dstRec = Rect:new( 100.0, 100.0, 8.0, 8.0 ) local dstRec = Rect:new( 100.0, 100.0, 8.0, 8.0 )
local origin = Vec2:new( 0.0, 0.0 ) local origin = Vec2:new( 0.0, 0.0 )
local stretched = true local stretched = true
-- local ninePatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH }
-- local nPatchTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_border.png" )
local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_NINE_PATCH } local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_NINE_PATCH }
-- local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_THREE_PATCH_VERTICAL } -- local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_THREE_PATCH_VERTICAL }
-- local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_THREE_PATCH_HORIZONTAL } -- local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_THREE_PATCH_HORIZONTAL }
local nPatchTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/nPatch.png" ) local nPatchTexture = nil
function RL.init() function RL.init()
RL.SetWindowTitle( "N-Patches" ) RL.SetWindowTitle( "N-Patches" )
RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowState( RL.FLAG_VSYNC_HINT )
nPatchTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/nPatch.png" )
end end
function RL.update( delta ) function RL.update( delta )

View File

@@ -12,11 +12,11 @@ local GRAVITY = 6
local JUMP_STR = 3 local JUMP_STR = 3
local WALK_ANIM_SPEED = 12 local WALK_ANIM_SPEED = 12
local tex = RL.LoadTexture( RL.GetBasePath().."../resources/images/arcade_platformerV2.png" ) local tex = nil
local res = Vec2:new( 160, 144 ) local res = Vec2:new( 160, 144 )
local winScale = 5 local winScale = 5
local winSize = res:scale( winScale ) local winSize = res:scale( winScale )
local framebuffer = RL.LoadRenderTexture( res ) local framebuffer = nil
local monitor = 0 local monitor = 0
local tilemap = { local tilemap = {
size = Vec2:new( res.x / TILE_SIZE, res.y / TILE_SIZE ), size = Vec2:new( res.x / TILE_SIZE, res.y / TILE_SIZE ),
@@ -80,21 +80,24 @@ local function createMap()
tilemap.tiles[1][8] = 6 tilemap.tiles[1][8] = 6
end end
function RL.init() function RL.config()
RL.SetConfigFlags( RL.FLAG_WINDOW_RESIZABLE )
RL.SetConfigFlags( RL.FLAG_VSYNC_HINT )
RL.InitWindow( winSize, "Platformer" )
local monitorPos = Vec2:newT( RL.GetMonitorPosition( monitor ) ) local monitorPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local monitorSize = Vec2:newT( RL.GetMonitorSize( monitor ) ) local monitorSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
RL.SetWindowTitle( "Platformer" )
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetWindowSize( winSize )
RL.SetWindowPosition( { monitorPos.x + monitorSize.x / 2 - winSize.x / 2, monitorPos.y + monitorSize.y / 2 - winSize.y / 2 } ) RL.SetWindowPosition( { monitorPos.x + monitorSize.x / 2 - winSize.x / 2, monitorPos.y + monitorSize.y / 2 - winSize.y / 2 } )
end
function RL.init()
createMap() createMap()
tex = RL.LoadTexture( RL.GetBasePath().."../resources/images/arcade_platformerV2.png" )
framebuffer = RL.LoadRenderTexture( res )
end end
local function isTileWall( pos ) local function isTileWall( pos )
-- if RL.CheckCollisionPointRec( { pos.x, pos.y }, { 0, 0, tilemap.size.x - 1, tilemap.size.y - 1 } ) then
if RL.CheckCollisionPointRec( { pos.x, pos.y }, { 0, 0, tilemap.size.x, tilemap.size.y } ) then if RL.CheckCollisionPointRec( { pos.x, pos.y }, { 0, 0, tilemap.size.x, tilemap.size.y } ) then
return 0 < tilemap.tiles[ pos.x + 1 ][ pos.y + 1 ] return 0 < tilemap.tiles[ pos.x + 1 ][ pos.y + 1 ]
else else

View File

@@ -1,5 +1,5 @@
local camera = -1 local camera = nil
local sphereMesh = -1 local sphereMesh = nil
local ray = { { 0.5, 0, 4 }, { 0.1, 0, -1 } } local ray = { { 0.5, 0, 4 }, { 0.1, 0, -1 } }
local rayCol = {} local rayCol = {}

View File

@@ -11,8 +11,8 @@ Gui = Raygui:new()
local grid = {} local grid = {}
local windowbox = {} local windowbox = {}
local tabBar = {} local tabBar = {}
local texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/gradient.png" ) local texture = nil
local textureRect = Rect:new( 0, 0, RL.GetTextureSize( texture )[1], RL.GetTextureSize( texture )[2] ) local textureRect = Rect:new()
local function closeTab( self, id ) local function closeTab( self, id )
local splits = Util.split( tabBar.text, ";" ) local splits = Util.split( tabBar.text, ";" )
@@ -55,6 +55,9 @@ function RL.init()
RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_LINE_SPACING, 20 ) RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_LINE_SPACING, 20 )
texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/gradient.png" )
textureRect = Rect:new( 0, 0, RL.GetTextureSize( texture )[1], RL.GetTextureSize( texture )[2] )
local label = Gui:Label( local label = Gui:Label(
Rect:new( 16, 16, 64, 32 ), Rect:new( 16, 16, 64, 32 ),
"Cat" "Cat"

View File

@@ -13,8 +13,6 @@ local STATE = { TITLE = 0, GAME = 1, OVER = 2 } -- Enum.
-- Resources -- Resources
local framebuffer = nil local framebuffer = nil
local monitor = 0 local monitor = 0
local monitorPos = Vector2:newT( RL.GetMonitorPosition( monitor ) )
local monitorSize = Vector2:newT( RL.GetMonitorSize( monitor ) )
local winScale = 6 local winScale = 6
local winSize = Vector2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale ) local winSize = Vector2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale )
local gameState = STATE.GAME local gameState = STATE.GAME
@@ -69,16 +67,22 @@ local function setApplePos()
end end
end end
-- Config.
function RL.config()
RL.SetConfigFlags( RL.FLAG_WINDOW_RESIZABLE )
RL.SetConfigFlags( RL.FLAG_VSYNC_HINT )
RL.InitWindow( winSize, "Snake" )
RL.SetWindowIcon( RL.LoadImage( RL.GetBasePath().."../resources/images/apple.png" ) )
local monitorPos = Vector2:newT( RL.GetMonitorPosition( monitor ) )
local monitorSize = Vector2:newT( RL.GetMonitorSize( monitor ) )
RL.SetWindowPosition( { monitorPos.x + monitorSize.x / 2 - winSize.x / 2, monitorPos.y + monitorSize.y / 2 - winSize.y / 2 } )
end
-- Init. -- Init.
function RL.init() function RL.init()
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetWindowSize( winSize )
RL.SetWindowPosition( { monitorPos.x + monitorSize.x / 2 - winSize.x / 2, monitorPos.y + monitorSize.y / 2 - winSize.y / 2 } )
RL.SetWindowTitle( "Snake" )
RL.SetWindowIcon( RL.LoadImage( RL.GetBasePath().."../resources/images/apple.png" ) )
framebuffer = RL.LoadRenderTexture( RESOLUTION ) framebuffer = RL.LoadRenderTexture( RESOLUTION )
grassTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/grass.png" ) grassTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/grass.png" )
snakeTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/snake.png" ) snakeTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/snake.png" )

View File

@@ -4,6 +4,7 @@
void unloadBuffer( Buffer* buffer ); void unloadBuffer( Buffer* buffer );
/* Window-related functions. */ /* Window-related functions. */
int lcoreInitWindow( lua_State* L );
int lcoreCloseWindow( lua_State* L ); int lcoreCloseWindow( lua_State* L );
int lcoreIsWindowReady( lua_State* L ); int lcoreIsWindowReady( lua_State* L );
int lcoreIsWindowFullscreen( lua_State* L ); int lcoreIsWindowFullscreen( lua_State* L );

View File

@@ -26,7 +26,8 @@ void assingGlobalFunction( const char* name, int ( *functionPtr )( lua_State* )
bool luaInit( int argn, const char** argc ); bool luaInit( int argn, const char** argc );
int luaTraceback( lua_State* L ); int luaTraceback( lua_State* L );
bool luaCallMain(); void luaCallMain();
void luaCallInit();
void luaCallUpdate(); void luaCallUpdate();
void luaCallDraw(); void luaCallDraw();
void luaCallExit(); void luaCallExit();

View File

@@ -6,14 +6,12 @@
typedef struct { typedef struct {
char* basePath; char* basePath;
bool hasWindow;
bool run; bool run;
bool gcUnload; bool gcUnload;
int lineSpacing; /* We need to store copy here since raylib has it in static. */ int lineSpacing; /* We need to store copy here since raylib has it in static. */
Vector2 mouseOffset; Vector2 mouseOffset;
Vector2 mouseScale; Vector2 mouseScale;
lua_State* luaState; lua_State* luaState;
Vector2 resolution;
int logLevelInvalid; int logLevelInvalid;
Font defaultFont; Font defaultFont;
Font guiFont; Font guiFont;
@@ -50,5 +48,6 @@ typedef struct {
extern State* state; extern State* state;
bool stateInit( int argn, const char** argc, const char* basePath ); bool stateInit( int argn, const char** argc, const char* basePath );
void stateContextInit();
void stateInitInterpret( int argn, const char** argc ); void stateInitInterpret( int argn, const char** argc );
void stateFree(); void stateFree();

View File

@@ -28,6 +28,21 @@ void unloadBuffer( Buffer* buffer ) {
## Core - Window-related functions ## Core - Window-related functions
*/ */
/*
> RL.InitWindow( Vector2 size, string title )
Initialize window and OpenGL context. Note! Should be called only in RL.config.
InitWindow will still be called automatically before RL.init
*/
int lcoreInitWindow( lua_State* L ) {
Vector2 size = uluaGetVector2( L, 1 );
const char* title = lua_tostring( L, 2 );
InitWindow( (int)size.x, (int)size.y, title );
return 0;
}
/* /*
> RL.CloseWindow() > RL.CloseWindow()
@@ -176,7 +191,7 @@ int lcoreClearWindowState( lua_State* L ) {
/* /*
> RL.ToggleFullscreen() > RL.ToggleFullscreen()
Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP) Toggle window state: fullscreen/windowed, resizes monitor to match window resolution
*/ */
int lcoreToggleFullscreen( lua_State* L ) { int lcoreToggleFullscreen( lua_State* L ) {
ToggleFullscreen(); ToggleFullscreen();
@@ -187,7 +202,7 @@ int lcoreToggleFullscreen( lua_State* L ) {
/* /*
> RL.ToggleBorderlessWindowed() > RL.ToggleBorderlessWindowed()
Toggle window state: borderless windowed (only PLATFORM_DESKTOP) Toggle window state: borderless windowed, resizes window to match monitor resolution
*/ */
int lcoreToggleBorderlessWindowed( lua_State* L ) { int lcoreToggleBorderlessWindowed( lua_State* L ) {
ToggleBorderlessWindowed(); ToggleBorderlessWindowed();

View File

@@ -1149,7 +1149,7 @@ int luaTraceback( lua_State* L ) {
return 1; return 1;
} }
bool luaCallMain() { void luaCallMain() {
lua_State* L = state->luaState; lua_State* L = state->luaState;
char path[ STRING_LEN ] = { '\0' }; char path[ STRING_LEN ] = { '\0' };
@@ -1168,6 +1168,11 @@ bool luaCallMain() {
snprintf( path, STRING_LEN, "%smain", state->basePath ); snprintf( path, STRING_LEN, "%smain", state->basePath );
} }
#endif #endif
if ( !FileExists( path ) ) {
TraceLog( LOG_ERROR, "Cannot find file: %s\n", path );
state->run = false;
return;
}
luaL_dofile( L, path ); luaL_dofile( L, path );
/* Check errors in main.lua */ /* Check errors in main.lua */
@@ -1180,27 +1185,49 @@ bool luaCallMain() {
/* Apply custom callback here. */ /* Apply custom callback here. */
SetTraceLogCallback( logCustom ); SetTraceLogCallback( logCustom );
lua_getglobal( L, "RL" );
lua_getfield( L, -1, "config" );
if ( lua_isfunction( L, -1 ) ) {
if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false;
return;
}
}
lua_pop( L, -1 );
/* If InitWindow is not called in RL.config, call it here. */
if ( !IsWindowReady() ) {
InitWindow( 800, 600, "ReiLua" );
}
/* Set shader locs after we have window. */
if ( IsWindowReady() ) {
stateContextInit();
}
else {
state->run = false;
}
}
void luaCallInit() {
lua_State* L = state->luaState;
lua_pushcfunction( L, luaTraceback );
int tracebackidx = lua_gettop(L);
lua_getglobal( L, "RL" ); lua_getglobal( L, "RL" );
lua_getfield( L, -1, "init" ); lua_getfield( L, -1, "init" );
if ( lua_isfunction( L, -1 ) ) { if ( lua_isfunction( L, -1 ) ) {
if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) { if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
return false; state->run = false;
} }
} }
//TODO Should this be removed?
else {
TraceLog( LOG_ERROR, "%s", "No Lua init found!" );
return false;
}
lua_pop( L, -1 ); lua_pop( L, -1 );
return state->run;
} }
void luaCallUpdate() {
void luaCallUpdate() {
#if defined PLATFORM_DESKTOP_SDL && defined LUA_EVENTS #if defined PLATFORM_DESKTOP_SDL && defined LUA_EVENTS
platformSendEvents(); platformSendEvents();
#endif #endif
@@ -1218,8 +1245,6 @@ void luaCallUpdate() {
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false; state->run = false;
lua_pop( L, -1 );
return;
} }
} }
lua_pop( L, -1 ); lua_pop( L, -1 );
@@ -1239,7 +1264,6 @@ void luaCallDraw() {
if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) { if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false; state->run = false;
return;
} }
EndDrawing(); EndDrawing();
} }
@@ -1258,7 +1282,6 @@ void luaCallExit() {
if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) { if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) {
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
state->run = false; state->run = false;
return;
} }
} }
lua_pop( L, -1 ); lua_pop( L, -1 );
@@ -1270,6 +1293,7 @@ void luaRegister() {
/* Core. */ /* Core. */
/* Window-related functions. */ /* Window-related functions. */
assingGlobalFunction( "InitWindow", lcoreInitWindow );
assingGlobalFunction( "CloseWindow", lcoreCloseWindow ); assingGlobalFunction( "CloseWindow", lcoreCloseWindow );
assingGlobalFunction( "IsWindowReady", lcoreIsWindowReady ); assingGlobalFunction( "IsWindowReady", lcoreIsWindowReady );
assingGlobalFunction( "IsWindowFullscreen", lcoreIsWindowFullscreen ); assingGlobalFunction( "IsWindowFullscreen", lcoreIsWindowFullscreen );

View File

@@ -65,14 +65,15 @@ int main( int argn, const char** argc ) {
else { else {
printVersion(); printVersion();
stateInit( argn, argc, basePath ); stateInit( argn, argc, basePath );
state->run = luaCallMain(); luaCallMain();
luaCallInit();
while ( state->run ) { while ( state->run ) {
luaCallUpdate();
luaCallDraw();
if ( WindowShouldClose() ) { if ( WindowShouldClose() ) {
state->run = false; state->run = false;
} }
luaCallUpdate();
luaCallDraw();
} }
luaCallExit(); luaCallExit();
} }

View File

@@ -10,102 +10,6 @@ void unloadMaterial( Material* material ) {
free( material->maps ); free( material->maps );
} }
void DrawBillboardProNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint ) {
// NOTE: Billboard size will maintain source rectangle aspect ratio, size will represent billboard width
// Vector2 sizeRatio = { size.x*(float)source.width/source.height, size.y };
Vector2 sizeRatio = { size.x, size.y };
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
Vector3 right = { matView.m0, matView.m4, matView.m8 };
//Vector3 up = { matView.m1, matView.m5, matView.m9 };
Vector3 rightScaled = Vector3Scale(right, sizeRatio.x/2);
Vector3 upScaled = Vector3Scale(up, sizeRatio.y/2);
Vector3 p1 = Vector3Add(rightScaled, upScaled);
Vector3 p2 = Vector3Subtract(rightScaled, upScaled);
Vector3 topLeft = Vector3Scale(p2, -1);
Vector3 topRight = p1;
Vector3 bottomRight = p2;
Vector3 bottomLeft = Vector3Scale(p1, -1);
if (rotation != 0.0f)
{
float sinRotation = sinf(rotation*DEG2RAD);
float cosRotation = cosf(rotation*DEG2RAD);
// NOTE: (-1, 1) is the range where origin.x, origin.y is inside the texture
float rotateAboutX = sizeRatio.x*origin.x/2;
float rotateAboutY = sizeRatio.y*origin.y/2;
float xtvalue, ytvalue;
float rotatedX, rotatedY;
xtvalue = Vector3DotProduct(right, topLeft) - rotateAboutX; // Project points to x and y coordinates on the billboard plane
ytvalue = Vector3DotProduct(up, topLeft) - rotateAboutY;
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX; // Rotate about the point origin
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
topLeft = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX)); // Translate back to cartesian coordinates
xtvalue = Vector3DotProduct(right, topRight) - rotateAboutX;
ytvalue = Vector3DotProduct(up, topRight) - rotateAboutY;
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
topRight = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX));
xtvalue = Vector3DotProduct(right, bottomRight) - rotateAboutX;
ytvalue = Vector3DotProduct(up, bottomRight) - rotateAboutY;
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
bottomRight = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX));
xtvalue = Vector3DotProduct(right, bottomLeft)-rotateAboutX;
ytvalue = Vector3DotProduct(up, bottomLeft)-rotateAboutY;
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
bottomLeft = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX));
}
// Translate points to the draw center (position)
topLeft = Vector3Add(topLeft, position);
topRight = Vector3Add(topRight, position);
bottomRight = Vector3Add(bottomRight, position);
bottomLeft = Vector3Add(bottomLeft, position);
rlSetTexture(texture.id);
rlBegin(RL_QUADS);
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
// Bottom-left corner for texture and quad
rlTexCoord2f((float)source.x/texture.width, (float)source.y/texture.height);
rlVertex3f(topLeft.x, topLeft.y, topLeft.z);
// Top-left corner for texture and quad
rlTexCoord2f((float)source.x/texture.width, (float)(source.y + source.height)/texture.height);
rlVertex3f(bottomLeft.x, bottomLeft.y, bottomLeft.z);
// Top-right corner for texture and quad
rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)(source.y + source.height)/texture.height);
rlVertex3f(bottomRight.x, bottomRight.y, bottomRight.z);
// Bottom-right corner for texture and quad
rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)source.y/texture.height);
rlVertex3f(topRight.x, topRight.y, topRight.z);
rlEnd();
rlSetTexture(0);
}
void DrawBillboardRecNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint ) {
// NOTE: Billboard locked on axis-Y
Vector3 up = { 0.0f, 1.0f, 0.0f };
DrawBillboardProNoRatio(camera, texture, source, position, up, size, Vector2Zero(), 0.0f, tint);
}
/* /*
## Models - Basic geometric 3D shapes drawing functions ## Models - Basic geometric 3D shapes drawing functions
*/ */
@@ -1060,7 +964,7 @@ int lmodelsDrawBillboardRec( lua_State* L ) {
Vector2 size = uluaGetVector2( L, 5 ); Vector2 size = uluaGetVector2( L, 5 );
Color tint = uluaGetColor( L, 6 ); Color tint = uluaGetColor( L, 6 );
DrawBillboardRecNoRatio( *camera, *texture, source, position, size, tint ); DrawBillboardRec( *camera, *texture, source, position, size, tint );
return 0; return 0;
} }
@@ -1081,7 +985,7 @@ int lmodelsDrawBillboardPro( lua_State* L ) {
float rotation = luaL_checknumber( L, 8 ); float rotation = luaL_checknumber( L, 8 );
Color tint = uluaGetColor( L, 9 ); Color tint = uluaGetColor( L, 9 );
DrawBillboardProNoRatio( *camera, *texture, source, position, up, size, origin, rotation, tint ); DrawBillboardPro( *camera, *texture, source, position, up, size, origin, rotation, tint );
return 0; return 0;
} }

View File

@@ -8,46 +8,36 @@ State* state;
bool stateInit( int argn, const char** argc, const char* basePath ) { bool stateInit( int argn, const char** argc, const char* basePath ) {
state = malloc( sizeof( State ) ); state = malloc( sizeof( State ) );
state->basePath = malloc( STRING_LEN * sizeof( char ) ); state->basePath = malloc( STRING_LEN * sizeof( char ) );
strncpy( state->basePath, basePath, STRING_LEN - 1 ); strncpy( state->basePath, basePath, STRING_LEN - 1 );
state->hasWindow = true;
state->run = true;
state->resolution = (Vector2){ 800, 600 };
state->luaState = NULL; state->luaState = NULL;
state->run = luaInit( argn, argc );;
state->logLevelInvalid = LOG_ERROR; state->logLevelInvalid = LOG_ERROR;
state->gcUnload = true; state->gcUnload = true;
state->lineSpacing = 15; state->lineSpacing = 15;
state->mouseOffset = (Vector2){ 0, 0 }; state->mouseOffset = (Vector2){ 0, 0 };
state->mouseScale = (Vector2){ 1, 1 }; state->mouseScale = (Vector2){ 1, 1 };
InitWindow( state->resolution.x, state->resolution.y, "ReiLua" ); return state->run;
}
if ( !IsWindowReady() ) { /* Init after InitWindow. (When there is OpenGL context.) */
state->hasWindow = false; void stateContextInit() {
state->run = false;
}
if ( state->run ) {
state->run = luaInit( argn, argc );
}
state->defaultFont = GetFontDefault(); state->defaultFont = GetFontDefault();
state->guiFont = GuiGetFont(); state->guiFont = GuiGetFont();
state->defaultMaterial = LoadMaterialDefault(); state->defaultMaterial = LoadMaterialDefault();
state->defaultTexture = (Texture){ 1, 1, 1, 1, 7 }; state->defaultTexture = (Texture){ 1, 1, 1, 1, 7 };
state->shapesTexture = (Texture){ 1, 1, 1, 1, 7 }; state->shapesTexture = (Texture){ 1, 1, 1, 1, 7 };
state->RLGLcurrentShaderLocs = malloc( RL_MAX_SHADER_LOCATIONS * sizeof( int ) ); state->RLGLcurrentShaderLocs = malloc( RL_MAX_SHADER_LOCATIONS * sizeof( int ) );
#ifdef PLATFORM_DESKTOP_SDL
state->SDL_eventQueue = malloc( PLATFORM_SDL_EVENT_QUEUE_LEN * sizeof( SDL_Event ) );
state->SDL_eventQueueLen = 0;
#endif
int* defaultShaderLocs = rlGetShaderLocsDefault(); int* defaultShaderLocs = rlGetShaderLocsDefault();
for ( int i = 0; i < RL_MAX_SHADER_LOCATIONS; i++ ) { for ( int i = 0; i < RL_MAX_SHADER_LOCATIONS; i++ ) {
state->RLGLcurrentShaderLocs[i] = defaultShaderLocs[i]; state->RLGLcurrentShaderLocs[i] = defaultShaderLocs[i];
} }
#ifdef PLATFORM_DESKTOP_SDL
state->SDL_eventQueue = malloc( PLATFORM_SDL_EVENT_QUEUE_LEN * sizeof( SDL_Event ) );
state->SDL_eventQueueLen = 0;
#endif
return state->run;
} }
void stateInitInterpret( int argn, const char** argc ) { void stateInitInterpret( int argn, const char** argc ) {
@@ -63,7 +53,7 @@ void stateFree() {
lua_close( state->luaState ); lua_close( state->luaState );
state->luaState = NULL; state->luaState = NULL;
} }
if ( state->hasWindow ) { if ( IsWindowReady() ) {
CloseWindow(); CloseWindow();
} }
#ifdef PLATFORM_DESKTOP_SDL #ifdef PLATFORM_DESKTOP_SDL