diff options
| -rw-r--r-- | API.md | 134 | ||||
| -rw-r--r-- | examples/heightmap/main.lua | 21 | ||||
| -rw-r--r-- | include/lua_core.h | 2 | ||||
| -rw-r--r-- | include/textures.h | 10 | ||||
| -rw-r--r-- | src/lua_core.c | 85 | ||||
| -rw-r--r-- | src/textures.c | 228 |
6 files changed, 456 insertions, 24 deletions
@@ -301,6 +301,50 @@ GESTURE_PINCH_IN GESTURE_PINCH_OUT +## Globals - PixelFormats + +PIXELFORMAT_UNCOMPRESSED_GRAYSCALE + +PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA + +PIXELFORMAT_UNCOMPRESSED_R5G6B5 + +PIXELFORMAT_UNCOMPRESSED_R8G8B8 + +PIXELFORMAT_UNCOMPRESSED_R5G5B5A1 + +PIXELFORMAT_UNCOMPRESSED_R4G4B4A4 + +PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 + +PIXELFORMAT_UNCOMPRESSED_R32 + +PIXELFORMAT_UNCOMPRESSED_R32G32B32 + +PIXELFORMAT_UNCOMPRESSED_R32G32B32A32 + +PIXELFORMAT_COMPRESSED_DXT1_RGB + +PIXELFORMAT_COMPRESSED_DXT1_RGBA + +PIXELFORMAT_COMPRESSED_DXT3_RGBA + +PIXELFORMAT_COMPRESSED_DXT5_RGBA + +PIXELFORMAT_COMPRESSED_ETC1_RGB + +PIXELFORMAT_COMPRESSED_ETC2_RGB + +PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA + +PIXELFORMAT_COMPRESSED_PVRT_RGB + +PIXELFORMAT_COMPRESSED_PVRT_RGBA + +PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA + +PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA + ## Globals - Colors WHITE @@ -1813,6 +1857,51 @@ Get texture size --- +> color = RL_Fade( Color color, float alpha ) + +Returns color with alpha applied, alpha goes from 0.0f to 1.0f + +- Failure return false +- Success return Color + +--- + +> value = RL_ColorToInt( Color color ) + +Returns hexadecimal value for a Color + +- Failure return false +- Success return int + +--- + +> color = RL_ColorNormalize( Color color ) + +Returns Color normalized as float [0..1] + +- Failure return false +- Success return Vector4 + +--- + +> color = RL_ColorFromNormalized( Vector4 normalized ) + +Color from normalized values [0..1] + +- Failure return false +- Success return Color + +--- + +> HSV = RL_ColorToHSV( Color color ) + +Returns HSV values for a Color, hue [0..360], saturation/value [0..1] + +- Failure return false +- Success return Vector3 + +--- + > color = RL_ColorFromHSV( float hue, float saturation, float value ) Returns a Color from HSV values, hue [0..360], saturation/value [0..1] @@ -1822,6 +1911,51 @@ Returns a Color from HSV values, hue [0..360], saturation/value [0..1] --- +> color = RL_ColorAlpha( Color color, float alpha ) + +Returns color with alpha applied, alpha goes from 0.0f to 1.0f + +- Failure return false +- Success return Color + +--- + +> color = RL_ColorAlphaBlend( Color dst, Color src, Color tint ) + +Returns src alpha-blended into dst color with tint + +- Failure return false +- Success return Color + +--- + +> Color = RL_GetColor( unsigned int hexValue ) + +Get Color structure from hexadecimal value + +- Failure return false +- Success return Color + +--- + +> Color = RL_GetPixelColor( Texture2D texture, Vector2 position ) + +Get pixel color from source texture + +- Failure return false +- Success return Color + +--- + +> size = RL_GetPixelDataSize( int width, int height, int format ) + +Get pixel data size in bytes for certain format + +- Failure return false +- Success return int + +--- + ## Text - Loading --- diff --git a/examples/heightmap/main.lua b/examples/heightmap/main.lua index c2d184e..ecc6993 100644 --- a/examples/heightmap/main.lua +++ b/examples/heightmap/main.lua @@ -70,27 +70,6 @@ function init() matrix = RL_MatrixMultiply( RL_MatrixIdentity(), RL_MatrixTranslate( { -4, 0, -4 } ) ) end -function process( delta ) - -- print( "RL_GetTouchPointCount()", RL_GetTouchPointCount() ) - -- print( "RL_GetGestureDetected()", RL_GetGestureDetected() ) - -- local gesture = RL_GetGestureDetected() - - -- if gesture then - -- local dragVec = RL_GetGestureDragVector() - -- local pinchVec = RL_GetGesturePinchVector() - -- -- print( "gesture "..gesture, "dragVec "..dragVec[1]..", "..dragVec[2] ) - -- print( "gesture "..gesture, "dragVec "..pinchVec[1]..", "..pinchVec[2] ) - -- end - - -- local vec = RL_GetGestureDragVector() - - -- print( vec[1]..", "..vec[2] ) - - -- if RL_IsGestureDetected() then - -- print( RL_GetGestureDetected() ) - -- end -end - function draw() RL_ClearBackground( { 100, 150, 100 } ) RL_UpdateCamera3D( camera ) diff --git a/include/lua_core.h b/include/lua_core.h index 66ee22a..694b94d 100644 --- a/include/lua_core.h +++ b/include/lua_core.h @@ -10,6 +10,7 @@ void luaRegister(); Color uluaGetColor( lua_State *L ); Vector2 uluaGetVector2( lua_State *L ); Vector3 uluaGetVector3( lua_State *L ); +Vector4 uluaGetVector4( lua_State *L ); Rectangle uluaGetRectangle( lua_State *L ); Quaternion uluaGetQuaternion( lua_State *L ); Matrix uluaGetMatrix( lua_State *L ); @@ -20,6 +21,7 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L ); void uluaPushColor( lua_State *L, Color color ); void uluaPushVector2( lua_State *L, Vector2 vector ); void uluaPushVector3( lua_State *L, Vector3 vector ); +void uluaPushVector4( lua_State *L, Vector4 vector ); void uluaPushRectangle( lua_State *L, Rectangle rect ); void uluaPushMatrix( lua_State *L, Matrix matrix ); void uluaPushRayCollision( lua_State *L, RayCollision rayCol ); diff --git a/include/textures.h b/include/textures.h index c759904..fdca59e 100644 --- a/include/textures.h +++ b/include/textures.h @@ -43,4 +43,14 @@ int ltexturesSetTextureFilter( lua_State *L ); int ltexturesSetTextureWrap( lua_State *L ); int ltexturesGetTextureSize( lua_State *L ); /* Color/pixel */ +int ltexturesFade( lua_State *L ); +int ltexturesColorToInt( lua_State *L ); +int ltexturesColorNormalize( lua_State *L ); +int ltexturesColorFromNormalized( lua_State *L ); +int ltexturesColorToHSV( lua_State *L ); int ltexturesColorFromHSV( lua_State *L ); +int ltexturesColorAlpha( lua_State *L ); +int ltexturesColorAlphaBlend( lua_State *L ); +int ltexturesGetColor( lua_State *L ); +int ltexturesGetPixelColor( lua_State *L ); +int ltexturesGetPixelDataSize( lua_State *L ); diff --git a/src/lua_core.c b/src/lua_core.c index d7204f5..55e0fda 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -168,6 +168,28 @@ void defineGlobals() { assignGlobalInt( GESTURE_SWIPE_DOWN, "GESTURE_SWIPE_DOWN" ); assignGlobalInt( GESTURE_PINCH_IN, "GESTURE_PINCH_IN" ); assignGlobalInt( GESTURE_PINCH_OUT, "GESTURE_PINCH_OUT" ); + /* PixelFormats */ + assignGlobalInt( PIXELFORMAT_UNCOMPRESSED_GRAYSCALE, "PIXELFORMAT_UNCOMPRESSED_GRAYSCALE" ); + assignGlobalInt( PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA, "PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA" ); + assignGlobalInt( PIXELFORMAT_UNCOMPRESSED_R5G6B5, "PIXELFORMAT_UNCOMPRESSED_R5G6B5" ); + assignGlobalInt( PIXELFORMAT_UNCOMPRESSED_R8G8B8, "PIXELFORMAT_UNCOMPRESSED_R8G8B8" ); + assignGlobalInt( PIXELFORMAT_UNCOMPRESSED_R5G5B5A1, "PIXELFORMAT_UNCOMPRESSED_R5G5B5A1" ); + assignGlobalInt( PIXELFORMAT_UNCOMPRESSED_R4G4B4A4, "PIXELFORMAT_UNCOMPRESSED_R4G4B4A4" ); + assignGlobalInt( PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, "PIXELFORMAT_UNCOMPRESSED_R8G8B8A8" ); + assignGlobalInt( PIXELFORMAT_UNCOMPRESSED_R32, "PIXELFORMAT_UNCOMPRESSED_R32" ); + assignGlobalInt( PIXELFORMAT_UNCOMPRESSED_R32G32B32, "PIXELFORMAT_UNCOMPRESSED_R32G32B32" ); + assignGlobalInt( PIXELFORMAT_UNCOMPRESSED_R32G32B32A32, "PIXELFORMAT_UNCOMPRESSED_R32G32B32A32" ); + assignGlobalInt( PIXELFORMAT_COMPRESSED_DXT1_RGB, "PIXELFORMAT_COMPRESSED_DXT1_RGB" ); + assignGlobalInt( PIXELFORMAT_COMPRESSED_DXT1_RGBA, "PIXELFORMAT_COMPRESSED_DXT1_RGBA" ); + assignGlobalInt( PIXELFORMAT_COMPRESSED_DXT3_RGBA, "PIXELFORMAT_COMPRESSED_DXT3_RGBA" ); + assignGlobalInt( PIXELFORMAT_COMPRESSED_DXT5_RGBA, "PIXELFORMAT_COMPRESSED_DXT5_RGBA" ); + assignGlobalInt( PIXELFORMAT_COMPRESSED_ETC1_RGB, "PIXELFORMAT_COMPRESSED_ETC1_RGB" ); + assignGlobalInt( PIXELFORMAT_COMPRESSED_ETC2_RGB, "PIXELFORMAT_COMPRESSED_ETC2_RGB" ); + assignGlobalInt( PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA, "PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA" ); + assignGlobalInt( PIXELFORMAT_COMPRESSED_PVRT_RGB, "PIXELFORMAT_COMPRESSED_PVRT_RGB" ); + assignGlobalInt( PIXELFORMAT_COMPRESSED_PVRT_RGBA, "PIXELFORMAT_COMPRESSED_PVRT_RGBA" ); + assignGlobalInt( PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA, "PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA" ); + assignGlobalInt( PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA, "PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA" ); /* Colors */ assignGlobalColor( WHITE, "WHITE" ); assignGlobalColor( BLACK, "BLACK" ); @@ -488,8 +510,18 @@ void luaRegister() { lua_register( L, "RL_SetTextureFilter", ltexturesSetTextureFilter ); lua_register( L, "RL_SetTextureWrap", ltexturesSetTextureWrap ); lua_register( L, "RL_GetTextureSize", ltexturesGetTextureSize ); - + /* Color/pixel */ + lua_register( L, "RL_Fade", ltexturesFade ); + lua_register( L, "RL_ColorToInt", ltexturesColorToInt ); + lua_register( L, "RL_ColorNormalize", ltexturesColorNormalize ); + lua_register( L, "RL_ColorFromNormalized", ltexturesColorFromNormalized ); + lua_register( L, "RL_ColorToHSV", ltexturesColorToHSV ); lua_register( L, "RL_ColorFromHSV", ltexturesColorFromHSV ); + lua_register( L, "RL_ColorAlpha", ltexturesColorAlpha ); + lua_register( L, "RL_ColorAlphaBlend", ltexturesColorAlphaBlend ); + lua_register( L, "RL_GetColor", ltexturesGetColor ); + lua_register( L, "RL_GetPixelColor", ltexturesGetPixelColor ); + lua_register( L, "RL_GetPixelDataSize", ltexturesGetPixelDataSize ); /* Models. */ /* Basic. */ @@ -700,7 +732,7 @@ Vector2 uluaGetVector2( lua_State *L ) { Vector2 vector = { 0.0f, 0.0f }; if ( !lua_istable( L, -1 ) ) { - TraceLog( LOG_WARNING, "%s", "Error. Wrong vector value. Returning { 0, 0 }" ); + TraceLog( LOG_WARNING, "%s", "Error. Wrong vector2 value. Returning { 0, 0 }" ); return vector; } int t = lua_gettop( L ), i = 0; @@ -729,7 +761,39 @@ Vector3 uluaGetVector3( lua_State *L ) { Vector3 vector = { 0.0f, 0.0f, 0.0f }; if ( !lua_istable( L, -1 ) ) { - TraceLog( LOG_WARNING, "%s", "Error. Wrong vector value. Returning { 0, 0, 0 }" ); + TraceLog( LOG_WARNING, "%s", "Error. Wrong vector3 value. Returning { 0, 0, 0 }" ); + return vector; + } + int t = lua_gettop( L ), i = 0; + lua_pushnil( L ); + + while ( lua_next( L, t ) != 0 ) { + if ( lua_isnumber( L, -1 ) ) { + switch ( i ) { + case 0: + vector.x = lua_tonumber( L, -1 ); + break; + case 1: + vector.y = lua_tonumber( L, -1 ); + break; + case 2: + vector.z = lua_tonumber( L, -1 ); + break; + default: + break; + } + } + i++; + lua_pop( L, 1 ); + } + return vector; +} + +Vector4 uluaGetVector4( lua_State *L ) { + Vector4 vector = { 0.0f, 0.0f, 0.0f, 0.0f }; + + if ( !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Error. Wrong vector4 value. Returning { 0, 0, 0, 0 }" ); return vector; } int t = lua_gettop( L ), i = 0; @@ -747,6 +811,9 @@ Vector3 uluaGetVector3( lua_State *L ) { case 2: vector.z = lua_tonumber( L, -1 ); break; + case 3: + vector.w = lua_tonumber( L, -1 ); + break; default: break; } @@ -992,6 +1059,18 @@ void uluaPushVector3( lua_State *L, Vector3 vector ) { lua_rawseti( L, -2, 3 ); } +void uluaPushVector4( lua_State *L, Vector4 vector ) { + lua_createtable( L, 4, 0 ); + lua_pushnumber( L, vector.x ); + lua_rawseti( L, -2, 1 ); + lua_pushnumber( L, vector.y ); + lua_rawseti( L, -2, 2 ); + lua_pushnumber( L, vector.z ); + lua_rawseti( L, -2, 3 ); + lua_pushnumber( L, vector.w ); + lua_rawseti( L, -2, 4 ); +} + void uluaPushRectangle( lua_State *L, Rectangle rect ) { lua_createtable( L, 4, 0 ); lua_pushnumber( L, rect.x ); diff --git a/src/textures.c b/src/textures.c index f28bd0f..72d6c28 100644 --- a/src/textures.c +++ b/src/textures.c @@ -1061,6 +1061,113 @@ int ltexturesGetTextureSize( lua_State *L ) { */ /* +> color = RL_Fade( Color color, float alpha ) + +Returns color with alpha applied, alpha goes from 0.0f to 1.0f + +- Failure return false +- Success return Color +*/ +int ltexturesFade( lua_State *L ) { + if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Fade( Color color, float alpha )" ); + lua_pushboolean( L, false ); + return 1; + } + float alpha = lua_tonumber( L, -1 ); + lua_pop( L, 1 ); + Color color = uluaGetColor( L ); + + uluaPushColor( L, Fade( color, alpha ) ); + + return 1; +} + +/* +> value = RL_ColorToInt( Color color ) + +Returns hexadecimal value for a Color + +- Failure return false +- Success return int +*/ +int ltexturesColorToInt( lua_State *L ) { + if ( !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorToInt( Color color )" ); + lua_pushboolean( L, false ); + return 1; + } + Color color = uluaGetColor( L ); + + lua_pushinteger( L, ColorToInt( color ) ); + + return 1; +} + +/* +> color = RL_ColorNormalize( Color color ) + +Returns Color normalized as float [0..1] + +- Failure return false +- Success return Vector4 +*/ +int ltexturesColorNormalize( lua_State *L ) { + if ( !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorNormalize( Color color )" ); + lua_pushboolean( L, false ); + return 1; + } + Color color = uluaGetColor( L ); + + uluaPushVector4( L, ColorNormalize( color ) ); + + return 1; +} + +/* +> color = RL_ColorFromNormalized( Vector4 normalized ) + +Color from normalized values [0..1] + +- Failure return false +- Success return Color +*/ +int ltexturesColorFromNormalized( lua_State *L ) { + if ( !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorFromNormalized( Vector4 normalized )" ); + lua_pushboolean( L, false ); + return 1; + } + Vector4 normalized = uluaGetVector4( L ); + + uluaPushColor( L, ColorFromNormalized( normalized ) ); + + return 1; +} + +/* +> HSV = RL_ColorToHSV( Color color ) + +Returns HSV values for a Color, hue [0..360], saturation/value [0..1] + +- Failure return false +- Success return Vector3 +*/ +int ltexturesColorToHSV( lua_State *L ) { + if ( !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorToHSV( Color color )" ); + lua_pushboolean( L, false ); + return 1; + } + Color color = uluaGetColor( L ); + + uluaPushVector3( L, ColorToHSV( color ) ); + + return 1; +} + +/* > color = RL_ColorFromHSV( float hue, float saturation, float value ) Returns a Color from HSV values, hue [0..360], saturation/value [0..1] @@ -1078,3 +1185,124 @@ int ltexturesColorFromHSV( lua_State *L ) { return 1; } + +/* +> color = RL_ColorAlpha( Color color, float alpha ) + +Returns color with alpha applied, alpha goes from 0.0f to 1.0f + +- Failure return false +- Success return Color +*/ +int ltexturesColorAlpha( lua_State *L ) { + if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorAlpha( Color color, float alpha )" ); + lua_pushboolean( L, false ); + return 1; + } + float alpha = lua_tonumber( L, -1 ); + lua_pop( L, 1 ); + Color color = uluaGetColor( L ); + + uluaPushColor( L, ColorAlpha( color, alpha ) ); + + return 1; +} + +/* +> color = RL_ColorAlphaBlend( Color dst, Color src, Color tint ) + +Returns src alpha-blended into dst color with tint + +- Failure return false +- Success return Color +*/ +int ltexturesColorAlphaBlend( lua_State *L ) { + if ( !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorAlphaBlend( Color dst, Color src, Color tint )" ); + lua_pushboolean( L, false ); + return 1; + } + Color tint = uluaGetColor( L ); + lua_pop( L, 1 ); + Color src = uluaGetColor( L ); + lua_pop( L, 1 ); + Color dst = uluaGetColor( L ); + + uluaPushColor( L, ColorAlphaBlend( dst, src, tint ) ); + + return 1; +} + +/* +> Color = RL_GetColor( unsigned int hexValue ) + +Get Color structure from hexadecimal value + +- Failure return false +- Success return Color +*/ +int ltexturesGetColor( lua_State *L ) { + if ( !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetColor( unsigned int hexValue )" ); + lua_pushboolean( L, false ); + return 1; + } + uluaPushColor( L, GetColor( (unsigned int)lua_tointeger( L, -1 ) ) ); + + return 1; +} + +/* +> Color = RL_GetPixelColor( Texture2D texture, Vector2 position ) + +Get pixel color from source texture + +- Failure return false +- Success return Color +*/ +int ltexturesGetPixelColor( lua_State *L ) { + if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetPixelColor( Texture2D texture, Vector2 position )" ); + lua_pushboolean( L, false ); + return 1; + } + Vector2 pos = uluaGetVector2( L ); + lua_pop( L, 1 ); + size_t texId = lua_tointeger( L, -2 ); + + if ( !validTexture( texId ) ) { + lua_pushboolean( L, false ); + return 1; + } + Texture2D *texture = texturesGetSourceTexture( texId ); + Image srcImage = LoadImageFromTexture( *texture ); + + uluaPushColor( L, GetImageColor( srcImage, pos.x, pos.y ) ); + UnloadImage( srcImage ); + + return 1; +} + + + +Color GetPixelColor(void *srcPtr, int format); + +/* +> size = RL_GetPixelDataSize( int width, int height, int format ) + +Get pixel data size in bytes for certain format + +- Failure return false +- Success return int +*/ +int ltexturesGetPixelDataSize( lua_State *L ) { + if ( !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetPixelDataSize( int width, int height, int format )" ); + lua_pushboolean( L, false ); + return 1; + } + lua_pushinteger( L, GetPixelDataSize( lua_tointeger( L, -3 ), lua_tointeger( L, -2 ), lua_tointeger( L, -1 ) ) ); + + return 1; +} |
