Documentation, heightmap example and custom begin and end draw.
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -9,7 +9,7 @@
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/ReiLua",
|
||||
"args": ["/examples/font/"],
|
||||
"args": ["/examples/heightmap/"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [],
|
||||
|
||||
15
API.md
15
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... )
|
||||
|
||||
32
README.md
32
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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
80
examples/heightmap/main.lua
Normal file
80
examples/heightmap/main.lua
Normal file
@@ -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
|
||||
BIN
examples/resources/images/heightmap.png
Normal file
BIN
examples/resources/images/heightmap.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 56 KiB |
@@ -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 );
|
||||
|
||||
22
src/core.c
22
src/core.c
@@ -494,6 +494,28 @@ int lcoreClearBackground( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> 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 )
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
11
src/models.c
11
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 )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user