summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorjussi2022-04-05 01:38:03 +0300
committerjussi2022-04-05 01:38:03 +0300
commitfbfe1e0cb6207b6c8afd42457cb1304c7264734f (patch)
treebeb8e4725b6e9842fee5f929ad3f3b24663a26d2 /include
parent2a46afbf91c17463b1360faf7773a9aeb69b4e46 (diff)
downloadreilua-enhanced-fbfe1e0cb6207b6c8afd42457cb1304c7264734f.tar.gz
reilua-enhanced-fbfe1e0cb6207b6c8afd42457cb1304c7264734f.tar.bz2
reilua-enhanced-fbfe1e0cb6207b6c8afd42457cb1304c7264734f.zip
Lights.
Diffstat (limited to 'include')
-rw-r--r--include/core.h3
-rw-r--r--include/lights.h7
-rw-r--r--include/main.h2
-rw-r--r--include/rlights.h183
-rw-r--r--include/state.h4
5 files changed, 199 insertions, 0 deletions
diff --git a/include/core.h b/include/core.h
index 1f0691c..8cb2977 100644
--- a/include/core.h
+++ b/include/core.h
@@ -2,6 +2,7 @@
/* Validators. */
bool validCamera3D( size_t id );
+bool validShader( size_t id );
/* Window. */
int lcoreIsWindowReady( lua_State *L );
int lcoreIsWindowFullscreen( lua_State *L );
@@ -61,6 +62,8 @@ int lcoreBeginShaderMode( lua_State *L );
int lcoreEndShaderMode( lua_State *L );
int lcoreGetShaderLocation( lua_State *L );
int lcoreGetShaderLocationAttrib( lua_State *L );
+int lcoreSetShaderLocationIndex( lua_State *L );
+int lcoreGetShaderLocationIndex( lua_State *L );
int lcoreSetShaderValueMatrix( lua_State *L );
int lcoreSetShaderValueTexture( lua_State *L );
int lcoreSetShaderValue( lua_State *L );
diff --git a/include/lights.h b/include/lights.h
new file mode 100644
index 0000000..2b483b3
--- /dev/null
+++ b/include/lights.h
@@ -0,0 +1,7 @@
+#pragma once
+
+/* Validators. */
+bool validLight( size_t id );
+/* Basics. */
+int llightsCreateLight( lua_State *L );
+int llightsUpdateLightValues( lua_State *L );
diff --git a/include/main.h b/include/main.h
index dd359ee..1f626f0 100644
--- a/include/main.h
+++ b/include/main.h
@@ -11,6 +11,8 @@
#include <string.h>
#include "raylib.h"
#include "raymath.h"
+#include "raygui.h"
+#include "rlights.h"
#include "rlgl.h"
#include <lua.h>
#include <lualib.h>
diff --git a/include/rlights.h b/include/rlights.h
new file mode 100644
index 0000000..a1b2988
--- /dev/null
+++ b/include/rlights.h
@@ -0,0 +1,183 @@
+/**********************************************************************************************
+*
+* raylib.lights - Some useful functions to deal with lights data
+*
+* CONFIGURATION:
+*
+* #define RLIGHTS_IMPLEMENTATION
+* Generates the implementation of the library into the included file.
+* If not defined, the library is in header only mode and can be included in other headers
+* or source files without problems. But only ONE file should hold the implementation.
+*
+* LICENSE: zlib/libpng
+*
+* Copyright (c) 2017-2020 Victor Fisac (@victorfisac) and Ramon Santamaria (@raysan5)
+*
+* This software is provided "as-is", without any express or implied warranty. In no event
+* will the authors be held liable for any damages arising from the use of this software.
+*
+* Permission is granted to anyone to use this software for any purpose, including commercial
+* applications, and to alter it and redistribute it freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not claim that you
+* wrote the original software. If you use this software in a product, an acknowledgment
+* in the product documentation would be appreciated but is not required.
+*
+* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
+* as being the original software.
+*
+* 3. This notice may not be removed or altered from any source distribution.
+*
+**********************************************************************************************/
+
+#ifndef RLIGHTS_H
+#define RLIGHTS_H
+
+//----------------------------------------------------------------------------------
+// Defines and Macros
+//----------------------------------------------------------------------------------
+#define MAX_LIGHTS 4 // Max dynamic lights supported by shader
+
+//----------------------------------------------------------------------------------
+// Types and Structures Definition
+//----------------------------------------------------------------------------------
+
+// Light data
+typedef struct {
+ int type;
+ Vector3 position;
+ Vector3 target;
+ Color color;
+ bool enabled;
+
+ // Shader locations
+ int enabledLoc;
+ int typeLoc;
+ int posLoc;
+ int targetLoc;
+ int colorLoc;
+} Light;
+
+// Light type
+typedef enum {
+ LIGHT_DIRECTIONAL,
+ LIGHT_POINT
+} LightType;
+
+#ifdef __cplusplus
+extern "C" { // Prevents name mangling of functions
+#endif
+
+//----------------------------------------------------------------------------------
+// Module Functions Declaration
+//----------------------------------------------------------------------------------
+Light CreateLight(int type, Vector3 position, Vector3 target, Color color, Shader shader); // Create a light and get shader locations
+void UpdateLightValues(Shader shader, Light light); // Send light properties to shader
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // RLIGHTS_H
+
+
+/***********************************************************************************
+*
+* RLIGHTS IMPLEMENTATION
+*
+************************************************************************************/
+
+#if defined(RLIGHTS_IMPLEMENTATION)
+
+#include "raylib.h"
+
+//----------------------------------------------------------------------------------
+// Defines and Macros
+//----------------------------------------------------------------------------------
+// ...
+
+//----------------------------------------------------------------------------------
+// Types and Structures Definition
+//----------------------------------------------------------------------------------
+// ...
+
+//----------------------------------------------------------------------------------
+// Global Variables Definition
+//----------------------------------------------------------------------------------
+static int lightsCount = 0; // Current amount of created lights
+
+//----------------------------------------------------------------------------------
+// Module specific Functions Declaration
+//----------------------------------------------------------------------------------
+// ...
+
+//----------------------------------------------------------------------------------
+// Module Functions Definition
+//----------------------------------------------------------------------------------
+
+// Create a light and get shader locations
+Light CreateLight(int type, Vector3 position, Vector3 target, Color color, Shader shader)
+{
+ Light light = { 0 };
+
+ if (lightsCount < MAX_LIGHTS)
+ {
+ light.enabled = true;
+ light.type = type;
+ light.position = position;
+ light.target = target;
+ light.color = color;
+
+ // TODO: Below code doesn't look good to me,
+ // it assumes a specific shader naming and structure
+ // Probably this implementation could be improved
+ char enabledName[32] = "lights[x].enabled\0";
+ char typeName[32] = "lights[x].type\0";
+ char posName[32] = "lights[x].position\0";
+ char targetName[32] = "lights[x].target\0";
+ char colorName[32] = "lights[x].color\0";
+
+ // Set location name [x] depending on lights count
+ enabledName[7] = '0' + lightsCount;
+ typeName[7] = '0' + lightsCount;
+ posName[7] = '0' + lightsCount;
+ targetName[7] = '0' + lightsCount;
+ colorName[7] = '0' + lightsCount;
+
+ light.enabledLoc = GetShaderLocation(shader, enabledName);
+ light.typeLoc = GetShaderLocation(shader, typeName);
+ light.posLoc = GetShaderLocation(shader, posName);
+ light.targetLoc = GetShaderLocation(shader, targetName);
+ light.colorLoc = GetShaderLocation(shader, colorName);
+
+ UpdateLightValues(shader, light);
+
+ lightsCount++;
+ }
+
+ return light;
+}
+
+// Send light properties to shader
+// NOTE: Light shader locations should be available
+void UpdateLightValues(Shader shader, Light light)
+{
+ // Send to shader light enabled state and type
+ SetShaderValue(shader, light.enabledLoc, &light.enabled, SHADER_UNIFORM_INT);
+ SetShaderValue(shader, light.typeLoc, &light.type, SHADER_UNIFORM_INT);
+
+ // Send to shader light position values
+ float position[3] = { light.position.x, light.position.y, light.position.z };
+ SetShaderValue(shader, light.posLoc, position, SHADER_UNIFORM_VEC3);
+
+ // Send to shader light target position values
+ float target[3] = { light.target.x, light.target.y, light.target.z };
+ SetShaderValue(shader, light.targetLoc, target, SHADER_UNIFORM_VEC3);
+
+ // Send to shader light color values
+ float color[4] = { (float)light.color.r/(float)255, (float)light.color.g/(float)255,
+ (float)light.color.b/(float)255, (float)light.color.a/(float)255 };
+ SetShaderValue(shader, light.colorLoc, color, SHADER_UNIFORM_VEC4);
+}
+
+#endif // RLIGHTS_IMPLEMENTATION \ No newline at end of file
diff --git a/include/state.h b/include/state.h
index 3fc4e8e..f724cc1 100644
--- a/include/state.h
+++ b/include/state.h
@@ -62,6 +62,10 @@ typedef struct {
Shader **shaders;
size_t shaderCount;
size_t shaderAlloc;
+ /* Lights. */
+ Light **lights;
+ size_t lightCount;
+ size_t lightAlloc;
} State;
extern State *state;