LoadTextureFromData and LoadRenderTextureFromData. Documentation updates.

This commit is contained in:
jussi
2023-10-29 18:36:23 +02:00
parent 0df40e2ac0
commit fcd2d2d8b5
11 changed files with 513 additions and 377 deletions

547
API.md
View File

@@ -45,6 +45,284 @@ This function will be called on program close. Cleanup could be done here.
Arguments are stored in 'RL.arg' array.
## Types
Raylib structs in Lua
---
> Vector2 = { 1.0, 1.0 } or { x = 1.0, y = 1.0 }
Vector2, 2 components
---
> Vector3 = { 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0 }
Vector3, 3 components
---
> Vector4 = { 1.0, 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0, w = 1.0 }
Vector4, 4 components
---
> Quaternion = { 1.0, 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0, w = 1.0 }
Quaternion, 4 components (Vector4 alias)
---
> Matrix = { { 1.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0 } }
Matrix, 4x4 components, column major, OpenGL style, right-handed. Identity matrix example
---
> Color = { 255, 255, 255, 255 } or { r = 255, g = 255, b = 255, a = 255 }
Color, 4 components, R8G8B8A8 (32bit)
---
> Rectangle = { 0.0, 0.0, 1.0, 1.0 } or { x = 0.0, y = 0.0, width = 1.0, height = 1.0 }
Rectangle, 4 components
---
> Image = Userdata
Image, pixel data stored in CPU memory (RAM)
---
> Texture = Userdata
Texture, tex data stored in GPU memory (VRAM)
```
textureData = {
id = unsigned int, --OpenGL texture id
width = int, --Texture base width
height = int, --Texture base height
mipmaps = int, --Mipmap levels, 1 by default
format = int --Data format (PixelFormat type)
}
```
---
> RenderTexture = Userdata
RenderTexture, fbo for texture rendering
```
renderTextureData = {
id = unsigned int, --OpenGL texture id
texture = Texture, --Texture base width
depth = Texture, --Texture base height
}
```
---
> Font = Userdata
Font, font texture and GlyphInfo array data
---
> Camera2D = Userdata
Camera2D, defines position/orientation in 2d space
---
> Camera3D = Userdata
Camera, defines position/orientation in 3d space
---
> Mesh = Userdata
Mesh, vertex data and vao/vbo
```
meshData = {
vertices = Vector3{}, --Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
texcoords = Vector2{}, --Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
texcoords2 = Vector2{}, --Vertex texture second coordinates (UV - 2 components per vertex) (shader-location = 5)
normals = Vector3{}, --Vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
tangents = Vector4{}, --Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4)
colors = Color{}, --Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
indices = int{} --Vertex indices (in case vertex data comes indexed)
}
```
---
> Material = Userdata
Material, includes shader and maps
```
materialData = {
shader = Shader,
maps = { --Material maps array (MAX_MATERIAL_MAPS)
{
MATERIAL_MAP_*, --Example MATERIAL_MAP_ALBEDO
{
texture = Texture, --Material map texture
color = Color, --Material map color
value = float, --Material map value
},
},
...
},
params = { float, float, float, float } --Material generic parameters (if required)
}
```
---
> Model = Userdata
Model, meshes, materials and animation data
---
> Ray = { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 } } or { position = { 0.0, 0.0, 0.0 }, direction = { 1.0, 0.0, 0.0 } }
Ray, ray for raycasting
---
> RayCollision = { hit = true, distance = 1.0, point = { 0.0, 0.0, 0.0 }, normal = { 0.0, 0.0, 1.0 } }
RayCollision, ray hit information
---
> BoundingBox = { { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 } } or { min = { 0.0, 0.0, 0.0 }, max = { 1.0, 1.0, 1.0 } }
BoundingBox
---
> Wave = Userdata
Wave, audio wave data
---
> Sound = Userdata
Sound
---
> Music = Userdata
Music, audio stream, anything longer than ~10 seconds should be streamed
---
> NPatchInfo = { { 0, 0, 24, 24 }, 8, 8, 8, 8, NPATCH_NINE_PATCH } or { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }
NPatchInfo, n-patch layout info
---
> ModelAnimations = Userdata
ModelAnimation
---
> Buffer = Buffer userdata
Data buffer for C primitive types. Type should be one of the Buffer types.
---
## Events
Content of event table received by RL.event.
### Window events
---
> { type: RL.EVENT_WINDOW_SIZE, int width, int height }
WindowSize Callback, runs when window is resized.
---
> { type RL.EVENT_WINDOW_MAXIMIZE, int maximized }
Window Maximize Callback, runs when window is maximized.
---
> { type RL.EVENT_WINDOW_ICONYFY, int iconified }
WindowIconify Callback, runs when window is minimized/restored.
---
> { type RL.EVENT_WINDOW_FOCUS, int focused }
WindowFocus Callback, runs when window get/lose focus.
---
> { type RL.EVENT_WINDOW_DROP, int count, string{} paths }
Window Drop Callback, runs when drop files into window.
---
### Input events
---
> { type: RL.EVENT_KEY, int key, int scancode, int action, int mods }
Keyboard Callback, runs on key pressed.
---
> { type RL.EVENT_CHAR, int key }
Char Key Callback, runs on key pressed (get char value).
---
> { type RL.EVENT_MOUSE_BUTTON, int button, int action, int mods }
Mouse Button Callback, runs on mouse button pressed.
---
> { type RL.EVENT_MOUSE_CURSOR_POS, number x, number y }
Cursor Position Callback, runs on mouse move.
---
> { type RL.EVENT_MOUSE_SCROLL, number xoffset, number yoffset }
Srolling Callback, runs on mouse wheel.
---
> { type RL.EVENT_CURSOR_ENTER, int enter }
Cursor Enter Callback, cursor enters client area.
---
## Globals - ConfigFlags
FLAG_VSYNC_HINT = 64
@@ -1208,257 +1486,6 @@ EVENT_MOUSE_SCROLL = 9
EVENT_CURSOR_ENTER = 10
## Types
Raylib structs in Lua
---
> Vector2 = { 1.0, 1.0 } or { x = 1.0, y = 1.0 }
Vector2 type
---
> Vector3 = { 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0 }
Vector3 type
---
> Vector4 = { 1.0, 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0, w = 1.0 }
Vector4 type
---
> Quaternion = { 1.0, 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0, w = 1.0 }
Quaternion type
---
> Matrix = { { 1.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0 } }
OpenGL style 4x4. Identity matrix example
---
> Color = { 255, 255, 255, 255 } or { r = 255, g = 255, b = 255, a = 255 }
{ r, g, b ,a }. Color type, RGBA (32bit)
---
> Rectangle = { 0.0, 0.0, 1.0, 1.0 } or { x = 0.0, y = 0.0, width = 1.0, height = 1.0 }
{ x, y, width ,height }. Rectangle type
---
> Image = ImageId
int id. Image type (multiple pixel formats supported). NOTE: Data stored in CPU memory (RAM)
---
> Texture = TextureId or { id, width, height, mipmaps, format }
int id. Texture type (multiple internal formats supported). NOTE: Data stored in GPU memory (VRAM)
---
> RenderTexture = RenderTextureId or { id, texture, depth }
int id. RenderTexture type, for texture rendering
---
> Font = FontId
int id. Font type, includes texture and chars data
---
> Camera2D = CameraId or { offset, target, rotation, zoom }
int id. Defines 2D camera position/orientation
---
> Camera = CameraId or { position, target, up, fovy, projection }
int id. Defines 3D camera3D position/orientation
---
> Mesh = MeshId
int id. Vertex data defining a mesh
```
mesh{} = {
vertices = { Vector3, ... },
texcoords = { Vector2, ... },
texcoords2 = { Vector2, ... },
normals = { Vector3, ... },
tangents = { Vector4, ... },
colors = { Color, ... },
indices = { int, ... },
}
```
---
> Material = MaterialId
int id. Material type
```
material{} = {
shader = Shader,
maps = {
{
MATERIAL_MAP_ALBEDO,
{
texture = Texture,
color = WHITE,
value = 1.0,
},
},
...
},
params = { 1.0, 2.0, 3.0, 4.0 },
}
```
---
> Model = ModelId
int id. Basic 3d Model type
---
> Ray = { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 } } or { position = { 0.0, 0.0, 0.0 }, direction = { 1.0, 0.0, 0.0 } }
{ position, direction }. Ray type (useful for raycast)
---
> RayCollision = { hit = true, distance = 1.0, point = { 0.0, 0.0, 0.0 }, normal = { 0.0, 0.0, 1.0 } }
Raycast hit information. NOTE: Data in named keys
---
> BoundingBox = { { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 } } or { min = { 0.0, 0.0, 0.0 }, max = { 1.0, 1.0, 1.0 } }
{ min, max }. Accepts Vector3. Bounding box type for 3d mesh
---
> Sound = SoundId
int id. Basic Sound source and buffer
---
> NPatchInfo = { { 0, 0, 24, 24 }, 8, 8, 8, 8, NPATCH_NINE_PATCH } or { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }
{ Rectangle source, int left, int top, int right, int bottom, int layout }.
{ Texture source rectangle, Left border offset, Top border offset, Right border offset, Bottom border offset, Layout of the n-patch: 3x3, 1x3 or 3x1 }
---
> ModelAnimations = ModelAnimationsId
int id. ModelAnimations
---
> Buffer = Buffer userdata
Userdata.
---
## Events
Content of event table received by RL.event.
### Window events
---
> { type: RL.EVENT_WINDOW_SIZE, int width, int height }
WindowSize Callback, runs when window is resized.
---
> { type RL.EVENT_WINDOW_MAXIMIZE, int maximized }
Window Maximize Callback, runs when window is maximized.
---
> { type RL.EVENT_WINDOW_ICONYFY, int iconified }
WindowIconify Callback, runs when window is minimized/restored.
---
> { type RL.EVENT_WINDOW_FOCUS, int focused }
WindowFocus Callback, runs when window get/lose focus.
---
> { type RL.EVENT_WINDOW_DROP, int count, string{} paths }
Window Drop Callback, runs when drop files into window.
---
### Input events
---
> { type: RL.EVENT_KEY, int key, int scancode, int action, int mods }
Keyboard Callback, runs on key pressed.
---
> { type RL.EVENT_CHAR, int key }
Char Key Callback, runs on key pressed (get char value).
---
> { type RL.EVENT_MOUSE_BUTTON, int button, int action, int mods }
Mouse Button Callback, runs on mouse button pressed.
---
> { type RL.EVENT_MOUSE_CURSOR_POS, number x, number y }
Cursor Position Callback, runs on mouse move.
---
> { type RL.EVENT_MOUSE_SCROLL, number xoffset, number yoffset }
Srolling Callback, runs on mouse wheel.
---
> { type RL.EVENT_CURSOR_ENTER, int enter }
Cursor Enter Callback, cursor enters client area.
---
## Core - Window
---
@@ -1761,7 +1788,7 @@ Open URL with default system browser (If available)
> buffer = RL.LoadBuffer( data{} buffer, int type )
Creates buffer as userdata. Type should be one of the Buffer types
Load Buffer. Type should be one of the Buffer types
- Success return Buffer
@@ -3474,6 +3501,14 @@ Load cubemap from image, multiple image cubemap layouts supported
---
> texture = RL.LoadTextureFromData( Texture{} textureData )
Load Texture from data
- Success return Texture
---
> renderTexture = RL.LoadRenderTexture( Vector2 size )
Load texture for rendering (framebuffer)
@@ -3482,6 +3517,14 @@ Load texture for rendering (framebuffer)
---
> renderTexture = RL.LoadRenderTextureFromData( Texture{} renderTextureData )
Load RenderTexture from data (framebuffer)
- Success return RenderTexture
---
> isReady = RL.IsTextureReady( Texture texture )
Check if a texture is ready

View File

@@ -1,8 +1,6 @@
## About
Idea of this project was to bring the power and simplicity of raylib to easy beginner friendly language like Lua in a very straight forward manner. It is loose binding to Raylib, some functions will not be included and some are added. The idea of pointing "main.lua" file and access functions "init", "process" and "draw" are borrowed from Löve game framework.
Need for boilerplate code is minimal and in true Lua fashion (in better and worse) you don't need to worry about strict type rules since all Raylib types are lua tables or object id's. Also what Lua cannot handle, the framework is simple enough to be fairly easily extended with new functionality or by using Lua C-libraries.
Idea of this project was to bring the power and simplicity of Raylib to easy beginner friendly language like Lua in a very straight forward manner. It is loose binding to Raylib, some functions will not be included and some are added. The idea of pointing "main.lua" file and access functions "init", "process" and "draw" are borrowed from Löve game framework.
ReiLua is not planned to be a one-to-one binding to raylib. If you want more direct bindings, there are other projects like https://github.com/TSnake41/raylib-lua.
@@ -10,8 +8,6 @@ Reilua means fair in finnish.
## 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.
Included submodules.
@@ -33,9 +29,6 @@ List of some MISSING features that are planned to be included. For specific func
## Roadmap
* v0.6
* Switch from id based objects to Lua userdata(like most bindings). Resources won't be stored in State anymore.
* Change argument checking to use more luaL_checkx functions and remove the TraceLog messages.
* v0.7
* Switch to Raylib v5.0?

View File

@@ -938,7 +938,7 @@ function RL.GetLogLevelInvalid() end
---@return any RL.OpenURL
function RL.OpenURL( url ) end
---Creates buffer as userdata. Type should be one of the Buffer types
---Load Buffer. Type should be one of the Buffer types
---- Success return Buffer
---@param buffer any
---@param type integer
@@ -2483,12 +2483,24 @@ function RL.LoadTextureFromImage( image ) end
---@return any texture
function RL.LoadTextureCubemap( image, layout ) end
---Load Texture from data
---- Success return Texture
---@param textureData any
---@return any texture
function RL.LoadTextureFromData( textureData ) end
---Load texture for rendering (framebuffer)
---- Success return RenderTexture
---@param size table
---@return any renderTexture
function RL.LoadRenderTexture( size ) end
---Load RenderTexture from data (framebuffer)
---- Success return RenderTexture
---@param renderTextureData any
---@return any renderTexture
function RL.LoadRenderTextureFromData( renderTextureData ) end
---Check if a texture is ready
---- Success return bool
---@param texture any

View File

@@ -3,9 +3,11 @@ 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.
- REMOVED: Unload* functions since unloading is now handled by Lua garbage collection.
- CHANGED: Rely mostly on luaL_check* functions for arg checking.
- CHANGED: ModelAnimations are changed to separate ModelAnimation types as in Raylib.
- ADDED: LoadTextureFromData.
- ADDED: LoadRenderTextureFromData.
DETAILED CHANGES:
- CHANGED: GenImageColor now takes Vector2 as size.

View File

@@ -1,12 +1,11 @@
Current {
* Converting to new style.
* Fix examples.
}
Backlog {
* rlgl
* Shaders management
* Compute shader management
* New type validators.
* Platformer example physics process for true framerate independence.
* Extend color lib functionality.
* Global variable descriptions for API.
@@ -17,7 +16,6 @@ Backlog {
* Audio
* AudioStream.
* Core.
* Load shader function arg check to new style.
* Compression/Encoding functionality.
* SetWindowIcons.
* Models

View File

@@ -127,6 +127,128 @@ luaApiFile:write(
apiFile:write( "\n## Arguments\n" )
apiFile:write( "\nArguments are stored in 'RL.arg' array.\n" )
-- Types.
apiFile:write( "\n## Types\n\
Raylib structs in Lua\n\n---\n" )
apiFile:write( "\n> Vector2 = { 1.0, 1.0 } or { x = 1.0, y = 1.0 }\n\
Vector2, 2 components\n\n---\n" )
apiFile:write( "\n> Vector3 = { 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0 }\n\
Vector3, 3 components\n\n---\n" )
apiFile:write( "\n> Vector4 = { 1.0, 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0, w = 1.0 }\n\
Vector4, 4 components\n\n---\n" )
apiFile:write( "\n> Quaternion = { 1.0, 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0, w = 1.0 }\n\
Quaternion, 4 components (Vector4 alias)\n\n---\n" )
apiFile:write( "\n> Matrix = { { 1.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0 } }\n\
Matrix, 4x4 components, column major, OpenGL style, right-handed. Identity matrix example\n\n---\n" )
apiFile:write( "\n> Color = { 255, 255, 255, 255 } or { r = 255, g = 255, b = 255, a = 255 }\n\
Color, 4 components, R8G8B8A8 (32bit)\n\n---\n" )
apiFile:write( "\n> Rectangle = { 0.0, 0.0, 1.0, 1.0 } or { x = 0.0, y = 0.0, width = 1.0, height = 1.0 }\n\
Rectangle, 4 components\n\n---\n" )
apiFile:write( "\n> Image = Userdata\n\
Image, pixel data stored in CPU memory (RAM)\n\n---\n" )
apiFile:write( "\n> Texture = Userdata\n\
Texture, tex data stored in GPU memory (VRAM)\
```\
textureData = {\
id = unsigned int, --OpenGL texture id\
width = int, --Texture base width\
height = int, --Texture base height\
mipmaps = int, --Mipmap levels, 1 by default\
format = int --Data format (PixelFormat type)\
}\
```\n\n---\n" )
apiFile:write( "\n> RenderTexture = Userdata\n\
RenderTexture, fbo for texture rendering\
```\
renderTextureData = {\
id = unsigned int, --OpenGL texture id\
texture = Texture, --Texture base width\
depth = Texture, --Texture base height\
}\
```\n\n---\n" )
apiFile:write( "\n> Font = Userdata\n\
Font, font texture and GlyphInfo array data\n\n---\n" )
apiFile:write( "\n> Camera2D = Userdata\n\
Camera2D, defines position/orientation in 2d space\n\n---\n" )
apiFile:write( "\n> Camera3D = Userdata\n\
Camera, defines position/orientation in 3d space\n\n---\n" )
apiFile:write( "\n> Mesh = Userdata\n\
Mesh, vertex data and vao/vbo\n\
```\
meshData = {\
vertices = Vector3{}, --Vertex position (XYZ - 3 components per vertex) (shader-location = 0)\
texcoords = Vector2{}, --Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)\
texcoords2 = Vector2{}, --Vertex texture second coordinates (UV - 2 components per vertex) (shader-location = 5)\
normals = Vector3{}, --Vertex normals (XYZ - 3 components per vertex) (shader-location = 2)\
tangents = Vector4{}, --Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4)\
colors = Color{}, --Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)\
indices = int{} --Vertex indices (in case vertex data comes indexed)\
}\
```\n\n---\n" )
apiFile:write( "\n> Material = Userdata\n\
Material, includes shader and maps\n\
```\
materialData = {\
shader = Shader,\
maps = { --Material maps array (MAX_MATERIAL_MAPS)\
{\
MATERIAL_MAP_*, --Example MATERIAL_MAP_ALBEDO\
{\
texture = Texture, --Material map texture\
color = Color, --Material map color\
value = float, --Material map value\
},\
},\
...\
},\
params = { float, float, float, float } --Material generic parameters (if required)\
}\
```\n\n---\n" )
apiFile:write( "\n> Model = Userdata\n\
Model, meshes, materials and animation data\n\n---\n" )
apiFile:write( "\n> Ray = { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 } } or { position = { 0.0, 0.0, 0.0 }, direction = { 1.0, 0.0, 0.0 } }\n\
Ray, ray for raycasting\n\n---\n" )
apiFile:write( "\n> RayCollision = { hit = true, distance = 1.0, point = { 0.0, 0.0, 0.0 }, normal = { 0.0, 0.0, 1.0 } }\n\
RayCollision, ray hit information\n\n---\n" )
apiFile:write( "\n> BoundingBox = { { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 } } or { min = { 0.0, 0.0, 0.0 }, max = { 1.0, 1.0, 1.0 } }\n\
BoundingBox\n\n---\n" )
apiFile:write( "\n> Wave = Userdata\n\
Wave, audio wave data\n\n---\n" )
apiFile:write( "\n> Sound = Userdata\n\
Sound\n\n---\n" )
apiFile:write( "\n> Music = Userdata\n\
Music, audio stream, anything longer than ~10 seconds should be streamed\n\n---\n" )
apiFile:write( "\n> NPatchInfo = { { 0, 0, 24, 24 }, 8, 8, 8, 8, NPATCH_NINE_PATCH } or { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }\n\
NPatchInfo, n-patch layout info\n\n---\n" )
apiFile:write( "\n> ModelAnimations = Userdata\n\
ModelAnimation\n\n---\n" )
apiFile:write( "\n> Buffer = Buffer userdata\n\
Data buffer for C primitive types. Type should be one of the Buffer types.\n\n---\n" )
-- Events.
apiFile:write( "\n## Events\n" )
apiFile:write( "\nContent of event table received by RL.event.\n" )
apiFile:write( "\n### Window events\n" )
apiFile:write( "\n---\n> { type: RL.EVENT_WINDOW_SIZE, int width, int height }\n\n WindowSize Callback, runs when window is resized.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_MAXIMIZE, int maximized }\n\n Window Maximize Callback, runs when window is maximized.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_ICONYFY, int iconified }\n\n WindowIconify Callback, runs when window is minimized/restored.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_FOCUS, int focused }\n\n WindowFocus Callback, runs when window get/lose focus.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_DROP, int count, string{} paths }\n\n Window Drop Callback, runs when drop files into window.\n\n---\n" )
apiFile:write( "\n### Input events\n" )
apiFile:write( "\n---\n> { type: RL.EVENT_KEY, int key, int scancode, int action, int mods }\n\n Keyboard Callback, runs on key pressed.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_CHAR, int key }\n\n Char Key Callback, runs on key pressed (get char value).\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_BUTTON, int button, int action, int mods }\n\n Mouse Button Callback, runs on mouse button pressed.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_CURSOR_POS, number x, number y }\n\n Cursor Position Callback, runs on mouse move.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_SCROLL, number xoffset, number yoffset }\n\n Srolling Callback, runs on mouse wheel.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_CURSOR_ENTER, int enter }\n\n Cursor Enter Callback, cursor enters client area.\n\n---\n" )
if separate then
apiFile:close()
end
-- Globals.
local srcFile = io.open( "../src/lua_core.c", "r" )
@@ -179,109 +301,6 @@ until line == nil
srcFile:close()
-- Types.
apiFile:write( "\n## Types\n\
Raylib structs in Lua\n\n---\n" )
apiFile:write( "\n> Vector2 = { 1.0, 1.0 } or { x = 1.0, y = 1.0 }\n\
Vector2 type\n\n---\n" )
apiFile:write( "\n> Vector3 = { 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0 }\n\
Vector3 type\n\n---\n" )
apiFile:write( "\n> Vector4 = { 1.0, 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0, w = 1.0 }\n\
Vector4 type\n\n---\n" )
apiFile:write( "\n> Quaternion = { 1.0, 1.0, 1.0, 1.0 } or { x = 1.0, y = 1.0, z = 1.0, w = 1.0 }\n\
Quaternion type\n\n---\n" )
apiFile:write( "\n> Matrix = { { 1.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0 } }\n\
OpenGL style 4x4. Identity matrix example\n\n---\n" )
apiFile:write( "\n> Color = { 255, 255, 255, 255 } or { r = 255, g = 255, b = 255, a = 255 }\n\
{ r, g, b ,a }. Color type, RGBA (32bit)\n\n---\n" )
apiFile:write( "\n> Rectangle = { 0.0, 0.0, 1.0, 1.0 } or { x = 0.0, y = 0.0, width = 1.0, height = 1.0 }\n\
{ x, y, width ,height }. Rectangle type\n\n---\n" )
apiFile:write( "\n> Image = ImageId\n\
int id. Image type (multiple pixel formats supported). NOTE: Data stored in CPU memory (RAM)\n\n---\n" )
apiFile:write( "\n> Texture = TextureId or { id, width, height, mipmaps, format }\n\
int id. Texture type (multiple internal formats supported). NOTE: Data stored in GPU memory (VRAM)\n\n---\n" )
apiFile:write( "\n> RenderTexture = RenderTextureId or { id, texture, depth }\n\
int id. RenderTexture type, for texture rendering\n\n---\n" )
apiFile:write( "\n> Font = FontId\n\
int id. Font type, includes texture and chars data\n\n---\n" )
apiFile:write( "\n> Camera2D = CameraId or { offset, target, rotation, zoom }\n\
int id. Defines 2D camera position/orientation\n\n---\n" )
apiFile:write( "\n> Camera = CameraId or { position, target, up, fovy, projection }\n\
int id. Defines 3D camera3D position/orientation\n\n---\n" )
apiFile:write( "\n> Mesh = MeshId\n\
int id. Vertex data defining a mesh\n\
```\
mesh{} = {\
vertices = { Vector3, ... },\
texcoords = { Vector2, ... },\
texcoords2 = { Vector2, ... },\
normals = { Vector3, ... },\
tangents = { Vector4, ... },\
colors = { Color, ... },\
indices = { int, ... },\
}\
```\n\n---\n" )
apiFile:write( "\n> Material = MaterialId\n\
int id. Material type\n\
```\
material{} = {\
shader = Shader,\
maps = {\
{\
MATERIAL_MAP_ALBEDO,\
{\
texture = Texture,\
color = WHITE,\
value = 1.0,\
},\
},\
...\
},\
params = { 1.0, 2.0, 3.0, 4.0 },\
}\
```\n\n---\n" )
apiFile:write( "\n> Model = ModelId\n\
int id. Basic 3d Model type\n\n---\n" )
apiFile:write( "\n> Ray = { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 } } or { position = { 0.0, 0.0, 0.0 }, direction = { 1.0, 0.0, 0.0 } }\n\
{ position, direction }. Ray type (useful for raycast)\n\n---\n" )
apiFile:write( "\n> RayCollision = { hit = true, distance = 1.0, point = { 0.0, 0.0, 0.0 }, normal = { 0.0, 0.0, 1.0 } }\n\
Raycast hit information. NOTE: Data in named keys\n\n---\n" )
apiFile:write( "\n> BoundingBox = { { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 } } or { min = { 0.0, 0.0, 0.0 }, max = { 1.0, 1.0, 1.0 } }\n\
{ min, max }. Accepts Vector3. Bounding box type for 3d mesh\n\n---\n" )
apiFile:write( "\n> Sound = SoundId\n\
int id. Basic Sound source and buffer\n\n---\n" )
apiFile:write( "\n> NPatchInfo = { { 0, 0, 24, 24 }, 8, 8, 8, 8, NPATCH_NINE_PATCH } or { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }\n\
{ Rectangle source, int left, int top, int right, int bottom, int layout }.\
{ Texture source rectangle, Left border offset, Top border offset, Right border offset, Bottom border offset, Layout of the n-patch: 3x3, 1x3 or 3x1 }\n\n---\n" )
apiFile:write( "\n> ModelAnimations = ModelAnimationsId\n\
int id. ModelAnimations\n\n---\n" )
apiFile:write( "\n> Buffer = Buffer userdata\n\
Userdata.\n\n---\n" )
-- Events.
apiFile:write( "\n## Events\n" )
apiFile:write( "\nContent of event table received by RL.event.\n" )
apiFile:write( "\n### Window events\n" )
apiFile:write( "\n---\n> { type: RL.EVENT_WINDOW_SIZE, int width, int height }\n\n WindowSize Callback, runs when window is resized.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_MAXIMIZE, int maximized }\n\n Window Maximize Callback, runs when window is maximized.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_ICONYFY, int iconified }\n\n WindowIconify Callback, runs when window is minimized/restored.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_FOCUS, int focused }\n\n WindowFocus Callback, runs when window get/lose focus.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_WINDOW_DROP, int count, string{} paths }\n\n Window Drop Callback, runs when drop files into window.\n\n---\n" )
apiFile:write( "\n### Input events\n" )
apiFile:write( "\n---\n> { type: RL.EVENT_KEY, int key, int scancode, int action, int mods }\n\n Keyboard Callback, runs on key pressed.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_CHAR, int key }\n\n Char Key Callback, runs on key pressed (get char value).\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_BUTTON, int button, int action, int mods }\n\n Mouse Button Callback, runs on mouse button pressed.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_CURSOR_POS, number x, number y }\n\n Cursor Position Callback, runs on mouse move.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_MOUSE_SCROLL, number xoffset, number yoffset }\n\n Srolling Callback, runs on mouse wheel.\n\n---\n" )
apiFile:write( "\n> { type RL.EVENT_CURSOR_ENTER, int enter }\n\n Cursor Enter Callback, cursor enters client area.\n\n---\n" )
if separate then
apiFile:close()
end
-- Functions.
local sourceFiles = {

View File

@@ -1,17 +1,10 @@
local textColor = RL.BLACK
local textPos = { 192, 200 }
local text = "Congrats! You created your first window!"
local texture = nil
function RL.init()
RL.SetWindowTitle( "First window" )
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
function RL.process( delta )
@@ -31,6 +24,5 @@ end
function RL.draw()
RL.ClearBackground( RL.RAYWHITE )
RL.DrawTexture( texture, { 20, 20 }, RL.WHITE )
RL.DrawText( RL.defaultFont, text, textPos, 20, 2, textColor )
end

View File

@@ -65,7 +65,9 @@ int ltexturesGetImageFormat( lua_State *L );
int ltexturesLoadTexture( lua_State *L );
int ltexturesLoadTextureFromImage( lua_State *L );
int ltexturesLoadTextureCubemap( lua_State *L );
int ltexturesLoadTextureFromData( lua_State *L );
int ltexturesLoadRenderTexture( lua_State *L );
int ltexturesLoadRenderTextureFromData( lua_State *L );
int ltexturesIsTextureReady( lua_State *L );
int ltexturesUpdateTexture( lua_State *L );
int ltexturesUpdateTextureRec( lua_State *L );

View File

@@ -544,7 +544,7 @@ int lcoreOpenURL( lua_State *L ) {
/*
> buffer = RL.LoadBuffer( data{} buffer, int type )
Creates buffer as userdata. Type should be one of the Buffer types
Load Buffer. Type should be one of the Buffer types
- Success return Buffer
*/

View File

@@ -1791,7 +1791,9 @@ void luaRegister() {
assingGlobalFunction( "LoadTexture", ltexturesLoadTexture );
assingGlobalFunction( "LoadTextureFromImage", ltexturesLoadTextureFromImage );
assingGlobalFunction( "LoadTextureCubemap", ltexturesLoadTextureCubemap );
assingGlobalFunction( "LoadTextureFromData", ltexturesLoadTextureFromData );
assingGlobalFunction( "LoadRenderTexture", ltexturesLoadRenderTexture );
assingGlobalFunction( "LoadRenderTextureFromData", ltexturesLoadRenderTextureFromData );
assingGlobalFunction( "IsTextureReady", ltexturesIsTextureReady );
assingGlobalFunction( "UpdateTexture", ltexturesUpdateTexture );
assingGlobalFunction( "UpdateTextureRec", ltexturesUpdateTextureRec );

View File

@@ -939,6 +939,44 @@ int ltexturesLoadTextureCubemap( lua_State *L ) {
return 1;
}
/*
> texture = RL.LoadTextureFromData( Texture{} textureData )
Load Texture from data
- Success return Texture
*/
int ltexturesLoadTextureFromData( lua_State *L ) {
luaL_checktype( L, 1, LUA_TTABLE );
Texture2D texture = { 0 };
int t = 1;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.id = (unsigned int)luaL_checkinteger( L, -1 );
}
else if ( strcmp( "width", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.width = luaL_checkinteger( L, -1 );
}
else if ( strcmp( "height", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.height = luaL_checkinteger( L, -1 );
}
else if ( strcmp( "mipmaps", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.mipmaps = luaL_checkinteger( L, -1 );
}
else if ( strcmp( "format", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.format = luaL_checkinteger( L, -1 );
}
lua_pop( L, 1 );
}
uluaPushTexture( L, texture );
return 1;
}
/*
> renderTexture = RL.LoadRenderTexture( Vector2 size )
@@ -954,6 +992,41 @@ int ltexturesLoadRenderTexture( lua_State *L ) {
return 1;
}
/*
> renderTexture = RL.LoadRenderTextureFromData( Texture{} renderTextureData )
Load RenderTexture from data (framebuffer)
- Success return RenderTexture
*/
int ltexturesLoadRenderTextureFromData( lua_State *L ) {
luaL_checktype( L, 1, LUA_TTABLE );
RenderTexture renTexture = { 0 };
int t = 1;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
renTexture.id = (unsigned int)luaL_checkinteger( L, -1 );
}
else if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 ) {
Texture *texture = luaL_checkudata( L, -1, "Texture" );
renTexture.texture = *texture;
}
else if ( strcmp( "depth", (char*)lua_tostring( L, -2 ) ) == 0 ) {
Texture *depth = luaL_checkudata( L, -1, "Texture" );
renTexture.depth = *depth;
}
lua_pop( L, 1 );
}
uluaPushRenderTexture( L, renTexture );
return 1;
}
/*
> isReady = RL.IsTextureReady( Texture texture )