New object types for Image, Texture, RenderTexture, Camera2D, Camera3D and Shader.
This commit is contained in:
@@ -10,6 +10,8 @@ Reilua means fair in finnish.
|
|||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
|
### WARNING !!! UNDER UNFINISHED HEAVY REFORM !!! WARNING
|
||||||
|
|
||||||
ReiLua is WIP and some planned raylib functionality is still missing but it already has over 700 functions and should include all functions to make most 2d and 3d games. Current Raylib version 4.5.0.
|
ReiLua is WIP and some planned raylib functionality is still missing but it already has over 700 functions and should include all functions to make most 2d and 3d games. Current Raylib version 4.5.0.
|
||||||
|
|
||||||
Included submodules.
|
Included submodules.
|
||||||
|
|||||||
17
changelog
17
changelog
@@ -1,3 +1,20 @@
|
|||||||
|
------------------------------------------------------------------------
|
||||||
|
Release: ReiLua version 0.6.0 Using Raylib 4.5
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
KEY CHANGES:
|
||||||
|
- CHANGED: Switch from ID based objects to userdata.
|
||||||
|
- CHANGED: Wrong arguments now largely crash the application instead of TraceLog state->logLevelInvalid.
|
||||||
|
- CHANGED: Rely mostly on luaL_check* functions for arg checking.
|
||||||
|
|
||||||
|
DETAILED CHANGES:
|
||||||
|
- CHANGED: GenImageColor now takes Vector2 as size.
|
||||||
|
- REMOVED: UnloadImage.
|
||||||
|
- REMOVED: UnloadTexture.
|
||||||
|
- REMOVED: GetTextureType and texture type DEFINES.
|
||||||
|
- ADDED: GetRenderTextureTexture and GetRenderTextureDepthTexture.
|
||||||
|
- REMOVED: UnloadCamera2D and UnloadCamera3D.
|
||||||
|
- REMOVED: UnloadShader.
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
Release: ReiLua version 0.5.0 Using Raylib 4.5
|
Release: ReiLua version 0.5.0 Using Raylib 4.5
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ function RL.draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 )
|
-- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 )
|
||||||
RL.GuiButton( { 112, 64, 96, 32 }, RL.GuiIconText( 113, "Kissa" ) )
|
RL.GuiButton( { 112, 64, 96, 32 }, RL.GuiIconText( 113, "Cat" ) )
|
||||||
-- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 10 )
|
-- RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 10 )
|
||||||
|
|
||||||
if windowOpen and RL.GuiWindowBox( { 300, 16, 200, 320 }, "Window" ) then
|
if windowOpen and RL.GuiWindowBox( { 300, 16, 200, 320 }, "Window" ) then
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ 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 = RL.LoadRenderTexture( res )
|
||||||
|
local framebufferTex = RL.GetRenderTextureTexture( framebuffer )
|
||||||
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 ),
|
||||||
@@ -293,7 +294,12 @@ function RL.draw()
|
|||||||
drawPlayer()
|
drawPlayer()
|
||||||
RL.EndTextureMode()
|
RL.EndTextureMode()
|
||||||
|
|
||||||
RL.DrawTexturePro( framebuffer, { 0, 0, res.x, -res.y }, { 0, 0, winSize.x, winSize.y }, { 0, 0 }, 0.0, RL.WHITE )
|
-- local framebufferTex = RL.GetRenderTextureTexture( framebuffer )
|
||||||
|
-- local texId = RL.GetTextureId( framebufferTex )
|
||||||
|
-- print( "texId", texId )
|
||||||
|
|
||||||
|
RL.DrawTexturePro( framebufferTex, { 0, 0, res.x, -res.y }, { 0, 0, winSize.x, winSize.y }, { 0, 0 }, 0.0, RL.WHITE )
|
||||||
|
|
||||||
|
-- collectgarbage( "collect" )
|
||||||
-- RL.glBlitFramebuffer( framebuffer, -1, res, winSize, RL.GL_COLOR_BUFFER_BIT, RL.GL_NEAREST )
|
-- RL.glBlitFramebuffer( framebuffer, -1, res, winSize, RL.GL_COLOR_BUFFER_BIT, RL.GL_NEAREST )
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ local LEVEL_SIZE = RESOLUTION[1] / TILE_SIZE
|
|||||||
local STATE = { TITLE = 0, GAME = 1, OVER = 2 } -- Enum wannabe.
|
local STATE = { TITLE = 0, GAME = 1, OVER = 2 } -- Enum wannabe.
|
||||||
|
|
||||||
-- Resources
|
-- Resources
|
||||||
local framebuffer = -1
|
local framebuffer = nil
|
||||||
|
local framebufferTex = nil
|
||||||
local monitor = 0
|
local monitor = 0
|
||||||
local monitorPos = RL.GetMonitorPosition( monitor )
|
local monitorPos = RL.GetMonitorPosition( monitor )
|
||||||
local monitorSize = RL.GetMonitorSize( monitor )
|
local monitorSize = RL.GetMonitorSize( monitor )
|
||||||
@@ -73,6 +74,7 @@ function RL.init()
|
|||||||
RL.SetWindowIcon( RL.LoadImage( RL.GetBasePath().."../resources/images/apple.png" ) )
|
RL.SetWindowIcon( RL.LoadImage( RL.GetBasePath().."../resources/images/apple.png" ) )
|
||||||
|
|
||||||
framebuffer = RL.LoadRenderTexture( RESOLUTION )
|
framebuffer = RL.LoadRenderTexture( RESOLUTION )
|
||||||
|
framebufferTex = RL.GetRenderTextureTexture( framebuffer )
|
||||||
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" )
|
||||||
appleTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/apple.png" )
|
appleTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/apple.png" )
|
||||||
@@ -218,5 +220,5 @@ function RL.draw()
|
|||||||
RL.EndTextureMode()
|
RL.EndTextureMode()
|
||||||
|
|
||||||
-- Draw framebuffer to window.
|
-- Draw framebuffer to window.
|
||||||
RL.DrawTexturePro( framebuffer, { 0, 0, RESOLUTION[1], -RESOLUTION[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, RL.WHITE )
|
RL.DrawTexturePro( framebufferTex, { 0, 0, RESOLUTION[1], -RESOLUTION[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, RL.WHITE )
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
local textColor = RL.BLACK
|
local textColor = RL.BLACK
|
||||||
local textPos = { 192, 200 }
|
local textPos = { 192, 200 }
|
||||||
local text = "Congrats! You created your first window!"
|
local text = "Congrats! You created your first window!"
|
||||||
|
local texture = nil
|
||||||
|
|
||||||
function RL.init()
|
function RL.init()
|
||||||
RL.SetWindowTitle( "First window" )
|
RL.SetWindowTitle( "First window" )
|
||||||
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
|
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
|
||||||
|
|
||||||
|
local path = RL.GetBasePath().."../resources/images/cat.png"
|
||||||
|
print( "path", path )
|
||||||
|
|
||||||
|
texture = RL.LoadTexture( path )
|
||||||
|
|
||||||
|
print( "texture", texture )
|
||||||
end
|
end
|
||||||
|
|
||||||
function RL.process( delta )
|
function RL.process( delta )
|
||||||
@@ -24,5 +32,6 @@ end
|
|||||||
|
|
||||||
function RL.draw()
|
function RL.draw()
|
||||||
RL.ClearBackground( RL.RAYWHITE )
|
RL.ClearBackground( RL.RAYWHITE )
|
||||||
|
RL.DrawTexture( texture, { 20, 20 }, RL.WHITE )
|
||||||
RL.DrawText( 0, text, textPos, 20, 2, textColor )
|
RL.DrawText( 0, text, textPos, 20, 2, textColor )
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/* Validators. */
|
|
||||||
bool validCamera3D( size_t id );
|
|
||||||
bool validShader( size_t id );
|
|
||||||
/* Window. */
|
/* Window. */
|
||||||
int lcoreIsWindowReady( lua_State *L );
|
int lcoreIsWindowReady( lua_State *L );
|
||||||
int lcoreIsWindowFullscreen( lua_State *L );
|
int lcoreIsWindowFullscreen( lua_State *L );
|
||||||
@@ -75,7 +72,6 @@ int lcoreSetShaderValueMatrix( lua_State *L );
|
|||||||
int lcoreSetShaderValueTexture( lua_State *L );
|
int lcoreSetShaderValueTexture( lua_State *L );
|
||||||
int lcoreSetShaderValue( lua_State *L );
|
int lcoreSetShaderValue( lua_State *L );
|
||||||
int lcoreSetShaderValueV( lua_State *L );
|
int lcoreSetShaderValueV( lua_State *L );
|
||||||
int lcoreUnloadShader( lua_State *L );
|
|
||||||
/* File. */
|
/* File. */
|
||||||
int lcoreGetBasePath( lua_State *L );
|
int lcoreGetBasePath( lua_State *L );
|
||||||
int lcoreFileExists( lua_State *L );
|
int lcoreFileExists( lua_State *L );
|
||||||
@@ -97,7 +93,6 @@ int lcoreLoadDroppedFiles( lua_State *L );
|
|||||||
int lcoreGetFileModTime( lua_State *L );
|
int lcoreGetFileModTime( lua_State *L );
|
||||||
/* Camera2D. */
|
/* Camera2D. */
|
||||||
int lcoreCreateCamera2D( lua_State *L );
|
int lcoreCreateCamera2D( lua_State *L );
|
||||||
int lcoreUnloadCamera2D( lua_State *L );
|
|
||||||
int lcoreBeginMode2D( lua_State *L );
|
int lcoreBeginMode2D( lua_State *L );
|
||||||
int lcoreEndMode2D( lua_State *L );
|
int lcoreEndMode2D( lua_State *L );
|
||||||
int lcoreSetCamera2DTarget( lua_State *L );
|
int lcoreSetCamera2DTarget( lua_State *L );
|
||||||
@@ -110,7 +105,6 @@ int lcoreGetCamera2DRotation( lua_State *L );
|
|||||||
int lcoreGetCamera2DZoom( lua_State *L );
|
int lcoreGetCamera2DZoom( lua_State *L );
|
||||||
/* Camera3D. */
|
/* Camera3D. */
|
||||||
int lcoreCreateCamera3D( lua_State *L );
|
int lcoreCreateCamera3D( lua_State *L );
|
||||||
int lcoreUnloadCamera3D( lua_State *L );
|
|
||||||
int lcoreBeginMode3D( lua_State *L );
|
int lcoreBeginMode3D( lua_State *L );
|
||||||
int lcoreEndMode3D( lua_State *L );
|
int lcoreEndMode3D( lua_State *L );
|
||||||
int lcoreSetCamera3DPosition( lua_State *L );
|
int lcoreSetCamera3DPosition( lua_State *L );
|
||||||
|
|||||||
@@ -28,10 +28,6 @@ typedef struct {
|
|||||||
int y;
|
int y;
|
||||||
} Buffer;
|
} Buffer;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int age;
|
|
||||||
} Kissa;
|
|
||||||
|
|
||||||
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();
|
bool luaCallMain();
|
||||||
@@ -39,12 +35,8 @@ void luaCallProcess();
|
|||||||
void luaCallDraw();
|
void luaCallDraw();
|
||||||
void luaCallExit();
|
void luaCallExit();
|
||||||
void luaRegister();
|
void luaRegister();
|
||||||
/* Type validators. */
|
|
||||||
bool isValidTexture( lua_State *L, int index, bool allowTable );
|
|
||||||
bool isValidRenderTexture( lua_State *L, int index, bool allowTable );
|
|
||||||
bool isValidCamera2D( lua_State *L, int index, bool allowTable );
|
|
||||||
bool isValidCamera3D( lua_State *L, int index, bool allowTable );
|
|
||||||
/* Lua Util functions. */
|
/* Lua Util functions. */
|
||||||
|
bool uluaGetBoolean( lua_State *L, int index );
|
||||||
Color uluaGetColor( lua_State *L );
|
Color uluaGetColor( lua_State *L );
|
||||||
Color uluaGetColorIndex( lua_State *L, int index );
|
Color uluaGetColorIndex( lua_State *L, int index );
|
||||||
Vector2 uluaGetVector2( lua_State *L );
|
Vector2 uluaGetVector2( lua_State *L );
|
||||||
@@ -65,10 +57,6 @@ Ray uluaGetRay( lua_State *L );
|
|||||||
Ray uluaGetRayIndex( lua_State *L, int index );
|
Ray uluaGetRayIndex( lua_State *L, int index );
|
||||||
NPatchInfo uluaGetNPatchInfo( lua_State *L );
|
NPatchInfo uluaGetNPatchInfo( lua_State *L );
|
||||||
NPatchInfo uluaGetNPatchInfoIndex( lua_State *L, int index );
|
NPatchInfo uluaGetNPatchInfoIndex( lua_State *L, int index );
|
||||||
Texture uluaGetTexture( lua_State *L, int index );
|
|
||||||
RenderTexture uluaGetRenderTexture( lua_State *L, int index );
|
|
||||||
Camera2D uluaGetCamera2D( lua_State *L, int index );
|
|
||||||
Camera3D uluaGetCamera3D( lua_State *L, int index );
|
|
||||||
/* Push types. */
|
/* Push types. */
|
||||||
void uluaPushColor( lua_State *L, Color color );
|
void uluaPushColor( lua_State *L, Color color );
|
||||||
void uluaPushVector2( lua_State *L, Vector2 vector );
|
void uluaPushVector2( lua_State *L, Vector2 vector );
|
||||||
@@ -80,7 +68,12 @@ void uluaPushMatrix( lua_State *L, Matrix matrix );
|
|||||||
void uluaPushRay( lua_State *L, Ray ray );
|
void uluaPushRay( lua_State *L, Ray ray );
|
||||||
void uluaPushRayCollision( lua_State *L, RayCollision rayCol );
|
void uluaPushRayCollision( lua_State *L, RayCollision rayCol );
|
||||||
void uluaPushBoundingBox( lua_State *L, BoundingBox box );
|
void uluaPushBoundingBox( lua_State *L, BoundingBox box );
|
||||||
|
void uluaPushImage( lua_State *L, Image image );
|
||||||
void uluaPushTexture( lua_State *L, Texture texture );
|
void uluaPushTexture( lua_State *L, Texture texture );
|
||||||
|
void uluaPushRenderTexture( lua_State *L, RenderTexture renderTexture );
|
||||||
|
void uluaPushCamera2D( lua_State *L, Camera2D camera );
|
||||||
|
void uluaPushCamera3D( lua_State *L, Camera3D camera );
|
||||||
|
void uluaPushShader( lua_State *L, Shader shader );
|
||||||
|
|
||||||
int uluaGetTableLen( lua_State *L );
|
int uluaGetTableLen( lua_State *L );
|
||||||
int uluaGetTableLenIndex( lua_State *L, int index );
|
int uluaGetTableLenIndex( lua_State *L, int index );
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
#define STRING_LEN 1024
|
#define STRING_LEN 1024
|
||||||
|
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 5
|
#define VERSION_MINOR 6
|
||||||
#define VERSION_PATCH 0
|
#define VERSION_PATCH 0
|
||||||
#define VERSION_DEV 0
|
#define VERSION_DEV 1
|
||||||
|
|
||||||
#include "glad.h"
|
#include "glad.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
@@ -7,13 +7,6 @@ typedef struct {
|
|||||||
unsigned int animCount;
|
unsigned int animCount;
|
||||||
} ModelAnimations;
|
} ModelAnimations;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int type;
|
|
||||||
int texRef; /* TextureReference. */
|
|
||||||
Texture texture;
|
|
||||||
RenderTexture renderTexture;
|
|
||||||
} ReiTexture;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *exePath;
|
char *exePath;
|
||||||
bool hasWindow;
|
bool hasWindow;
|
||||||
@@ -23,14 +16,6 @@ typedef struct {
|
|||||||
size_t guiFont;
|
size_t guiFont;
|
||||||
int logLevelInvalid;
|
int logLevelInvalid;
|
||||||
/* Resources. */
|
/* Resources. */
|
||||||
/* Images. */
|
|
||||||
Image **images;
|
|
||||||
size_t imageCount;
|
|
||||||
size_t imageAlloc;
|
|
||||||
/* Textures. */
|
|
||||||
ReiTexture **textures;
|
|
||||||
size_t textureCount;
|
|
||||||
size_t textureAlloc;
|
|
||||||
/* Fonts. */
|
/* Fonts. */
|
||||||
Font **fonts;
|
Font **fonts;
|
||||||
size_t fontCount;
|
size_t fontCount;
|
||||||
@@ -47,14 +32,6 @@ typedef struct {
|
|||||||
Music **musics;
|
Music **musics;
|
||||||
size_t musicCount;
|
size_t musicCount;
|
||||||
size_t musicAlloc;
|
size_t musicAlloc;
|
||||||
/* Camera2D's. */
|
|
||||||
Camera2D **camera2Ds;
|
|
||||||
size_t camera2DCount;
|
|
||||||
size_t camera2DAlloc;
|
|
||||||
/* Camera3D's. */
|
|
||||||
Camera3D **camera3Ds;
|
|
||||||
size_t camera3DCount;
|
|
||||||
size_t camera3DAlloc;
|
|
||||||
/* Meshes. */
|
/* Meshes. */
|
||||||
Mesh **meshes;
|
Mesh **meshes;
|
||||||
size_t meshCount;
|
size_t meshCount;
|
||||||
@@ -71,10 +48,6 @@ typedef struct {
|
|||||||
ModelAnimations **animations;
|
ModelAnimations **animations;
|
||||||
size_t animationCount;
|
size_t animationCount;
|
||||||
size_t animationAlloc;
|
size_t animationAlloc;
|
||||||
/* Shaders. */
|
|
||||||
Shader **shaders;
|
|
||||||
size_t shaderCount;
|
|
||||||
size_t shaderAlloc;
|
|
||||||
/* Lights. */
|
/* Lights. */
|
||||||
Light **lights;
|
Light **lights;
|
||||||
size_t lightCount;
|
size_t lightCount;
|
||||||
|
|||||||
@@ -1,19 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/* TEXTURE_TYPE_ALL is internal and used for accepting every type. */
|
|
||||||
enum TextureType { TEXTURE_TYPE_TEXTURE, TEXTURE_TYPE_RENDER_TEXTURE, TEXTURE_TYPE_ALL };
|
|
||||||
|
|
||||||
/* Validators. */
|
|
||||||
bool validImage( size_t id );
|
|
||||||
// bool validTexture( size_t id, int type );
|
|
||||||
// bool validTexture( lua_State *L, int index );
|
|
||||||
Texture2D* texturesGetSourceTexture( size_t id );
|
|
||||||
void texturesFreeTexture( size_t id );
|
|
||||||
/* Image Loading. */
|
/* Image Loading. */
|
||||||
int ltexturesLoadImage( lua_State *L );
|
int ltexturesLoadImage( lua_State *L );
|
||||||
int ltexturesLoadImageFromTexture( lua_State *L );
|
int ltexturesLoadImageFromTexture( lua_State *L );
|
||||||
int ltexturesLoadImageFromScreen( lua_State *L );
|
int ltexturesLoadImageFromScreen( lua_State *L );
|
||||||
int ltexturesUnloadImage( lua_State *L );
|
|
||||||
int ltexturesExportImage( lua_State *L );
|
int ltexturesExportImage( lua_State *L );
|
||||||
int ltexturesExportImageAsCode( lua_State *L );
|
int ltexturesExportImageAsCode( lua_State *L );
|
||||||
/* Image Generation. */
|
/* Image Generation. */
|
||||||
@@ -76,7 +66,6 @@ int ltexturesLoadTexture( lua_State *L );
|
|||||||
int ltexturesLoadTextureFromImage( lua_State *L );
|
int ltexturesLoadTextureFromImage( lua_State *L );
|
||||||
int ltexturesLoadTextureCubemap( lua_State *L );
|
int ltexturesLoadTextureCubemap( lua_State *L );
|
||||||
int ltexturesLoadRenderTexture( lua_State *L );
|
int ltexturesLoadRenderTexture( lua_State *L );
|
||||||
int ltexturesUnloadTexture( lua_State *L );
|
|
||||||
int ltexturesIsTextureReady( lua_State *L );
|
int ltexturesIsTextureReady( lua_State *L );
|
||||||
int ltexturesUpdateTexture( lua_State *L );
|
int ltexturesUpdateTexture( lua_State *L );
|
||||||
int ltexturesUpdateTextureRec( lua_State *L );
|
int ltexturesUpdateTextureRec( lua_State *L );
|
||||||
@@ -87,7 +76,6 @@ int ltexturesDrawTexturePro( lua_State *L );
|
|||||||
int ltexturesDrawTextureNPatch( lua_State *L );
|
int ltexturesDrawTextureNPatch( lua_State *L );
|
||||||
int ltexturesBeginTextureMode( lua_State *L );
|
int ltexturesBeginTextureMode( lua_State *L );
|
||||||
int ltexturesEndTextureMode( lua_State *L );
|
int ltexturesEndTextureMode( lua_State *L );
|
||||||
int ltexturesGetTextureType( lua_State *L );
|
|
||||||
/* Texture Configuration. */
|
/* Texture Configuration. */
|
||||||
int ltexturesGenTextureMipmaps( lua_State *L );
|
int ltexturesGenTextureMipmaps( lua_State *L );
|
||||||
int ltexturesSetTextureFilter( lua_State *L );
|
int ltexturesSetTextureFilter( lua_State *L );
|
||||||
@@ -96,6 +84,10 @@ int ltexturesGetTextureId( lua_State *L );
|
|||||||
int ltexturesGetTextureSize( lua_State *L );
|
int ltexturesGetTextureSize( lua_State *L );
|
||||||
int ltexturesGetTextureMipmaps( lua_State *L );
|
int ltexturesGetTextureMipmaps( lua_State *L );
|
||||||
int ltexturesGetTextureFormat( lua_State *L );
|
int ltexturesGetTextureFormat( lua_State *L );
|
||||||
|
/* RenderTexture Configuration. */
|
||||||
|
int ltexturesGetRenderTextureId( lua_State *L );
|
||||||
|
int ltexturesGetRenderTextureTexture( lua_State *L );
|
||||||
|
int ltexturesGetRenderTextureDepthTexture( lua_State *L );
|
||||||
/* Color/pixel */
|
/* Color/pixel */
|
||||||
int ltexturesFade( lua_State *L );
|
int ltexturesFade( lua_State *L );
|
||||||
int ltexturesColorToInt( lua_State *L );
|
int ltexturesColorToInt( lua_State *L );
|
||||||
|
|||||||
1077
src/core.c
1077
src/core.c
File diff suppressed because it is too large
Load Diff
26
src/gl.c
26
src/gl.c
@@ -9,40 +9,32 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> success = RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )
|
> RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )
|
||||||
|
|
||||||
Copy a block of pixels from one framebuffer object to another.
|
Copy a block of pixels from one framebuffer object to another.
|
||||||
Use -1 RenderTexture for window framebuffer.
|
Use -1 RenderTexture for window framebuffer.
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
*/
|
*/
|
||||||
int lglBlitFramebuffer( lua_State *L ) {
|
int lglBlitFramebuffer( lua_State *L ) {
|
||||||
if ( !isValidRenderTexture( L, 1, true ) || !isValidRenderTexture( L, 2, true ) || !lua_istable( L, 3 )
|
// TOCO Currently doesn't support setting window render target because of luaL_checkudata.
|
||||||
|| !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) ) {
|
RenderTexture *srcTex = luaL_checkudata( L, 1, "RenderTexture" );
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.glBlitFramebuffer( RenderTexture srcTex, RenderTexture dstTex, Rectangle srcRect, Rectangle dstRect, int mask, int filter )" );
|
RenderTexture *dstTex = luaL_checkudata( L, 2, "RenderTexture" );
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
RenderTexture2D srcTex = uluaGetRenderTexture( L, 1 );
|
|
||||||
RenderTexture2D dstTex = uluaGetRenderTexture( L, 2 );
|
|
||||||
Rectangle srcRect = uluaGetRectangleIndex( L, 3 );
|
Rectangle srcRect = uluaGetRectangleIndex( L, 3 );
|
||||||
Rectangle dstRect = uluaGetRectangleIndex( L, 4 );
|
Rectangle dstRect = uluaGetRectangleIndex( L, 4 );
|
||||||
int mask = lua_tointeger( L, 5 );
|
int mask = luaL_checkinteger( L, 5 );
|
||||||
int filter = lua_tointeger( L, 6 );
|
int filter = luaL_checkinteger( L, 6 );
|
||||||
|
|
||||||
if ( lua_tointeger( L, 1 ) == -1 ) {
|
if ( lua_tointeger( L, 1 ) == -1 ) {
|
||||||
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
|
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glBindFramebuffer( GL_READ_FRAMEBUFFER, srcTex.id );
|
glBindFramebuffer( GL_READ_FRAMEBUFFER, srcTex->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( lua_tointeger( L, 2 ) == -1 ) {
|
if ( lua_tointeger( L, 2 ) == -1 ) {
|
||||||
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
|
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, dstTex.id );
|
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, dstTex->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
glBlitFramebuffer(
|
glBlitFramebuffer(
|
||||||
@@ -55,7 +47,5 @@ int lglBlitFramebuffer( lua_State *L ) {
|
|||||||
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
|
glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
|
||||||
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
|
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
|
||||||
|
|
||||||
lua_pushboolean( L, true );
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/lights.c
33
src/lights.c
@@ -59,54 +59,35 @@ Create a light and get shader locations
|
|||||||
- Success return int
|
- Success return int
|
||||||
*/
|
*/
|
||||||
int llightsCreateLight( lua_State *L ) {
|
int llightsCreateLight( lua_State *L ) {
|
||||||
if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 )
|
int type = luaL_checkinteger( L, 1 );
|
||||||
|| !lua_istable( L, 4 ) || !lua_isnumber( L, 5 ) ) {
|
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.CreateLight( int type, Vector3 position, Vector3 target, Color color, Shader shader )" );
|
|
||||||
lua_pushinteger( L, -1 );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
int type = lua_tointeger( L, 1 );
|
|
||||||
Vector3 position = uluaGetVector3Index( L, 2 );
|
Vector3 position = uluaGetVector3Index( L, 2 );
|
||||||
Vector3 target = uluaGetVector3Index( L, 3 );
|
Vector3 target = uluaGetVector3Index( L, 3 );
|
||||||
Color color = uluaGetColorIndex( L, 4 );
|
Color color = uluaGetColorIndex( L, 4 );
|
||||||
size_t shaderId = lua_tointeger( L, 5 );
|
Shader *shader = luaL_checkudata( L, 5, "Shader" );
|
||||||
|
|
||||||
int i = newLight();
|
int i = newLight();
|
||||||
*state->lights[i] = CreateLight( type, position, target, color, *state->shaders[ shaderId ] );
|
*state->lights[i] = CreateLight( type, position, target, color, *shader );
|
||||||
lua_pushinteger( L, i );
|
lua_pushinteger( L, i );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> success = RL.UpdateLightValues( Shader shader, Light light )
|
> RL.UpdateLightValues( Shader shader, Light light )
|
||||||
|
|
||||||
Send light properties to shader
|
Send light properties to shader
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
*/
|
*/
|
||||||
int llightsUpdateLightValues( lua_State *L ) {
|
int llightsUpdateLightValues( lua_State *L ) {
|
||||||
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
|
Shader *shader = luaL_checkudata( L, 1, "Shader" );
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UpdateLightValues( Shader shader, Light light )" );
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
size_t shaderId = lua_tointeger( L, 1 );
|
|
||||||
size_t lightId = lua_tointeger( L, 2 );
|
size_t lightId = lua_tointeger( L, 2 );
|
||||||
|
|
||||||
if ( !validLight( lightId ) ) {
|
if ( !validLight( lightId ) ) {
|
||||||
lua_pushboolean( L, false );
|
lua_pushboolean( L, false );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if ( !validShader( shaderId ) ) {
|
UpdateLightValues( *shader, *state->lights[ lightId ] );
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
UpdateLightValues( *state->shaders[ shaderId ], *state->lights[ lightId ] );
|
|
||||||
lua_pushboolean( L, true );
|
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
501
src/lua_core.c
501
src/lua_core.c
@@ -14,6 +14,116 @@
|
|||||||
#include "lgl.h"
|
#include "lgl.h"
|
||||||
#include "reasings.h"
|
#include "reasings.h"
|
||||||
|
|
||||||
|
/* Define types. */
|
||||||
|
|
||||||
|
/* Buffer. */
|
||||||
|
static int gcBuffer( lua_State *L ) {
|
||||||
|
Buffer *buffer = luaL_checkudata ( L, 1, "Buffer" );
|
||||||
|
free( buffer->data );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void defineBuffer() {
|
||||||
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
|
luaL_newmetatable( L, "Buffer" );
|
||||||
|
lua_pushvalue( L, -1 );
|
||||||
|
lua_setfield( L, -2, "__index" );
|
||||||
|
lua_pushcfunction( L, gcBuffer );
|
||||||
|
lua_setfield( L, -2, "__gc" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Image */
|
||||||
|
static int gcImage( lua_State *L ) {
|
||||||
|
Image *image = luaL_checkudata ( L, 1, "Image" );
|
||||||
|
printf( "gcImage\n" );
|
||||||
|
|
||||||
|
UnloadImage( *image );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void defineImage() {
|
||||||
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
|
luaL_newmetatable( L, "Image" );
|
||||||
|
lua_pushvalue( L, -1 );
|
||||||
|
lua_setfield( L, -2, "__index" );
|
||||||
|
lua_pushcfunction( L, gcImage );
|
||||||
|
lua_setfield( L, -2, "__gc" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Texture */
|
||||||
|
static int gcTexture( lua_State *L ) {
|
||||||
|
Texture *texture = luaL_checkudata ( L, 1, "Texture" );
|
||||||
|
printf( "gcTexture\n" );
|
||||||
|
|
||||||
|
UnloadTexture( *texture );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void defineTexture() {
|
||||||
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
|
luaL_newmetatable( L, "Texture" );
|
||||||
|
lua_pushvalue( L, -1 );
|
||||||
|
lua_setfield( L, -2, "__index" );
|
||||||
|
lua_pushcfunction( L, gcTexture );
|
||||||
|
lua_setfield( L, -2, "__gc" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RenderRexture. */
|
||||||
|
static int gcRenderTexture( lua_State *L ) {
|
||||||
|
RenderTexture *renderTexture = luaL_checkudata ( L, 1, "RenderTexture" );
|
||||||
|
printf( "gcRenderTexture\n" );
|
||||||
|
|
||||||
|
UnloadRenderTexture( *renderTexture );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void defineRenderTexture() {
|
||||||
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
|
luaL_newmetatable( L, "RenderTexture" );
|
||||||
|
lua_pushvalue( L, -1 );
|
||||||
|
lua_setfield( L, -2, "__index" );
|
||||||
|
lua_pushcfunction( L, gcRenderTexture );
|
||||||
|
lua_setfield( L, -2, "__gc" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Camera2D. */
|
||||||
|
static void defineCamera2D() {
|
||||||
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
|
luaL_newmetatable( L, "Camera2D" );
|
||||||
|
lua_pushvalue( L, -1 );
|
||||||
|
lua_setfield( L, -2, "__index" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Camera3D. */
|
||||||
|
static void defineCamera3D() {
|
||||||
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
|
luaL_newmetatable( L, "Camera3D" );
|
||||||
|
lua_pushvalue( L, -1 );
|
||||||
|
lua_setfield( L, -2, "__index" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Shader. */
|
||||||
|
static int gcShader( lua_State *L ) {
|
||||||
|
Shader *shader = luaL_checkudata ( L, 1, "Shader" );
|
||||||
|
printf( "gcShader\n" );
|
||||||
|
|
||||||
|
UnloadShader( *shader );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void defineShader() {
|
||||||
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
|
luaL_newmetatable( L, "Shader" );
|
||||||
|
lua_pushvalue( L, -1 );
|
||||||
|
lua_setfield( L, -2, "__index" );
|
||||||
|
lua_pushcfunction( L, gcShader );
|
||||||
|
lua_setfield( L, -2, "__gc" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Assing globals. */
|
||||||
|
|
||||||
static void assignGlobalInt( int value, const char *name ) {
|
static void assignGlobalInt( int value, const char *name ) {
|
||||||
lua_State *L = state->luaState;
|
lua_State *L = state->luaState;
|
||||||
lua_pushinteger( L, value );
|
lua_pushinteger( L, value );
|
||||||
@@ -371,9 +481,6 @@ static void defineGlobals() {
|
|||||||
assignGlobalInt( NPATCH_NINE_PATCH, "NPATCH_NINE_PATCH" );
|
assignGlobalInt( NPATCH_NINE_PATCH, "NPATCH_NINE_PATCH" );
|
||||||
assignGlobalInt( NPATCH_THREE_PATCH_VERTICAL, "NPATCH_THREE_PATCH_VERTICAL" );
|
assignGlobalInt( NPATCH_THREE_PATCH_VERTICAL, "NPATCH_THREE_PATCH_VERTICAL" );
|
||||||
assignGlobalInt( NPATCH_THREE_PATCH_HORIZONTAL, "NPATCH_THREE_PATCH_HORIZONTAL" );
|
assignGlobalInt( NPATCH_THREE_PATCH_HORIZONTAL, "NPATCH_THREE_PATCH_HORIZONTAL" );
|
||||||
/* TextureTypes */
|
|
||||||
assignGlobalInt( TEXTURE_TYPE_TEXTURE, "TEXTURE_TYPE_TEXTURE" );
|
|
||||||
assignGlobalInt( TEXTURE_TYPE_RENDER_TEXTURE, "TEXTURE_TYPE_RENDER_TEXTURE" );
|
|
||||||
/* Colors */
|
/* Colors */
|
||||||
assignGlobalColor( LIGHTGRAY, "LIGHTGRAY" );
|
assignGlobalColor( LIGHTGRAY, "LIGHTGRAY" );
|
||||||
assignGlobalColor( GRAY, "GRAY" );
|
assignGlobalColor( GRAY, "GRAY" );
|
||||||
@@ -641,39 +748,6 @@ static void defineGlobals() {
|
|||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gcBuffer( lua_State *L ) {
|
|
||||||
Buffer *buffer = luaL_checkudata ( L, 1, "Buffer" );
|
|
||||||
free( buffer->data );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void defineBuffer() {
|
|
||||||
lua_State *L = state->luaState;
|
|
||||||
|
|
||||||
luaL_newmetatable( L, "Buffer" );
|
|
||||||
lua_pushvalue( L, -1 );
|
|
||||||
lua_setfield( L, -2, "__index" );
|
|
||||||
lua_pushcfunction( L, gcBuffer );
|
|
||||||
lua_setfield( L, -2, "__gc" );
|
|
||||||
}
|
|
||||||
|
|
||||||
// static int gcTexture( lua_State *L ) {
|
|
||||||
// Texture *texture = luaL_checkudata ( L, 1, "Texture" );
|
|
||||||
// printf( "gcTexture\n" );
|
|
||||||
// printf( "\ttexture->id = %d\n", texture->id );
|
|
||||||
|
|
||||||
// UnloadTexture( *texture );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// static void defineTexture() {
|
|
||||||
// lua_State *L = state->luaState;
|
|
||||||
|
|
||||||
// luaL_newmetatable( L, "Texture" );
|
|
||||||
// lua_pushvalue( L, -1 );
|
|
||||||
// lua_setfield( L, -2, "__index" );
|
|
||||||
// lua_pushcfunction( L, gcTexture );
|
|
||||||
// lua_setfield( L, -2, "__gc" );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Custom logging funtion.
|
// Custom logging funtion.
|
||||||
static void logCustom( int logLevel, const char *text, va_list args ) {
|
static void logCustom( int logLevel, const char *text, va_list args ) {
|
||||||
char string[ STRING_LEN ] = {'\0'};
|
char string[ STRING_LEN ] = {'\0'};
|
||||||
@@ -1060,8 +1134,14 @@ bool luaInit( int argn, const char **argc ) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
defineGlobals();
|
defineGlobals();
|
||||||
|
/* Define object types. */
|
||||||
defineBuffer();
|
defineBuffer();
|
||||||
// defineTexture();
|
defineImage();
|
||||||
|
defineTexture();
|
||||||
|
defineRenderTexture();
|
||||||
|
defineCamera2D();
|
||||||
|
defineCamera3D();
|
||||||
|
defineShader();
|
||||||
|
|
||||||
/* Set arguments. */
|
/* Set arguments. */
|
||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
@@ -1124,7 +1204,6 @@ bool luaCallMain() {
|
|||||||
if ( lua_tostring( state->luaState, -1 ) ) {
|
if ( lua_tostring( state->luaState, -1 ) ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s\n", lua_tostring( state->luaState, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s\n", lua_tostring( state->luaState, -1 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pushcfunction( L, luaTraceback );
|
lua_pushcfunction( L, luaTraceback );
|
||||||
int tracebackidx = lua_gettop( L );
|
int tracebackidx = lua_gettop( L );
|
||||||
|
|
||||||
@@ -1235,7 +1314,6 @@ void luaRegister() {
|
|||||||
|
|
||||||
/* Core. */
|
/* Core. */
|
||||||
/* Window. */
|
/* Window. */
|
||||||
|
|
||||||
assingGlobalFunction( "IsWindowReady", lcoreIsWindowReady );
|
assingGlobalFunction( "IsWindowReady", lcoreIsWindowReady );
|
||||||
assingGlobalFunction( "IsWindowFullscreen", lcoreIsWindowFullscreen );
|
assingGlobalFunction( "IsWindowFullscreen", lcoreIsWindowFullscreen );
|
||||||
assingGlobalFunction( "IsWindowHidden", lcoreIsWindowHidden );
|
assingGlobalFunction( "IsWindowHidden", lcoreIsWindowHidden );
|
||||||
@@ -1307,7 +1385,6 @@ void luaRegister() {
|
|||||||
assingGlobalFunction( "SetShaderValueTexture", lcoreSetShaderValueTexture );
|
assingGlobalFunction( "SetShaderValueTexture", lcoreSetShaderValueTexture );
|
||||||
assingGlobalFunction( "SetShaderValue", lcoreSetShaderValue );
|
assingGlobalFunction( "SetShaderValue", lcoreSetShaderValue );
|
||||||
assingGlobalFunction( "SetShaderValueV", lcoreSetShaderValueV );
|
assingGlobalFunction( "SetShaderValueV", lcoreSetShaderValueV );
|
||||||
assingGlobalFunction( "UnloadShader", lcoreUnloadShader );
|
|
||||||
/* File. */
|
/* File. */
|
||||||
assingGlobalFunction( "GetBasePath", lcoreGetBasePath );
|
assingGlobalFunction( "GetBasePath", lcoreGetBasePath );
|
||||||
assingGlobalFunction( "FileExists", lcoreFileExists );
|
assingGlobalFunction( "FileExists", lcoreFileExists );
|
||||||
@@ -1329,7 +1406,6 @@ void luaRegister() {
|
|||||||
assingGlobalFunction( "GetFileModTime", lcoreGetFileModTime );
|
assingGlobalFunction( "GetFileModTime", lcoreGetFileModTime );
|
||||||
/* Camera2D. */
|
/* Camera2D. */
|
||||||
assingGlobalFunction( "CreateCamera2D", lcoreCreateCamera2D );
|
assingGlobalFunction( "CreateCamera2D", lcoreCreateCamera2D );
|
||||||
assingGlobalFunction( "UnloadCamera2D", lcoreUnloadCamera2D );
|
|
||||||
assingGlobalFunction( "BeginMode2D", lcoreBeginMode2D );
|
assingGlobalFunction( "BeginMode2D", lcoreBeginMode2D );
|
||||||
assingGlobalFunction( "EndMode2D", lcoreEndMode2D );
|
assingGlobalFunction( "EndMode2D", lcoreEndMode2D );
|
||||||
assingGlobalFunction( "SetCamera2DTarget", lcoreSetCamera2DTarget );
|
assingGlobalFunction( "SetCamera2DTarget", lcoreSetCamera2DTarget );
|
||||||
@@ -1342,7 +1418,6 @@ void luaRegister() {
|
|||||||
assingGlobalFunction( "GetCamera2DZoom", lcoreGetCamera2DZoom );
|
assingGlobalFunction( "GetCamera2DZoom", lcoreGetCamera2DZoom );
|
||||||
/* Camera3D. */
|
/* Camera3D. */
|
||||||
assingGlobalFunction( "CreateCamera3D", lcoreCreateCamera3D );
|
assingGlobalFunction( "CreateCamera3D", lcoreCreateCamera3D );
|
||||||
assingGlobalFunction( "UnloadCamera3D", lcoreUnloadCamera3D );
|
|
||||||
assingGlobalFunction( "BeginMode3D", lcoreBeginMode3D );
|
assingGlobalFunction( "BeginMode3D", lcoreBeginMode3D );
|
||||||
assingGlobalFunction( "EndMode3D", lcoreEndMode3D );
|
assingGlobalFunction( "EndMode3D", lcoreEndMode3D );
|
||||||
assingGlobalFunction( "SetCamera3DPosition", lcoreSetCamera3DPosition );
|
assingGlobalFunction( "SetCamera3DPosition", lcoreSetCamera3DPosition );
|
||||||
@@ -1472,7 +1547,6 @@ void luaRegister() {
|
|||||||
assingGlobalFunction( "LoadImage", ltexturesLoadImage );
|
assingGlobalFunction( "LoadImage", ltexturesLoadImage );
|
||||||
assingGlobalFunction( "LoadImageFromTexture", ltexturesLoadImageFromTexture );
|
assingGlobalFunction( "LoadImageFromTexture", ltexturesLoadImageFromTexture );
|
||||||
assingGlobalFunction( "LoadImageFromScreen", ltexturesLoadImageFromScreen );
|
assingGlobalFunction( "LoadImageFromScreen", ltexturesLoadImageFromScreen );
|
||||||
assingGlobalFunction( "UnloadImage", ltexturesUnloadImage );
|
|
||||||
assingGlobalFunction( "ExportImage", ltexturesExportImage );
|
assingGlobalFunction( "ExportImage", ltexturesExportImage );
|
||||||
assingGlobalFunction( "ExportImageAsCode", ltexturesExportImageAsCode );
|
assingGlobalFunction( "ExportImageAsCode", ltexturesExportImageAsCode );
|
||||||
/* Image Generation. */
|
/* Image Generation. */
|
||||||
@@ -1535,7 +1609,6 @@ void luaRegister() {
|
|||||||
assingGlobalFunction( "LoadTextureFromImage", ltexturesLoadTextureFromImage );
|
assingGlobalFunction( "LoadTextureFromImage", ltexturesLoadTextureFromImage );
|
||||||
assingGlobalFunction( "LoadTextureCubemap", ltexturesLoadTextureCubemap );
|
assingGlobalFunction( "LoadTextureCubemap", ltexturesLoadTextureCubemap );
|
||||||
assingGlobalFunction( "LoadRenderTexture", ltexturesLoadRenderTexture );
|
assingGlobalFunction( "LoadRenderTexture", ltexturesLoadRenderTexture );
|
||||||
assingGlobalFunction( "UnloadTexture", ltexturesUnloadTexture );
|
|
||||||
assingGlobalFunction( "IsTextureReady", ltexturesIsTextureReady );
|
assingGlobalFunction( "IsTextureReady", ltexturesIsTextureReady );
|
||||||
assingGlobalFunction( "UpdateTexture", ltexturesUpdateTexture );
|
assingGlobalFunction( "UpdateTexture", ltexturesUpdateTexture );
|
||||||
assingGlobalFunction( "UpdateTextureRec", ltexturesUpdateTextureRec );
|
assingGlobalFunction( "UpdateTextureRec", ltexturesUpdateTextureRec );
|
||||||
@@ -1546,7 +1619,6 @@ void luaRegister() {
|
|||||||
assingGlobalFunction( "DrawTextureNPatch", ltexturesDrawTextureNPatch );
|
assingGlobalFunction( "DrawTextureNPatch", ltexturesDrawTextureNPatch );
|
||||||
assingGlobalFunction( "BeginTextureMode", ltexturesBeginTextureMode );
|
assingGlobalFunction( "BeginTextureMode", ltexturesBeginTextureMode );
|
||||||
assingGlobalFunction( "EndTextureMode", ltexturesEndTextureMode );
|
assingGlobalFunction( "EndTextureMode", ltexturesEndTextureMode );
|
||||||
assingGlobalFunction( "GetTextureType", ltexturesGetTextureType );
|
|
||||||
/* Texture Configuration. */
|
/* Texture Configuration. */
|
||||||
assingGlobalFunction( "GenTextureMipmaps", ltexturesGenTextureMipmaps );
|
assingGlobalFunction( "GenTextureMipmaps", ltexturesGenTextureMipmaps );
|
||||||
assingGlobalFunction( "SetTextureFilter", ltexturesSetTextureFilter );
|
assingGlobalFunction( "SetTextureFilter", ltexturesSetTextureFilter );
|
||||||
@@ -1555,6 +1627,10 @@ void luaRegister() {
|
|||||||
assingGlobalFunction( "GetTextureSize", ltexturesGetTextureSize );
|
assingGlobalFunction( "GetTextureSize", ltexturesGetTextureSize );
|
||||||
assingGlobalFunction( "GetTextureMipmaps", ltexturesGetTextureMipmaps );
|
assingGlobalFunction( "GetTextureMipmaps", ltexturesGetTextureMipmaps );
|
||||||
assingGlobalFunction( "GetTextureFormat", ltexturesGetTextureFormat );
|
assingGlobalFunction( "GetTextureFormat", ltexturesGetTextureFormat );
|
||||||
|
/* RenderTexture Configuration. */
|
||||||
|
assingGlobalFunction( "GetRenderTextureId", ltexturesGetRenderTextureId );
|
||||||
|
assingGlobalFunction( "GetRenderTextureTexture", ltexturesGetRenderTextureTexture );
|
||||||
|
assingGlobalFunction( "GetRenderTextureDepthTexture", ltexturesGetRenderTextureDepthTexture );
|
||||||
/* Color/pixel */
|
/* Color/pixel */
|
||||||
assingGlobalFunction( "Fade", ltexturesFade );
|
assingGlobalFunction( "Fade", ltexturesFade );
|
||||||
assingGlobalFunction( "ColorToInt", ltexturesColorToInt );
|
assingGlobalFunction( "ColorToInt", ltexturesColorToInt );
|
||||||
@@ -2063,76 +2139,20 @@ void luaRegister() {
|
|||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Type validators. */
|
|
||||||
|
|
||||||
bool isValidTexture( lua_State *L, int index, bool allowTable ) {
|
|
||||||
if ( lua_isnumber( L, index ) ) {
|
|
||||||
int id = lua_tointeger( L, index );
|
|
||||||
|
|
||||||
if ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( allowTable && lua_istable( L, index ) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Texture." );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isValidRenderTexture( lua_State *L, int index, bool allowTable ) {
|
|
||||||
if ( lua_isnumber( L, index ) ) {
|
|
||||||
int id = lua_tointeger( L, index );
|
|
||||||
|
|
||||||
if ( 0 <= id && id < state->textureCount && state->textures[ id ] != NULL
|
|
||||||
&& state->textures[ id ]->type == TEXTURE_TYPE_RENDER_TEXTURE ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( allowTable && lua_istable( L, index ) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid RenderTexture." );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isValidCamera2D( lua_State *L, int index, bool allowTable ) {
|
|
||||||
if ( lua_isnumber( L, index ) ) {
|
|
||||||
int id = lua_tointeger( L, index );
|
|
||||||
|
|
||||||
if ( 0 <= id && id < state->camera2DCount && state->camera2Ds[ id ] != NULL ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( allowTable && lua_istable( L, index ) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera2D." );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isValidCamera3D( lua_State *L, int index, bool allowTable ) {
|
|
||||||
if ( lua_isnumber( L, index ) ) {
|
|
||||||
int id = lua_tointeger( L, index );
|
|
||||||
|
|
||||||
if ( ( 0 <= id && id < state->camera3DCount && state->camera3Ds[ id ] != NULL ) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( allowTable && lua_istable( L, index ) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Error. Invalid Camera3D." );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Lua util functions. */
|
/* Lua util functions. */
|
||||||
|
|
||||||
|
bool uluaGetBoolean( lua_State *L, int index ) {
|
||||||
|
luaL_checktype( L, index, LUA_TBOOLEAN );
|
||||||
|
|
||||||
|
return lua_toboolean( L, index );
|
||||||
|
}
|
||||||
|
|
||||||
Color uluaGetColor( lua_State *L ) {
|
Color uluaGetColor( lua_State *L ) {
|
||||||
return uluaGetColorIndex( L, lua_gettop( L ) );
|
return uluaGetColorIndex( L, lua_gettop( L ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
Color uluaGetColorIndex( lua_State *L, int index ) {
|
Color uluaGetColorIndex( lua_State *L, int index ) {
|
||||||
|
luaL_checktype( L, index, LUA_TTABLE );
|
||||||
Color color = { 0, 0, 0, 255 };
|
Color color = { 0, 0, 0, 255 };
|
||||||
|
|
||||||
if ( !lua_istable( L, index ) ) {
|
if ( !lua_istable( L, index ) ) {
|
||||||
@@ -2188,7 +2208,7 @@ Vector2 uluaGetVector2( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector2 uluaGetVector2Index( lua_State *L, int index ) {
|
Vector2 uluaGetVector2Index( lua_State *L, int index ) {
|
||||||
// luaL_checktype( L, index, LUA_TTABLE );
|
luaL_checktype( L, index, LUA_TTABLE );
|
||||||
Vector2 vector = { 0.0f, 0.0f };
|
Vector2 vector = { 0.0f, 0.0f };
|
||||||
|
|
||||||
if ( !lua_istable( L, index ) ) {
|
if ( !lua_istable( L, index ) ) {
|
||||||
@@ -2232,6 +2252,7 @@ Vector3 uluaGetVector3( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector3 uluaGetVector3Index( lua_State *L, int index ) {
|
Vector3 uluaGetVector3Index( lua_State *L, int index ) {
|
||||||
|
luaL_checktype( L, index, LUA_TTABLE );
|
||||||
Vector3 vector = { 0.0f, 0.0f, 0.0f };
|
Vector3 vector = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
if ( !lua_istable( L, index ) ) {
|
if ( !lua_istable( L, index ) ) {
|
||||||
@@ -2281,6 +2302,7 @@ Vector4 uluaGetVector4( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector4 uluaGetVector4Index( lua_State *L, int index ) {
|
Vector4 uluaGetVector4Index( lua_State *L, int index ) {
|
||||||
|
luaL_checktype( L, index, LUA_TTABLE );
|
||||||
Vector4 vector = { 0.0f, 0.0f, 0.0f, 0.0f };
|
Vector4 vector = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
if ( !lua_istable( L, index ) ) {
|
if ( !lua_istable( L, index ) ) {
|
||||||
@@ -2336,6 +2358,7 @@ Rectangle uluaGetRectangle( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Rectangle uluaGetRectangleIndex( lua_State *L, int index ) {
|
Rectangle uluaGetRectangleIndex( lua_State *L, int index ) {
|
||||||
|
luaL_checktype( L, index, LUA_TTABLE );
|
||||||
Rectangle rect = { 0.0f, 0.0f, 0.0f, 0.0f };
|
Rectangle rect = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
if ( !lua_istable( L, index ) ) {
|
if ( !lua_istable( L, index ) ) {
|
||||||
@@ -2392,6 +2415,7 @@ Quaternion uluaGetQuaternion( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Quaternion uluaGetQuaternionIndex( lua_State *L, int index ) {
|
Quaternion uluaGetQuaternionIndex( lua_State *L, int index ) {
|
||||||
|
luaL_checktype( L, index, LUA_TTABLE );
|
||||||
Quaternion quaternion = { 0.0f, 0.0f, 0.0f, 0.0f };
|
Quaternion quaternion = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
if ( !lua_istable( L, index ) ) {
|
if ( !lua_istable( L, index ) ) {
|
||||||
@@ -2447,6 +2471,7 @@ Matrix uluaGetMatrix( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Matrix uluaGetMatrixIndex( lua_State *L, int index ) {
|
Matrix uluaGetMatrixIndex( lua_State *L, int index ) {
|
||||||
|
luaL_checktype( L, index, LUA_TTABLE );
|
||||||
Matrix matrix = { 0.0f };
|
Matrix matrix = { 0.0f };
|
||||||
float m[4][4];
|
float m[4][4];
|
||||||
|
|
||||||
@@ -2486,6 +2511,7 @@ BoundingBox uluaGetBoundingBox( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BoundingBox uluaGetBoundingBoxIndex( lua_State *L, int index ) {
|
BoundingBox uluaGetBoundingBoxIndex( lua_State *L, int index ) {
|
||||||
|
luaL_checktype( L, index, LUA_TTABLE );
|
||||||
BoundingBox box = { .min = { 0.0, 0.0, 0.0 }, .max = { 0.0, 0.0, 0.0 } };
|
BoundingBox box = { .min = { 0.0, 0.0, 0.0 }, .max = { 0.0, 0.0, 0.0 } };
|
||||||
|
|
||||||
if ( !lua_istable( L, index ) ) {
|
if ( !lua_istable( L, index ) ) {
|
||||||
@@ -2530,6 +2556,7 @@ Ray uluaGetRay( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ray uluaGetRayIndex( lua_State *L, int index ) {
|
Ray uluaGetRayIndex( lua_State *L, int index ) {
|
||||||
|
luaL_checktype( L, index, LUA_TTABLE );
|
||||||
Ray ray = { .position = { 0.0, 0.0, 0.0 }, .direction = { 0.0, 0.0, 0.0 } };
|
Ray ray = { .position = { 0.0, 0.0, 0.0 }, .direction = { 0.0, 0.0, 0.0 } };
|
||||||
|
|
||||||
if ( !lua_istable( L, index ) ) {
|
if ( !lua_istable( L, index ) ) {
|
||||||
@@ -2574,6 +2601,7 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NPatchInfo uluaGetNPatchInfoIndex( lua_State *L, int index ) {
|
NPatchInfo uluaGetNPatchInfoIndex( lua_State *L, int index ) {
|
||||||
|
luaL_checktype( L, index, LUA_TTABLE );
|
||||||
NPatchInfo npatch = { .source = { 0.0, 0.0, 0.0, 0.0 }, .left = 0, .top = 0, .right = 0, .bottom = 0, .layout = NPATCH_NINE_PATCH };
|
NPatchInfo npatch = { .source = { 0.0, 0.0, 0.0, 0.0 }, .left = 0, .top = 0, .right = 0, .bottom = 0, .layout = NPATCH_NINE_PATCH };
|
||||||
|
|
||||||
if ( !lua_istable( L, index ) ) {
|
if ( !lua_istable( L, index ) ) {
|
||||||
@@ -2635,216 +2663,6 @@ NPatchInfo uluaGetNPatchInfoIndex( lua_State *L, int index ) {
|
|||||||
return npatch;
|
return npatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture uluaGetTexture( lua_State *L, int index ) {
|
|
||||||
Texture texture = { 0 };
|
|
||||||
|
|
||||||
if ( lua_isnumber( L, index ) ) {
|
|
||||||
texture = *texturesGetSourceTexture( lua_tointeger( L, index ) );
|
|
||||||
}
|
|
||||||
else if ( lua_istable( L, index ) ) {
|
|
||||||
int t = index, i = 0;
|
|
||||||
lua_pushnil( L );
|
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
|
||||||
if ( lua_isnumber( L, -2 ) ) {
|
|
||||||
switch ( i ) {
|
|
||||||
case 0:
|
|
||||||
texture.id = lua_tointeger( L, -1 );
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
texture.width = lua_tointeger( L, -1 );
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
texture.height = lua_tointeger( L, -1 );
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
texture.mipmaps = lua_tointeger( L, -1 );
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
texture.format = lua_tointeger( L, -1 );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( lua_isstring( L, -2 ) ) {
|
|
||||||
if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
texture.id = lua_tointeger( L, -1 );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "width", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
texture.width = lua_tointeger( L, -1 );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "height", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
texture.height = lua_tointeger( L, -1 );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "mipmaps", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
texture.mipmaps = lua_tointeger( L, -1 );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "format", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
texture.format = lua_tointeger( L, -1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
lua_pop( L, 1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderTexture uluaGetRenderTexture( lua_State *L, int index ) {
|
|
||||||
RenderTexture renderTexture = { 0 };
|
|
||||||
|
|
||||||
if ( lua_isnumber( L, index ) ) {
|
|
||||||
renderTexture = state->textures[ lua_tointeger( L, index ) ]->renderTexture;
|
|
||||||
}
|
|
||||||
else if ( lua_istable( L, index ) ) {
|
|
||||||
int t = index, i = 0;
|
|
||||||
lua_pushnil( L );
|
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
|
||||||
if ( lua_isnumber( L, -2 ) ) {
|
|
||||||
switch ( i ) {
|
|
||||||
case 0:
|
|
||||||
renderTexture.id = lua_tointeger( L, -1 );
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
renderTexture.texture = uluaGetTexture( L, lua_gettop( L ) );
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
renderTexture.depth = uluaGetTexture( L, lua_gettop( L ) );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( lua_isstring( L, -2 ) ) {
|
|
||||||
if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
renderTexture.id = lua_tointeger( L, -1 );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
renderTexture.texture = uluaGetTexture( L, lua_gettop( L ) );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "depth", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
renderTexture.depth = uluaGetTexture( L, lua_gettop( L ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
lua_pop( L, 1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return renderTexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
Camera2D uluaGetCamera2D( lua_State *L, int index ) {
|
|
||||||
Camera2D camera = { 0 };
|
|
||||||
|
|
||||||
if ( lua_isnumber( L, index ) ) {
|
|
||||||
camera = *state->camera2Ds[ lua_tointeger( L, index ) ];
|
|
||||||
}
|
|
||||||
else if ( lua_istable( L, index ) ) {
|
|
||||||
int t = index, i = 0;
|
|
||||||
lua_pushnil( L );
|
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
|
||||||
if ( lua_isnumber( L, -2 ) ) {
|
|
||||||
switch ( i ) {
|
|
||||||
case 0:
|
|
||||||
camera.offset = uluaGetVector2Index( L, lua_gettop( L ) );
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
camera.target = uluaGetVector2Index( L, lua_gettop( L ) );
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
camera.rotation = lua_tonumber( L, -1 );
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
camera.zoom = lua_tonumber( L, -1 );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( lua_isstring( L, -2 ) ) {
|
|
||||||
if ( strcmp( "offset", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
camera.offset = uluaGetVector2Index( L, lua_gettop( L ) );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "target", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
camera.target = uluaGetVector2Index( L, lua_gettop( L ) );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "rotation", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
camera.rotation = lua_tonumber( L, -1 );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "zoom", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
camera.zoom = lua_tonumber( L, -1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
lua_pop( L, 1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
Camera3D uluaGetCamera3D( lua_State *L, int index ) {
|
|
||||||
Camera3D camera = { 0 };
|
|
||||||
|
|
||||||
if ( lua_isnumber( L, index ) ) {
|
|
||||||
camera = *state->camera3Ds[ lua_tointeger( L, index ) ];
|
|
||||||
}
|
|
||||||
else if ( lua_istable( L, index ) ) {
|
|
||||||
int t = index, i = 0;
|
|
||||||
lua_pushnil( L );
|
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
|
||||||
if ( lua_isnumber( L, -2 ) ) {
|
|
||||||
switch ( i ) {
|
|
||||||
case 0:
|
|
||||||
camera.position = uluaGetVector3Index( L, lua_gettop( L ) );
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
camera.target = uluaGetVector3Index( L, lua_gettop( L ) );
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
camera.up = uluaGetVector3Index( L, lua_gettop( L ) );
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
camera.fovy = lua_tonumber( L, -1 );
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
camera.projection = lua_tointeger( L, -1 );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( lua_isstring( L, -2 ) ) {
|
|
||||||
if ( strcmp( "position", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
camera.position = uluaGetVector3Index( L, lua_gettop( L ) );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "target", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
camera.target = uluaGetVector3Index( L, lua_gettop( L ) );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "up", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
camera.up = uluaGetVector3Index( L, lua_gettop( L ) );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "fovy", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
camera.fovy = lua_tonumber( L, -1 );
|
|
||||||
}
|
|
||||||
else if ( strcmp( "projection", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
|
||||||
camera.projection = lua_tointeger( L, -1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
lua_pop( L, 1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Push types. */
|
/* Push types. */
|
||||||
|
|
||||||
void uluaPushColor( lua_State *L, Color color ) {
|
void uluaPushColor( lua_State *L, Color color ) {
|
||||||
@@ -3017,18 +2835,40 @@ void uluaPushBoundingBox( lua_State *L, BoundingBox box ) {
|
|||||||
lua_rawseti( L, -2, 2 );
|
lua_rawseti( L, -2, 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uluaPushImage( lua_State *L, Image image ) {
|
||||||
|
Image *imageP = lua_newuserdata( L, sizeof( Image ) );
|
||||||
|
*imageP = image;
|
||||||
|
luaL_setmetatable( L, "Image" );
|
||||||
|
}
|
||||||
|
|
||||||
void uluaPushTexture( lua_State *L, Texture texture ) {
|
void uluaPushTexture( lua_State *L, Texture texture ) {
|
||||||
lua_createtable( L, 5, 0 );
|
Texture *textureP = lua_newuserdata( L, sizeof( Texture ) );
|
||||||
lua_pushinteger( L, texture.id );
|
*textureP = texture;
|
||||||
lua_setfield( L, -2, "id" );
|
luaL_setmetatable( L, "Texture" );
|
||||||
lua_pushinteger( L, texture.width );
|
}
|
||||||
lua_setfield( L, -2, "width" );
|
|
||||||
lua_pushinteger( L, texture.height );
|
void uluaPushRenderTexture( lua_State *L, RenderTexture renderTexture ) {
|
||||||
lua_setfield( L, -2, "height" );
|
RenderTexture *renderTextureP = lua_newuserdata( L, sizeof( RenderTexture ) );
|
||||||
lua_pushinteger( L, texture.mipmaps );
|
*renderTextureP = renderTexture;
|
||||||
lua_setfield( L, -2, "mipmaps" );
|
luaL_setmetatable( L, "RenderTexture" );
|
||||||
lua_pushinteger( L, texture.format );
|
}
|
||||||
lua_setfield( L, -2, "format" );
|
|
||||||
|
void uluaPushCamera2D( lua_State *L, Camera2D camera ) {
|
||||||
|
Camera2D *cameraP = lua_newuserdata( L, sizeof( Camera2D ) );
|
||||||
|
*cameraP = camera;
|
||||||
|
luaL_setmetatable( L, "Camera2D" );
|
||||||
|
}
|
||||||
|
|
||||||
|
void uluaPushCamera3D( lua_State *L, Camera3D camera ) {
|
||||||
|
Camera3D *cameraP = lua_newuserdata( L, sizeof( Camera3D ) );
|
||||||
|
*cameraP = camera;
|
||||||
|
luaL_setmetatable( L, "Camera3D" );
|
||||||
|
}
|
||||||
|
|
||||||
|
void uluaPushShader( lua_State *L, Shader shader ) {
|
||||||
|
Shader *shaderP = lua_newuserdata( L, sizeof( Shader ) );
|
||||||
|
*shaderP = shader;
|
||||||
|
luaL_setmetatable( L, "Shader" );
|
||||||
}
|
}
|
||||||
|
|
||||||
int uluaGetTableLen( lua_State *L ) {
|
int uluaGetTableLen( lua_State *L ) {
|
||||||
@@ -3036,6 +2876,7 @@ int uluaGetTableLen( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int uluaGetTableLenIndex( lua_State *L, int index ) {
|
int uluaGetTableLenIndex( lua_State *L, int index ) {
|
||||||
|
luaL_checktype( L, index, LUA_TTABLE );
|
||||||
int t = index, i = 0;
|
int t = index, i = 0;
|
||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
|
|||||||
221
src/models.c
221
src/models.c
@@ -700,21 +700,12 @@ int lmodelsDrawPlane( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> success = RL.DrawQuad3DTexture( Texture2D texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )
|
> RL.DrawQuad3DTexture( Texture texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )
|
||||||
|
|
||||||
Draw 3D textured quad. ( Texture coordinates opengl style 0.0 - 1.0 ).
|
Draw 3D textured quad. ( Texture coordinates opengl style 0.0 - 1.0 ).
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
*/
|
*/
|
||||||
int lmodelDrawQuad3DTexture( lua_State *L ) {
|
int lmodelDrawQuad3DTexture( lua_State *L ) {
|
||||||
if ( !isValidTexture( L, 1, true ) || !lua_istable( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) ) {
|
Texture *texture = luaL_checkudata( L, 1, "Texture" );
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawQuad3DTexture( Texture2D texture, Vector3{} vertices, Vector2{} texCoords, Color{} colors )" );
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
/* Texture. */
|
|
||||||
Texture texture = uluaGetTexture( L, 1 );
|
|
||||||
|
|
||||||
/* Vertices. */
|
/* Vertices. */
|
||||||
Vector3 vertices[4] = { 0 };
|
Vector3 vertices[4] = { 0 };
|
||||||
@@ -762,7 +753,7 @@ int lmodelDrawQuad3DTexture( lua_State *L ) {
|
|||||||
|
|
||||||
/* Draw. */
|
/* Draw. */
|
||||||
rlCheckRenderBatchLimit( 4 );
|
rlCheckRenderBatchLimit( 4 );
|
||||||
rlSetTexture( texture.id );
|
rlSetTexture( texture->id );
|
||||||
|
|
||||||
rlBegin( RL_QUADS );
|
rlBegin( RL_QUADS );
|
||||||
for ( i = 0; i < 4; ++i ) {
|
for ( i = 0; i < 4; ++i ) {
|
||||||
@@ -773,9 +764,7 @@ int lmodelDrawQuad3DTexture( lua_State *L ) {
|
|||||||
rlEnd();
|
rlEnd();
|
||||||
rlSetTexture( 0 );
|
rlSetTexture( 0 );
|
||||||
|
|
||||||
lua_pushboolean( L, true );
|
return 0;
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1053,19 +1042,9 @@ Generate heightmap mesh from image data
|
|||||||
- Success return int
|
- Success return int
|
||||||
*/
|
*/
|
||||||
int lmodelsGenMeshHeightmap( lua_State *L ) {
|
int lmodelsGenMeshHeightmap( lua_State *L ) {
|
||||||
if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) ) {
|
Image *heightmap = luaL_checkudata( L, 1, "Image" );
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GenMeshHeightmap( Image heightmap, Vector3 size )" );
|
|
||||||
lua_pushinteger( L, -1 );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
size_t imageId = lua_tointeger( L, 1 );
|
|
||||||
Vector3 size = uluaGetVector3Index( L, 2 );
|
Vector3 size = uluaGetVector3Index( L, 2 );
|
||||||
|
|
||||||
if ( !validImage( imageId ) ) {
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Image *heightmap = state->images[ imageId ];
|
|
||||||
int i = newMesh();
|
int i = newMesh();
|
||||||
|
|
||||||
*state->meshes[i] = GenMeshHeightmap( *heightmap, size );
|
*state->meshes[i] = GenMeshHeightmap( *heightmap, size );
|
||||||
@@ -1661,14 +1640,15 @@ int lmodelsCreateMaterial( lua_State *L ) {
|
|||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
while ( lua_next( L, t4 ) != 0 ) {
|
while ( lua_next( L, t4 ) != 0 ) {
|
||||||
if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 && isValidTexture( L, lua_gettop( L ), true ) ) {
|
if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||||
state->materials[i]->maps[map].texture = uluaGetTexture( L, lua_gettop( L ) );
|
Texture *texture = luaL_checkudata( L, lua_gettop( L ), "Texture" );
|
||||||
|
state->materials[i]->maps[map].texture = *texture;
|
||||||
}
|
}
|
||||||
else if ( strcmp( "color", (char*)lua_tostring( L, -2 ) ) == 0 && lua_istable( L, -1 ) ) {
|
else if ( strcmp( "color", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||||
state->materials[i]->maps[map].color = uluaGetColor( L );
|
state->materials[i]->maps[map].color = uluaGetColorIndex( L, lua_gettop( L ) );
|
||||||
}
|
}
|
||||||
else if ( strcmp( "value", (char*)lua_tostring( L, -2 ) ) == 0 && lua_isnumber( L, -1 ) ) {
|
else if ( strcmp( "value", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||||
state->materials[i]->maps[map].value = lua_tonumber( L, -1 );
|
state->materials[i]->maps[map].value = luaL_checkinteger( L, -1 );
|
||||||
}
|
}
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
@@ -1697,7 +1677,8 @@ int lmodelsCreateMaterial( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( strcmp( "shader", (char*)lua_tostring( L, -2 ) ) == 0 && lua_isnumber( L, -1 ) ) {
|
else if ( strcmp( "shader", (char*)lua_tostring( L, -2 ) ) == 0 && lua_isnumber( L, -1 ) ) {
|
||||||
state->materials[i]->shader = *state->shaders[ lua_tointeger( L, -1 ) ];
|
Shader *shader = luaL_checkudata( L, lua_gettop( L ), "Shader" );
|
||||||
|
state->materials[i]->shader = *shader;
|
||||||
}
|
}
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
@@ -1735,27 +1716,18 @@ int lmodelsUnloadMaterial( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> success = RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )
|
> RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )
|
||||||
|
|
||||||
Set texture for a material map type ( MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS... )
|
Set texture for a material map type ( MATERIAL_MAP_ALBEDO, MATERIAL_MAP_METALNESS... )
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
*/
|
*/
|
||||||
int lmodelsSetMaterialTexture( lua_State *L ) {
|
int lmodelsSetMaterialTexture( lua_State *L ) {
|
||||||
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !isValidTexture( L, 3, true ) ) {
|
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMaterialTexture( Material material, int mapType, Texture2D texture )" );
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
size_t materialId = lua_tointeger( L, 1 );
|
size_t materialId = lua_tointeger( L, 1 );
|
||||||
int mapType = lua_tointeger( L, 2 );
|
int mapType = lua_tointeger( L, 2 );
|
||||||
Texture texture = uluaGetTexture( L, 3 );
|
Texture *texture = luaL_checkudata( L, 3, "Texture" );
|
||||||
|
|
||||||
SetMaterialTexture( state->materials[ materialId ], mapType, texture );
|
SetMaterialTexture( state->materials[ materialId ], mapType, *texture );
|
||||||
lua_pushboolean( L, true );
|
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1815,30 +1787,17 @@ int lmodelsSetMaterialValue( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> success = RL.SetMaterialShader( Material material, Shader shader )
|
> RL.SetMaterialShader( Material material, Shader shader )
|
||||||
|
|
||||||
Set shader for material
|
Set shader for material
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
*/
|
*/
|
||||||
int lmodelsSetMaterialShader( lua_State *L ) {
|
int lmodelsSetMaterialShader( lua_State *L ) {
|
||||||
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
|
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetMaterialShader( Material material, Shader shader )" );
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
size_t materialId = lua_tointeger( L, 1 );
|
size_t materialId = lua_tointeger( L, 1 );
|
||||||
size_t shaderId = lua_tointeger( L, 2 );
|
Shader *shader = luaL_checkudata( L, 2, "Shader" );
|
||||||
|
|
||||||
if ( !validMaterial( materialId || !validShader( shaderId ) ) ) {
|
state->materials[ materialId ]->shader = *shader;
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
state->materials[ materialId ]->shader = *state->shaders[ shaderId ];
|
|
||||||
lua_pushboolean( L, true );
|
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1892,32 +1851,32 @@ Get texture from material map type. Returns -1 if no texture.
|
|||||||
- Success return int
|
- Success return int
|
||||||
*/
|
*/
|
||||||
int lmodelsGetMaterialTexture( lua_State *L ) {
|
int lmodelsGetMaterialTexture( lua_State *L ) {
|
||||||
if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
|
// if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMaterialTexture( Material material, int mapType )" );
|
// TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetMaterialTexture( Material material, int mapType )" );
|
||||||
lua_pushboolean( L, false );
|
// lua_pushboolean( L, false );
|
||||||
return 1;
|
// return 1;
|
||||||
}
|
// }
|
||||||
size_t materialId = lua_tointeger( L, 1 );
|
// size_t materialId = lua_tointeger( L, 1 );
|
||||||
int mapType = lua_tointeger( L, 2 );
|
// int mapType = lua_tointeger( L, 2 );
|
||||||
|
|
||||||
if ( !validMaterial( materialId ) ) {
|
// if ( !validMaterial( materialId ) ) {
|
||||||
lua_pushboolean( L, false );
|
// lua_pushboolean( L, false );
|
||||||
return 1;
|
// return 1;
|
||||||
}
|
// }
|
||||||
/* Check what ReiLua texture has same openGL texture and return that. */
|
// /* Check what ReiLua texture has same openGL texture and return that. */
|
||||||
for ( int i = 0; i < state->textureCount; i++ ) {
|
// for ( int i = 0; i < state->textureCount; i++ ) {
|
||||||
if ( state->textures[i]->type == TEXTURE_TYPE_TEXTURE
|
// if ( state->textures[i]->type == TEXTURE_TYPE_TEXTURE
|
||||||
&& state->textures[i]->texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
|
// && state->textures[i]->texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
|
||||||
lua_pushinteger( L, i );
|
// lua_pushinteger( L, i );
|
||||||
return 1;
|
// return 1;
|
||||||
}
|
// }
|
||||||
else if ( state->textures[i]->type == TEXTURE_TYPE_RENDER_TEXTURE
|
// else if ( state->textures[i]->type == TEXTURE_TYPE_RENDER_TEXTURE
|
||||||
&& state->textures[i]->renderTexture.texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
|
// && state->textures[i]->renderTexture.texture.id == state->materials[ materialId ]->maps[ mapType ].texture.id ) {
|
||||||
lua_pushinteger( L, i );
|
// lua_pushinteger( L, i );
|
||||||
return 1;
|
// return 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
lua_pushinteger( L, -1 );
|
// lua_pushinteger( L, -1 );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -1980,7 +1939,7 @@ int lmodelsGetMaterialValue( lua_State *L ) {
|
|||||||
Get material shader. Returns -1 if no shader.
|
Get material shader. Returns -1 if no shader.
|
||||||
|
|
||||||
- Failure return false
|
- Failure return false
|
||||||
- Success return int
|
- Success return Shader
|
||||||
*/
|
*/
|
||||||
int lmodelsGetMaterialShader( lua_State *L ) {
|
int lmodelsGetMaterialShader( lua_State *L ) {
|
||||||
if ( !lua_isnumber( L, 1 ) ) {
|
if ( !lua_isnumber( L, 1 ) ) {
|
||||||
@@ -1994,14 +1953,17 @@ int lmodelsGetMaterialShader( lua_State *L ) {
|
|||||||
lua_pushboolean( L, false );
|
lua_pushboolean( L, false );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uluaPushShader( L, state->materials[ materialId ]->shader );
|
||||||
|
|
||||||
/* Look for shader that has same shader program id. */
|
/* Look for shader that has same shader program id. */
|
||||||
for ( int i = 0; i < state->shaderCount; i++ ) {
|
// for ( int i = 0; i < state->shaderCount; i++ ) {
|
||||||
if ( state->shaders[i]->id == state->materials[ materialId ]->shader.id ) {
|
// if ( state->shaders[i]->id == state->materials[ materialId ]->shader.id ) {
|
||||||
lua_pushinteger( L, i );
|
// lua_pushinteger( L, i );
|
||||||
return 1;
|
// return 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
lua_pushinteger( L, -1 );
|
// lua_pushinteger( L, -1 );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -2263,92 +2225,59 @@ int lmodelsSetModelMeshMaterial( lua_State *L ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> success = RL.DrawBillboard( Camera3D camera, Texture2D texture, Vector3 position, float size, Color tint )
|
> RL.DrawBillboard( Camera3D camera, Texture texture, Vector3 position, float size, Color tint )
|
||||||
|
|
||||||
Draw a billboard texture
|
Draw a billboard texture
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
*/
|
*/
|
||||||
int lmodelsDrawBillboard( lua_State *L ) {
|
int lmodelsDrawBillboard( lua_State *L ) {
|
||||||
if ( !isValidCamera3D( L, 1, true ) || !isValidTexture( L, 2, true ) || !lua_istable( L, 3 )
|
Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
|
||||||
|| !lua_isnumber( L, 4 ) || !lua_istable( L, 5 ) ) {
|
Texture *texture = luaL_checkudata( L, 2, "Texture" );
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawBillboard( Camera camera, Texture2D texture, Vector3 position, float size, Color tint )" );
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Camera3D camera = uluaGetCamera3D( L, 1 );
|
|
||||||
Texture texture = uluaGetTexture( L, 2 );
|
|
||||||
Vector3 position = uluaGetVector3Index( L, 3 );
|
Vector3 position = uluaGetVector3Index( L, 3 );
|
||||||
float size = lua_tonumber( L, 4 );
|
float size = luaL_checknumber( L, 4 );
|
||||||
Color tint = uluaGetColorIndex( L, 5 );
|
Color tint = uluaGetColorIndex( L, 5 );
|
||||||
|
|
||||||
DrawBillboard( camera, texture, position, size, tint );
|
DrawBillboard( *camera, *texture, position, size, tint );
|
||||||
lua_pushboolean( L, true );
|
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> success = RL.DrawBillboardRec( Camera3D camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint )
|
> RL.DrawBillboardRec( Camera3D camera, Texture texture, Rectangle source, Vector3 position, Vector2 size, Color tint )
|
||||||
|
|
||||||
Draw a billboard texture defined by source
|
Draw a billboard texture defined by source
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
*/
|
*/
|
||||||
int lmodelsDrawBillboardRec( lua_State *L ) {
|
int lmodelsDrawBillboardRec( lua_State *L ) {
|
||||||
if ( !isValidCamera3D( L, 1, true ) || !isValidTexture( L, 2, true ) || !lua_istable( L, 3 )
|
Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
|
||||||
|| !lua_istable( L, 4 ) || !lua_istable( L, 5 ) || !lua_istable( L, 6 ) ) {
|
Texture *texture = luaL_checkudata( L, 2, "Texture" );
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawBillboardRec( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint )" );
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Camera3D camera = uluaGetCamera3D( L, 1 );
|
|
||||||
Texture texture = uluaGetTexture( L, 2 );
|
|
||||||
Rectangle source = uluaGetRectangleIndex( L, 3 );
|
Rectangle source = uluaGetRectangleIndex( L, 3 );
|
||||||
Vector3 position = uluaGetVector3Index( L, 4 );
|
Vector3 position = uluaGetVector3Index( L, 4 );
|
||||||
Vector2 size = uluaGetVector2Index( L, 5 );
|
Vector2 size = uluaGetVector2Index( L, 5 );
|
||||||
Color tint = uluaGetColorIndex( L, 6 );
|
Color tint = uluaGetColorIndex( L, 6 );
|
||||||
|
|
||||||
// DrawBillboardRec( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, size, tint );
|
DrawBillboardRecNoRatio( *camera, *texture, source, position, size, tint );
|
||||||
DrawBillboardRecNoRatio( camera, texture, source, position, size, tint );
|
|
||||||
lua_pushboolean( L, true );
|
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> success = RL.DrawBillboardPro( Camera3D camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )
|
> RL.DrawBillboardPro( Camera3D camera, Texture texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )
|
||||||
|
|
||||||
Draw a billboard texture defined by source and rotation
|
Draw a billboard texture defined by source and rotation
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
*/
|
*/
|
||||||
int lmodelsDrawBillboardPro( lua_State *L ) {
|
int lmodelsDrawBillboardPro( lua_State *L ) {
|
||||||
if ( !isValidCamera3D( L, 1, true ) || !isValidTexture( L, 2, true ) || !lua_istable( L, 3 )
|
Camera3D *camera = luaL_checkudata( L, 1, "Camera3D" );
|
||||||
|| !lua_istable( L, 4 ) || !lua_istable( L, 5 ) || !lua_istable( L, 6 )
|
Texture *texture = luaL_checkudata( L, 2, "Texture" );
|
||||||
|| !lua_istable( L, 7 ) || !lua_isnumber( L, 8 ) || !lua_istable( L, 9 ) ) {
|
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawBillboardPro( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint )" );
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Camera3D camera = uluaGetCamera3D( L, 1 );
|
|
||||||
Texture texture = uluaGetTexture( L, 2 );
|
|
||||||
Rectangle source = uluaGetRectangleIndex( L, 3 );
|
Rectangle source = uluaGetRectangleIndex( L, 3 );
|
||||||
Vector3 position = uluaGetVector3Index( L, 4 );
|
Vector3 position = uluaGetVector3Index( L, 4 );
|
||||||
Vector3 up = uluaGetVector3Index( L, 5 );
|
Vector3 up = uluaGetVector3Index( L, 5 );
|
||||||
Vector2 size = uluaGetVector2Index( L, 6 );
|
Vector2 size = uluaGetVector2Index( L, 6 );
|
||||||
Vector2 origin = uluaGetVector2Index( L, 7 );
|
Vector2 origin = uluaGetVector2Index( L, 7 );
|
||||||
float rotation = lua_tonumber( L, 8 );
|
float rotation = luaL_checknumber( L, 8 );
|
||||||
Color tint = uluaGetColorIndex( L, 9 );
|
Color tint = uluaGetColorIndex( L, 9 );
|
||||||
|
|
||||||
// DrawBillboardPro( *state->camera3Ds[ cameraId ], *texturesGetSourceTexture( texId ), source, position, up, size, origin, rotation, tint );
|
DrawBillboardProNoRatio( *camera, *texture, source, position, up, size, origin, rotation, tint );
|
||||||
DrawBillboardProNoRatio( camera, texture, source, position, up, size, origin, rotation, tint );
|
|
||||||
lua_pushboolean( L, true );
|
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
17
src/shapes.c
17
src/shapes.c
@@ -9,28 +9,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
> success = RL.SetShapesTexture( Texture2D texture, Rectangle source )
|
> RL.SetShapesTexture( Texture texture, Rectangle source )
|
||||||
|
|
||||||
Set texture and rectangle to be used on shapes drawing
|
Set texture and rectangle to be used on shapes drawing
|
||||||
NOTE: It can be useful when using basic shapes and one single font,
|
NOTE: It can be useful when using basic shapes and one single font,
|
||||||
defining a font char white rectangle would allow drawing everything in a single draw call
|
defining a font char white rectangle would allow drawing everything in a single draw call
|
||||||
|
|
||||||
- Failure return false
|
|
||||||
- Success return true
|
|
||||||
*/
|
*/
|
||||||
int lshapesSetShapesTexture( lua_State *L ) {
|
int lshapesSetShapesTexture( lua_State *L ) {
|
||||||
if ( !isValidTexture( L, 1, true ) || !lua_isnumber( L, 2 ) ) {
|
Texture *texture = luaL_checkudata( L, 1, "Texture" );
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.SetShapesTexture( Texture2D texture, Rectangle source )" );
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Texture texture = uluaGetTexture( L, 1 );
|
|
||||||
Rectangle source = uluaGetRectangleIndex( L, 2 );
|
Rectangle source = uluaGetRectangleIndex( L, 2 );
|
||||||
|
|
||||||
SetShapesTexture( texture, source );
|
SetShapesTexture( *texture, source );
|
||||||
lua_pushboolean( L, true );
|
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
58
src/state.c
58
src/state.c
@@ -18,14 +18,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
|
|||||||
state->luaState = NULL;
|
state->luaState = NULL;
|
||||||
state->guiFont = 0;
|
state->guiFont = 0;
|
||||||
state->logLevelInvalid = LOG_ERROR;
|
state->logLevelInvalid = LOG_ERROR;
|
||||||
/* Images. */
|
|
||||||
state->imageAlloc = ALLOC_PAGE_SIZE;
|
|
||||||
state->imageCount = 0;
|
|
||||||
state->images = malloc( state->imageAlloc * sizeof( Image* ) );
|
|
||||||
/* Textures. */
|
|
||||||
state->textureAlloc = ALLOC_PAGE_SIZE;
|
|
||||||
state->textureCount = 0;
|
|
||||||
state->textures = malloc( state->textureAlloc * sizeof( ReiTexture* ) );
|
|
||||||
/* Fonts. */
|
/* Fonts. */
|
||||||
state->fontAlloc = ALLOC_PAGE_SIZE;
|
state->fontAlloc = ALLOC_PAGE_SIZE;
|
||||||
state->fontCount = 1;
|
state->fontCount = 1;
|
||||||
@@ -42,14 +34,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
|
|||||||
state->musicAlloc = ALLOC_PAGE_SIZE;
|
state->musicAlloc = ALLOC_PAGE_SIZE;
|
||||||
state->musicCount = 0;
|
state->musicCount = 0;
|
||||||
state->musics = malloc( state->musicAlloc * sizeof( Music* ) );
|
state->musics = malloc( state->musicAlloc * sizeof( Music* ) );
|
||||||
/* Camera2D's. */
|
|
||||||
state->camera2DAlloc = ALLOC_PAGE_SIZE;
|
|
||||||
state->camera2DCount = 0;
|
|
||||||
state->camera2Ds = malloc( state->camera2DAlloc * sizeof( Camera2D* ) );
|
|
||||||
/* Camera3D's. */
|
|
||||||
state->camera3DAlloc = ALLOC_PAGE_SIZE;
|
|
||||||
state->camera3DCount = 0;
|
|
||||||
state->camera3Ds = malloc( state->camera3DAlloc * sizeof( Camera3D* ) );
|
|
||||||
/* Meshes. */
|
/* Meshes. */
|
||||||
state->meshAlloc = ALLOC_PAGE_SIZE;
|
state->meshAlloc = ALLOC_PAGE_SIZE;
|
||||||
state->meshCount = 0;
|
state->meshCount = 0;
|
||||||
@@ -66,26 +50,17 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
|
|||||||
state->animationAlloc = ALLOC_PAGE_SIZE;
|
state->animationAlloc = ALLOC_PAGE_SIZE;
|
||||||
state->animationCount = 0;
|
state->animationCount = 0;
|
||||||
state->animations = malloc( state->animationAlloc * sizeof( ModelAnimations* ) );
|
state->animations = malloc( state->animationAlloc * sizeof( ModelAnimations* ) );
|
||||||
/* Shaders. */
|
|
||||||
state->shaderAlloc = ALLOC_PAGE_SIZE;
|
|
||||||
state->shaderCount = 0;
|
|
||||||
state->shaders = malloc( state->shaderAlloc * sizeof( Shader* ) );
|
|
||||||
/* Lights. */
|
/* Lights. */
|
||||||
state->lightAlloc = ALLOC_PAGE_SIZE;
|
state->lightAlloc = ALLOC_PAGE_SIZE;
|
||||||
state->lightCount = 0;
|
state->lightCount = 0;
|
||||||
state->lights = malloc( state->lightAlloc * sizeof( Light* ) );
|
state->lights = malloc( state->lightAlloc * sizeof( Light* ) );
|
||||||
|
|
||||||
for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) {
|
for ( int i = 0; i < ALLOC_PAGE_SIZE; i++ ) {
|
||||||
state->images[i] = NULL;
|
|
||||||
state->textures[i] = NULL;
|
|
||||||
state->waves[i] = NULL;
|
state->waves[i] = NULL;
|
||||||
state->sounds[i] = NULL;
|
state->sounds[i] = NULL;
|
||||||
state->camera2Ds[i] = NULL;
|
|
||||||
state->camera3Ds[i] = NULL;
|
|
||||||
state->meshes[i] = NULL;
|
state->meshes[i] = NULL;
|
||||||
state->models[i] = NULL;
|
state->models[i] = NULL;
|
||||||
state->animations[i] = NULL;
|
state->animations[i] = NULL;
|
||||||
state->shaders[i] = NULL;
|
|
||||||
state->lights[i] = NULL;
|
state->lights[i] = NULL;
|
||||||
|
|
||||||
/* The ones we want to save the first. */
|
/* The ones we want to save the first. */
|
||||||
@@ -119,18 +94,6 @@ void stateInitInterpret( int argn, const char **argc ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stateFree() {
|
void stateFree() {
|
||||||
for ( int i = 0; i < state->imageCount; ++i ) {
|
|
||||||
if ( state->images[i] != NULL ) {
|
|
||||||
UnloadImage( *state->images[i] );
|
|
||||||
free( state->images[i] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for ( int i = 0; i < state->textureCount; ++i ) {
|
|
||||||
if ( state->textures[i] != NULL ) {
|
|
||||||
texturesFreeTexture(i);
|
|
||||||
free( state->textures[i] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for ( int i = 0; i < state->fontCount; ++i ) {
|
for ( int i = 0; i < state->fontCount; ++i ) {
|
||||||
if ( state->fonts[i] != NULL ) {
|
if ( state->fonts[i] != NULL ) {
|
||||||
UnloadFont( *state->fonts[i] );
|
UnloadFont( *state->fonts[i] );
|
||||||
@@ -155,16 +118,6 @@ void stateFree() {
|
|||||||
free( state->musics[i] );
|
free( state->musics[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ( int i = 0; i < state->camera2DCount; ++i ) {
|
|
||||||
if ( state->camera2Ds[i] != NULL ) {
|
|
||||||
free( state->camera2Ds[i] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for ( int i = 0; i < state->camera3DCount; ++i ) {
|
|
||||||
if ( state->camera3Ds[i] != NULL ) {
|
|
||||||
free( state->camera3Ds[i] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for ( int i = 0; i < state->modelCount; ++i ) {
|
for ( int i = 0; i < state->modelCount; ++i ) {
|
||||||
if ( state->models[i] != NULL ) {
|
if ( state->models[i] != NULL ) {
|
||||||
//TODO Test if UnloadModel causes segfaults on exit.
|
//TODO Test if UnloadModel causes segfaults on exit.
|
||||||
@@ -194,12 +147,6 @@ void stateFree() {
|
|||||||
free( state->animations[i] );
|
free( state->animations[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ( int i = 0; i < state->shaderCount; ++i ) {
|
|
||||||
if ( state->shaders[i] != NULL ) {
|
|
||||||
UnloadShader( *state->shaders[i] );
|
|
||||||
free( state->shaders[i] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !defined( PLATFORM_RPI ) || !defined( PLATFORM_DRM )
|
#if !defined( PLATFORM_RPI ) || !defined( PLATFORM_DRM )
|
||||||
for ( int i = 0; i < state->lightCount; ++i ) {
|
for ( int i = 0; i < state->lightCount; ++i ) {
|
||||||
@@ -218,19 +165,14 @@ void stateFree() {
|
|||||||
if ( state->hasWindow ) {
|
if ( state->hasWindow ) {
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
}
|
}
|
||||||
free( state->images );
|
|
||||||
free( state->textures );
|
|
||||||
free( state->fonts );
|
free( state->fonts );
|
||||||
free( state->waves );
|
free( state->waves );
|
||||||
free( state->sounds );
|
free( state->sounds );
|
||||||
free( state->musics );
|
free( state->musics );
|
||||||
free( state->camera2Ds );
|
|
||||||
free( state->camera3Ds );
|
|
||||||
free( state->meshes );
|
free( state->meshes );
|
||||||
free( state->materials );
|
free( state->materials );
|
||||||
free( state->models );
|
free( state->models );
|
||||||
free( state->animations );
|
free( state->animations );
|
||||||
free( state->shaders );
|
|
||||||
free( state->lights );
|
free( state->lights );
|
||||||
free( state->exePath );
|
free( state->exePath );
|
||||||
free( state );
|
free( state );
|
||||||
|
|||||||
14
src/text.c
14
src/text.c
@@ -114,22 +114,12 @@ Load font from Image ( XNA style )
|
|||||||
- Success return int
|
- Success return int
|
||||||
*/
|
*/
|
||||||
int ltextLoadFontFromImage( lua_State *L ) {
|
int ltextLoadFontFromImage( lua_State *L ) {
|
||||||
if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) ) {
|
Image *image = luaL_checkudata( L, 1, "Image" );
|
||||||
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadFontFromImage( Image image, Color key, int firstChar )" );
|
|
||||||
lua_pushinteger( L, -1 );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
size_t imageId = lua_tointeger( L, 1 );
|
|
||||||
Color key = uluaGetColorIndex( L, 2 );
|
Color key = uluaGetColorIndex( L, 2 );
|
||||||
int firstChar = lua_tointeger( L, 3 );
|
int firstChar = lua_tointeger( L, 3 );
|
||||||
|
|
||||||
if ( !validImage( imageId ) ) {
|
|
||||||
lua_pushboolean( L, false );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = newFont();
|
int i = newFont();
|
||||||
*state->fonts[i] = LoadFontFromImage( *state->images[ imageId ], key, firstChar );
|
*state->fonts[i] = LoadFontFromImage( *image, key, firstChar );
|
||||||
lua_pushinteger( L, i );
|
lua_pushinteger( L, i );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
1790
src/textures.c
1790
src/textures.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user