RL.config and InitWindow.
This commit is contained in:
21
API.md
21
API.md
@@ -2,12 +2,12 @@
|
||||
|
||||
## 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()
|
||||
|
||||
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
|
||||
|
||||
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()
|
||||
|
||||
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()
|
||||
|
||||
Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP)
|
||||
Toggle window state: fullscreen/windowed, resizes monitor to match window resolution
|
||||
|
||||
---
|
||||
|
||||
> RL.ToggleBorderlessWindowed()
|
||||
|
||||
Toggle window state: borderless windowed (only PLATFORM_DESKTOP)
|
||||
Toggle window state: borderless windowed, resizes window to match monitor resolution
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ List of some MISSING features that are planned to be included. For specific func
|
||||
|
||||
## 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.
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ RL={}
|
||||
|
||||
-- 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
|
||||
---This function will be called every frame during execution. It will get time duration from last frame on argument 'delta'
|
||||
---@param delta number
|
||||
@@ -20,6 +20,8 @@ function RL.event( event ) end
|
||||
function RL.log( logLevel, message ) end
|
||||
---This function will be called on program close. Cleanup could be done here.
|
||||
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
|
||||
|
||||
@@ -1324,6 +1326,13 @@ RL.assignGlobalInt=nil
|
||||
RL.assignGlobalInt=nil
|
||||
-- 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
|
||||
---@return any RL.CloseWindow
|
||||
function RL.CloseWindow() end
|
||||
@@ -1380,11 +1389,11 @@ function RL.SetWindowState( flag ) end
|
||||
---@return any resized
|
||||
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
|
||||
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
|
||||
function RL.ToggleBorderlessWindowed() end
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ local raylib = {
|
||||
prefix = "RLAPI",
|
||||
file = "raylib.h",
|
||||
blacklist = {
|
||||
InitWindow = "Handled internally",
|
||||
WindowShouldClose = "Handled internally",
|
||||
GetScreenWidth = "Replaced by GetScreenSize",
|
||||
GetScreenHeight = "Replaced by GetScreenSize",
|
||||
|
||||
@@ -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:
|
||||
- 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:
|
||||
- CHANGE: Is*Ready to Is*Valid functions.
|
||||
@@ -22,6 +23,9 @@ DETAILED CHANGES:
|
||||
rlBindFramebuffer, rlColorMask and rlSetUniformMatrices.
|
||||
- ADDED: Vector2Min, Vector2Max, Vector2Refract, Vector3MoveTowards, Vector3CubicHermite,
|
||||
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
|
||||
|
||||
11
devnotes
11
devnotes
@@ -1,8 +1,5 @@
|
||||
Current {
|
||||
* Migrating to raylib 5.5.
|
||||
* New core functions.
|
||||
* New rlgl functions.
|
||||
* New raymath functions.
|
||||
* Setup callback.
|
||||
}
|
||||
|
||||
Backlog {
|
||||
@@ -16,6 +13,8 @@ Backlog {
|
||||
* Platform desktop SDL
|
||||
* Text input not working on gui. Could this be Raylib issue?
|
||||
* Haptic functions.
|
||||
* SDL3 Pen.
|
||||
* SDL3 GPU?
|
||||
* Audio
|
||||
* AudioStream.
|
||||
* Models
|
||||
@@ -23,7 +22,6 @@ Backlog {
|
||||
* CBuffer
|
||||
* Swap endianess.
|
||||
|
||||
* SDL2 platform specific functions.
|
||||
* Textures
|
||||
* Try making atlas packer with stbrp_pack_rects.
|
||||
* Examples
|
||||
@@ -37,9 +35,6 @@ Bugs {
|
||||
}
|
||||
|
||||
Notes {
|
||||
* raylib 5.5
|
||||
* DrawBillboardPro BREAKING CHANGE.
|
||||
|
||||
}
|
||||
|
||||
Needs Testing {
|
||||
|
||||
@@ -105,15 +105,16 @@ apiFile:write( "# ReiLua API\n" )
|
||||
-- Usage.
|
||||
|
||||
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 = {
|
||||
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'",
|
||||
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.",
|
||||
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.",
|
||||
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" )
|
||||
@@ -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.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.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( "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" )
|
||||
luaApiFile:write(
|
||||
"---"..FUNC_DESC.exit.."\nfunction RL.exit() end\n" )
|
||||
luaApiFile:write(
|
||||
"---"..FUNC_DESC.config.."\nfunction RL.config() end\n" )
|
||||
|
||||
-- Object unloading.
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@ local WALL_MESH_HEIGHT = math.tan( RL.DEG2RAD * ( 90 - SHADOW_FOV / 2 ) ) * LIGH
|
||||
print( "WALL_MESH_HEIGHT", WALL_MESH_HEIGHT )
|
||||
|
||||
local monitor = 0
|
||||
local monitorPos = Vector2:newT( RL.GetMonitorPosition( monitor ) )
|
||||
local monitorSize = Vector2:newT( RL.GetMonitorSize( monitor ) )
|
||||
local winScale = 1
|
||||
local winSize = Vector2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale )
|
||||
|
||||
@@ -87,6 +85,9 @@ local function createShadowMesh()
|
||||
end
|
||||
|
||||
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_VSYNC_HINT )
|
||||
RL.SetWindowSize( winSize )
|
||||
|
||||
@@ -10,33 +10,6 @@ Gui = require( "gui" )
|
||||
Calculator = require( "calculator" )
|
||||
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.
|
||||
|
||||
local calculator = nil
|
||||
@@ -72,6 +45,32 @@ function RL.init()
|
||||
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
|
||||
RL.SetWindowSize( winSize )
|
||||
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()
|
||||
end
|
||||
|
||||
@@ -4,11 +4,7 @@ package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
|
||||
|
||||
Vec2 = require( "vector2" )
|
||||
|
||||
local monitor = 0
|
||||
local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
|
||||
local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
|
||||
local winSize = Vec2:newT( RL.GetScreenSize() )
|
||||
|
||||
local winSize = Vec2:new()
|
||||
local polygon = {
|
||||
texture = -1,
|
||||
texcoords = {
|
||||
@@ -30,6 +26,11 @@ local polygon = {
|
||||
}
|
||||
|
||||
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_VSYNC_HINT )
|
||||
RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } )
|
||||
|
||||
@@ -6,18 +6,16 @@ Rect = require( "rectangle" )
|
||||
local dstRec = Rect:new( 100.0, 100.0, 8.0, 8.0 )
|
||||
local origin = Vec2:new( 0.0, 0.0 )
|
||||
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_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 nPatchTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/nPatch.png" )
|
||||
local nPatchTexture = nil
|
||||
|
||||
function RL.init()
|
||||
RL.SetWindowTitle( "N-Patches" )
|
||||
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
|
||||
|
||||
nPatchTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/nPatch.png" )
|
||||
end
|
||||
|
||||
function RL.update( delta )
|
||||
|
||||
@@ -12,11 +12,11 @@ local GRAVITY = 6
|
||||
local JUMP_STR = 3
|
||||
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 winScale = 5
|
||||
local winSize = res:scale( winScale )
|
||||
local framebuffer = RL.LoadRenderTexture( res )
|
||||
local framebuffer = nil
|
||||
local monitor = 0
|
||||
local tilemap = {
|
||||
size = Vec2:new( res.x / TILE_SIZE, res.y / TILE_SIZE ),
|
||||
@@ -80,21 +80,24 @@ local function createMap()
|
||||
tilemap.tiles[1][8] = 6
|
||||
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 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 } )
|
||||
end
|
||||
|
||||
function RL.init()
|
||||
createMap()
|
||||
|
||||
tex = RL.LoadTexture( RL.GetBasePath().."../resources/images/arcade_platformerV2.png" )
|
||||
framebuffer = RL.LoadRenderTexture( res )
|
||||
end
|
||||
|
||||
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
|
||||
return 0 < tilemap.tiles[ pos.x + 1 ][ pos.y + 1 ]
|
||||
else
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local camera = -1
|
||||
local sphereMesh = -1
|
||||
local camera = nil
|
||||
local sphereMesh = nil
|
||||
local ray = { { 0.5, 0, 4 }, { 0.1, 0, -1 } }
|
||||
local rayCol = {}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ Gui = Raygui:new()
|
||||
local grid = {}
|
||||
local windowbox = {}
|
||||
local tabBar = {}
|
||||
local texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/gradient.png" )
|
||||
local textureRect = Rect:new( 0, 0, RL.GetTextureSize( texture )[1], RL.GetTextureSize( texture )[2] )
|
||||
local texture = nil
|
||||
local textureRect = Rect:new()
|
||||
|
||||
local function closeTab( self, id )
|
||||
local splits = Util.split( tabBar.text, ";" )
|
||||
@@ -55,6 +55,9 @@ function RL.init()
|
||||
|
||||
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(
|
||||
Rect:new( 16, 16, 64, 32 ),
|
||||
"Cat"
|
||||
|
||||
@@ -13,8 +13,6 @@ local STATE = { TITLE = 0, GAME = 1, OVER = 2 } -- Enum.
|
||||
-- Resources
|
||||
local framebuffer = nil
|
||||
local monitor = 0
|
||||
local monitorPos = Vector2:newT( RL.GetMonitorPosition( monitor ) )
|
||||
local monitorSize = Vector2:newT( RL.GetMonitorSize( monitor ) )
|
||||
local winScale = 6
|
||||
local winSize = Vector2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale )
|
||||
local gameState = STATE.GAME
|
||||
@@ -69,16 +67,22 @@ local function setApplePos()
|
||||
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.
|
||||
|
||||
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 )
|
||||
grassTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/grass.png" )
|
||||
snakeTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/snake.png" )
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
void unloadBuffer( Buffer* buffer );
|
||||
/* Window-related functions. */
|
||||
int lcoreInitWindow( lua_State* L );
|
||||
int lcoreCloseWindow( lua_State* L );
|
||||
int lcoreIsWindowReady( lua_State* L );
|
||||
int lcoreIsWindowFullscreen( lua_State* L );
|
||||
|
||||
@@ -26,7 +26,8 @@ void assingGlobalFunction( const char* name, int ( *functionPtr )( lua_State* )
|
||||
|
||||
bool luaInit( int argn, const char** argc );
|
||||
int luaTraceback( lua_State* L );
|
||||
bool luaCallMain();
|
||||
void luaCallMain();
|
||||
void luaCallInit();
|
||||
void luaCallUpdate();
|
||||
void luaCallDraw();
|
||||
void luaCallExit();
|
||||
|
||||
@@ -6,14 +6,12 @@
|
||||
|
||||
typedef struct {
|
||||
char* basePath;
|
||||
bool hasWindow;
|
||||
bool run;
|
||||
bool gcUnload;
|
||||
int lineSpacing; /* We need to store copy here since raylib has it in static. */
|
||||
Vector2 mouseOffset;
|
||||
Vector2 mouseScale;
|
||||
lua_State* luaState;
|
||||
Vector2 resolution;
|
||||
int logLevelInvalid;
|
||||
Font defaultFont;
|
||||
Font guiFont;
|
||||
@@ -50,5 +48,6 @@ typedef struct {
|
||||
extern State* state;
|
||||
|
||||
bool stateInit( int argn, const char** argc, const char* basePath );
|
||||
void stateContextInit();
|
||||
void stateInitInterpret( int argn, const char** argc );
|
||||
void stateFree();
|
||||
|
||||
19
src/core.c
19
src/core.c
@@ -28,6 +28,21 @@ void unloadBuffer( Buffer* buffer ) {
|
||||
## 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()
|
||||
|
||||
@@ -176,7 +191,7 @@ int lcoreClearWindowState( lua_State* L ) {
|
||||
/*
|
||||
> 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 ) {
|
||||
ToggleFullscreen();
|
||||
@@ -187,7 +202,7 @@ int lcoreToggleFullscreen( lua_State* L ) {
|
||||
/*
|
||||
> 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 ) {
|
||||
ToggleBorderlessWindowed();
|
||||
|
||||
@@ -1149,7 +1149,7 @@ int luaTraceback( lua_State* L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool luaCallMain() {
|
||||
void luaCallMain() {
|
||||
lua_State* L = state->luaState;
|
||||
|
||||
char path[ STRING_LEN ] = { '\0' };
|
||||
@@ -1168,6 +1168,11 @@ bool luaCallMain() {
|
||||
snprintf( path, STRING_LEN, "%smain", state->basePath );
|
||||
}
|
||||
#endif
|
||||
if ( !FileExists( path ) ) {
|
||||
TraceLog( LOG_ERROR, "Cannot find file: %s\n", path );
|
||||
state->run = false;
|
||||
return;
|
||||
}
|
||||
luaL_dofile( L, path );
|
||||
|
||||
/* Check errors in main.lua */
|
||||
@@ -1180,27 +1185,49 @@ bool luaCallMain() {
|
||||
/* Apply custom callback here. */
|
||||
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_getfield( L, -1, "init" );
|
||||
|
||||
if ( lua_isfunction( L, -1 ) ) {
|
||||
if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) {
|
||||
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 );
|
||||
|
||||
return state->run;
|
||||
}
|
||||
|
||||
void luaCallUpdate() {
|
||||
|
||||
void luaCallUpdate() {
|
||||
#if defined PLATFORM_DESKTOP_SDL && defined LUA_EVENTS
|
||||
platformSendEvents();
|
||||
#endif
|
||||
@@ -1218,8 +1245,6 @@ void luaCallUpdate() {
|
||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||
state->run = false;
|
||||
lua_pop( L, -1 );
|
||||
return;
|
||||
}
|
||||
}
|
||||
lua_pop( L, -1 );
|
||||
@@ -1239,7 +1264,6 @@ void luaCallDraw() {
|
||||
if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) {
|
||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||
state->run = false;
|
||||
return;
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
@@ -1258,7 +1282,6 @@ void luaCallExit() {
|
||||
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 );
|
||||
@@ -1270,6 +1293,7 @@ void luaRegister() {
|
||||
|
||||
/* Core. */
|
||||
/* Window-related functions. */
|
||||
assingGlobalFunction( "InitWindow", lcoreInitWindow );
|
||||
assingGlobalFunction( "CloseWindow", lcoreCloseWindow );
|
||||
assingGlobalFunction( "IsWindowReady", lcoreIsWindowReady );
|
||||
assingGlobalFunction( "IsWindowFullscreen", lcoreIsWindowFullscreen );
|
||||
|
||||
@@ -65,14 +65,15 @@ int main( int argn, const char** argc ) {
|
||||
else {
|
||||
printVersion();
|
||||
stateInit( argn, argc, basePath );
|
||||
state->run = luaCallMain();
|
||||
luaCallMain();
|
||||
luaCallInit();
|
||||
|
||||
while ( state->run ) {
|
||||
luaCallUpdate();
|
||||
luaCallDraw();
|
||||
if ( WindowShouldClose() ) {
|
||||
state->run = false;
|
||||
}
|
||||
luaCallUpdate();
|
||||
luaCallDraw();
|
||||
}
|
||||
luaCallExit();
|
||||
}
|
||||
|
||||
100
src/models.c
100
src/models.c
@@ -10,102 +10,6 @@ void unloadMaterial( Material* material ) {
|
||||
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
|
||||
*/
|
||||
@@ -1060,7 +964,7 @@ int lmodelsDrawBillboardRec( lua_State* L ) {
|
||||
Vector2 size = uluaGetVector2( L, 5 );
|
||||
Color tint = uluaGetColor( L, 6 );
|
||||
|
||||
DrawBillboardRecNoRatio( *camera, *texture, source, position, size, tint );
|
||||
DrawBillboardRec( *camera, *texture, source, position, size, tint );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1081,7 +985,7 @@ int lmodelsDrawBillboardPro( lua_State* L ) {
|
||||
float rotation = luaL_checknumber( L, 8 );
|
||||
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;
|
||||
}
|
||||
|
||||
30
src/state.c
30
src/state.c
@@ -8,46 +8,36 @@ State* state;
|
||||
|
||||
bool stateInit( int argn, const char** argc, const char* basePath ) {
|
||||
state = malloc( sizeof( State ) );
|
||||
|
||||
state->basePath = malloc( STRING_LEN * sizeof( char ) );
|
||||
strncpy( state->basePath, basePath, STRING_LEN - 1 );
|
||||
|
||||
state->hasWindow = true;
|
||||
state->run = true;
|
||||
state->resolution = (Vector2){ 800, 600 };
|
||||
state->luaState = NULL;
|
||||
state->run = luaInit( argn, argc );;
|
||||
state->logLevelInvalid = LOG_ERROR;
|
||||
state->gcUnload = true;
|
||||
state->lineSpacing = 15;
|
||||
state->mouseOffset = (Vector2){ 0, 0 };
|
||||
state->mouseScale = (Vector2){ 1, 1 };
|
||||
|
||||
InitWindow( state->resolution.x, state->resolution.y, "ReiLua" );
|
||||
return state->run;
|
||||
}
|
||||
|
||||
if ( !IsWindowReady() ) {
|
||||
state->hasWindow = false;
|
||||
state->run = false;
|
||||
}
|
||||
if ( state->run ) {
|
||||
state->run = luaInit( argn, argc );
|
||||
}
|
||||
/* Init after InitWindow. (When there is OpenGL context.) */
|
||||
void stateContextInit() {
|
||||
state->defaultFont = GetFontDefault();
|
||||
state->guiFont = GuiGetFont();
|
||||
state->defaultMaterial = LoadMaterialDefault();
|
||||
state->defaultTexture = (Texture){ 1, 1, 1, 1, 7 };
|
||||
state->shapesTexture = (Texture){ 1, 1, 1, 1, 7 };
|
||||
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();
|
||||
|
||||
for ( int i = 0; i < RL_MAX_SHADER_LOCATIONS; 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 ) {
|
||||
@@ -63,7 +53,7 @@ void stateFree() {
|
||||
lua_close( state->luaState );
|
||||
state->luaState = NULL;
|
||||
}
|
||||
if ( state->hasWindow ) {
|
||||
if ( IsWindowReady() ) {
|
||||
CloseWindow();
|
||||
}
|
||||
#ifdef PLATFORM_DESKTOP_SDL
|
||||
|
||||
Reference in New Issue
Block a user