summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/launch.json2
-rw-r--r--API.md15
-rw-r--r--README.md32
-rw-r--r--doc_parser.lua3
-rw-r--r--examples/heightmap/main.lua80
-rw-r--r--examples/resources/images/heightmap.pngbin0 -> 1056 bytes
-rw-r--r--examples/resources/images/tiles.pngbin32917 -> 57203 bytes
-rw-r--r--include/core.h2
-rw-r--r--src/core.c22
-rw-r--r--src/lua_core.c6
-rw-r--r--src/models.c11
11 files changed, 167 insertions, 6 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 662de51..6927ffe 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -9,7 +9,7 @@
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/ReiLua",
- "args": ["/examples/font/"],
+ "args": ["/examples/heightmap/"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
diff --git a/API.md b/API.md
index e9805ba..297e9d8 100644
--- a/API.md
+++ b/API.md
@@ -20,7 +20,8 @@ This function will be called every frame during execution. It will get time dura
> function draw()
This function will be called every frame after process and it should have all rendering related functions.
-Note: Engine will call Raylib functions 'BeginDrawing()' before this function call and 'EndDrawing()' after it
+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.
---
@@ -698,6 +699,18 @@ Set background color ( framebuffer clear color )
---
+> RL_BeginDrawing()
+
+Setup canvas ( framebuffer ) to start drawing
+
+---
+
+> RL_EndDrawing()
+
+End canvas drawing and swap buffers ( double buffering )
+
+---
+
> success = RL_BeginBlendMode( int mode )
Begin blending mode ( BLEND_ALPHA, BLEND_ADDITIVE, BLEND_MULTIPLIED... )
diff --git a/README.md b/README.md
index 899c3c6..2d2b338 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,37 @@ Reilua means fair in finnish.
## Status
-ReiLua is currently in arbitrary version 0.1 and some planned raylib functionality is still missing.
+ReiLua is currently in arbitrary version 0.1 and some planned raylib functionality is still missing but it already has over 300 functions.
+
+List of some missing features that are planned to be included. For specific function check API.
+
+* Core
+ * Some screen-space-related functions
+ * Files drop
+ * custom callbacks
+ * camera2d and it's functions
+ * VR stereo config functions for VR simulator
+* Textures
+ * Most image loading functions
+ * Image manipulation functions
+ * Texture update functions
+ * Color/pixel related functions
+* Text
+ * Some font loading/unloading functions
+* Audio
+ * Wave
+ * AudioStream management functions
+* Mesh
+ * Some mesh management functions
+
+Submodules.
+
+* Raygui
+ * Advanced controls
+* Raymath
+ * Quaternions
+* Physac
+ * Whole implementation
## Usage
diff --git a/doc_parser.lua b/doc_parser.lua
index 848577c..80fa490 100644
--- a/doc_parser.lua
+++ b/doc_parser.lua
@@ -30,7 +30,8 @@ apiFile:write( "\n> function process( delta )\n\
This function will be called every frame during execution. It will get time duration from last frame on argument 'delta'\n\n---\n" )
apiFile:write( "\n> function draw()\n\
This function will be called every frame after process and it should have all rendering related functions.\
-Note: Engine will call Raylib functions 'BeginDrawing()' before this function call and 'EndDrawing()' after it\n\n---\n" )
+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.\n\n---\n" )
-- Globals.
diff --git a/examples/heightmap/main.lua b/examples/heightmap/main.lua
new file mode 100644
index 0000000..ea594b2
--- /dev/null
+++ b/examples/heightmap/main.lua
@@ -0,0 +1,80 @@
+local TILE_SIZE = 32
+
+local monitor = 0
+local camera = -1
+local groundTexture = -1
+local tilesetTex = -1
+local heigthImage = -1
+local mesh = -1
+local material = -1
+
+local grassRec = { 6 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE }
+local dirtRec = { 4 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE }
+local dirtRightRec = { 5 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE }
+local dirtLeftRec = { 5 * TILE_SIZE, 2 * TILE_SIZE, TILE_SIZE, TILE_SIZE }
+local dirtTopRec = { 6 * TILE_SIZE, 1 * TILE_SIZE, TILE_SIZE, TILE_SIZE }
+local dirtBottomRec = { 7 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE }
+
+local matrix = {}
+
+function init()
+ local mPos = RL_GetMonitorPosition( monitor )
+ local mSize = RL_GetMonitorSize( monitor )
+ local winSize = RL_GetWindowSize()
+
+ RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
+ RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
+
+ camera = RL_CreateCamera3D()
+ RL_SetCamera3DPosition( camera, { 0, 2, 4 } )
+ RL_SetCamera3DTarget( camera, { 0, 0, 0 } )
+ RL_SetCamera3DUp( camera, { 0, 2, 0 } )
+ RL_SetCamera3DMode( camera, CAMERA_FREE )
+
+ heigthImage = RL_LoadImage( RL_GetBasePath().."../resources/images/heightmap.png" )
+
+ mesh = RL_GenMeshHeightmap( heigthImage, { 16, 4, 16 } )
+ tilesetTex = RL_LoadTexture( RL_GetBasePath().."../resources/images/tiles.png" )
+ groundTexture = RL_LoadRenderTexture( { TILE_SIZE * 16, TILE_SIZE * 16 } )
+
+ -- Draw to ground texture.
+ RL_BeginTextureMode( groundTexture )
+
+ for x = 1, 16 do
+ for y = 1, 16 do
+ local pos = { x - 1, y - 1 }
+
+ if 4 < x and x < 14 and 4 < y and y < 8 then
+ RL_DrawTextureRec( tilesetTex, dirtRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE )
+ elseif 4 == x and 4 < y and y < 8 then
+ RL_DrawTextureRec( tilesetTex, dirtRightRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE )
+ elseif 14 == x and 4 < y and y < 8 then
+ RL_DrawTextureRec( tilesetTex, dirtLeftRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE )
+ elseif 4 < x and x < 14 and 4 == y then
+ RL_DrawTextureRec( tilesetTex, dirtTopRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE )
+ elseif 4 < x and x < 14 and 8 == y then
+ RL_DrawTextureRec( tilesetTex, dirtBottomRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE )
+ else
+ RL_DrawTextureRec( tilesetTex, grassRec, { pos[1] * TILE_SIZE, pos[2] * TILE_SIZE }, WHITE )
+ end
+ end
+ end
+
+ RL_EndTextureMode()
+
+ material = RL_LoadMaterialDefault()
+ RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE )
+ RL_SetMaterialTexture( material, MATERIAL_MAP_ALBEDO, groundTexture )
+ RL_SetTextureSource( TEXTURE_SOURCE_TEXTURE )
+
+ matrix = RL_MatrixMultiply( RL_MatrixIdentity(), RL_MatrixTranslate( { -4, 0, -4 } ) )
+end
+
+function draw()
+ RL_ClearBackground( { 100, 150, 100 } )
+ RL_UpdateCamera3D( camera )
+
+ RL_BeginMode3D( camera )
+ RL_DrawMesh( mesh, material, matrix )
+ RL_EndMode3D()
+end
diff --git a/examples/resources/images/heightmap.png b/examples/resources/images/heightmap.png
new file mode 100644
index 0000000..d0c9b17
--- /dev/null
+++ b/examples/resources/images/heightmap.png
Binary files differ
diff --git a/examples/resources/images/tiles.png b/examples/resources/images/tiles.png
index 4e3e9cc..e88795f 100644
--- a/examples/resources/images/tiles.png
+++ b/examples/resources/images/tiles.png
Binary files differ
diff --git a/include/core.h b/include/core.h
index 8d855be..7a0655a 100644
--- a/include/core.h
+++ b/include/core.h
@@ -32,6 +32,8 @@ int lcoreDisableCursor( lua_State *L );
int lcoreIsCursorOnScreen( lua_State *L );
/* Drawing. */
int lcoreClearBackground( lua_State *L );
+int lcoreBeginDrawing( lua_State *L );
+int lcoreEndDrawing( lua_State *L );
int lcoreBeginBlendMode( lua_State *L );
int lcoreEndBlendMode( lua_State *L );
int lcoreBeginScissorMode( lua_State *L );
diff --git a/src/core.c b/src/core.c
index f772617..cd7316e 100644
--- a/src/core.c
+++ b/src/core.c
@@ -495,6 +495,28 @@ int lcoreClearBackground( lua_State *L ) {
}
/*
+> RL_BeginDrawing()
+
+Setup canvas ( framebuffer ) to start drawing
+*/
+int lcoreBeginDrawing( lua_State *L ) {
+ BeginDrawing();
+
+ return 1;
+}
+
+/*
+> RL_EndDrawing()
+
+End canvas drawing and swap buffers ( double buffering )
+*/
+int lcoreEndDrawing( lua_State *L ) {
+ EndDrawing();
+
+ return 1;
+}
+
+/*
> success = RL_BeginBlendMode( int mode )
Begin blending mode ( BLEND_ALPHA, BLEND_ADDITIVE, BLEND_MULTIPLIED... )
diff --git a/src/lua_core.c b/src/lua_core.c
index 42b3f22..d7204f5 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -228,6 +228,10 @@ bool luaCallMain() {
/* If web, set path to resources folder. */
#ifdef EMSCRIPTEN
sprintf( path, "resources/main.lua" );
+ /* Alternatively look for main. Could be precompiled binary file. */
+ if ( !FileExists( path ) ) {
+ sprintf( path, "resources/main" );
+ }
#else
sprintf( path, "%smain.lua", state->exePath );
/* Alternatively look for main. Could be precompiled binary file. */
@@ -347,6 +351,8 @@ void luaRegister() {
lua_register( L, "RL_IsCursorOnScreen", lcoreIsCursorOnScreen );
/* Drawing. */
lua_register( L, "RL_ClearBackground", lcoreClearBackground );
+ lua_register( L, "RL_BeginDrawing", lcoreBeginDrawing );
+ lua_register( L, "RL_EndDrawing", lcoreEndDrawing );
lua_register( L, "RL_BeginBlendMode", lcoreBeginBlendMode );
lua_register( L, "RL_EndBlendMode", lcoreEndBlendMode );
lua_register( L, "RL_BeginScissorMode", lcoreBeginScissorMode );
diff --git a/src/models.c b/src/models.c
index 17683b8..f105991 100644
--- a/src/models.c
+++ b/src/models.c
@@ -939,7 +939,14 @@ int lmodelsGenMeshHeightmap( lua_State *L ) {
}
Vector3 size = uluaGetVector3( L );
lua_pop( L, 1 );
- Image *heightmap = state->images[ lua_tointeger( L, -1 ) ];
+ size_t imageId = lua_tointeger( L, -1 );
+
+ if ( !validImage( imageId ) ) {
+ lua_pushboolean( L, false );
+ return 1;
+ }
+
+ Image *heightmap = state->images[ imageId ];
int i = 0;
for ( i = 0; i < state->meshCount; i++ ) {
@@ -1112,7 +1119,7 @@ int lmodelsDrawMesh( lua_State *L ) {
return 1;
}
-/* TODO Needs shader to work. Test it when we have shaders. */
+/* TODO Not testet. */
/*
> success = RL_DrawMeshInstanced( Mesh mesh, Material material, Matrix{} transforms, int instances )