summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorRay <[email protected]>2019-01-10 16:57:15 +0100
committerGitHub <[email protected]>2019-01-10 16:57:15 +0100
commit56173d7cf457413fd56e26967becc7c5054aa2cf (patch)
treef1428e583f4ed5ee8c7060c47da55e8ce0194882 /examples
parent6056a2a5cf2aa939a10e807e452ed43d4b67f1ce (diff)
parent93471b0a7c75fc675f27fc74dfda281eb8310a7a (diff)
downloadraylib-56173d7cf457413fd56e26967becc7c5054aa2cf.tar.gz
raylib-56173d7cf457413fd56e26967becc7c5054aa2cf.zip
Merge branch 'master' into window-visibility
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt1
-rw-r--r--examples/Makefile21
-rw-r--r--examples/audio/audio_module_playing.c6
-rw-r--r--examples/models/models_material_pbr.c22
-rw-r--r--examples/models/models_skybox.c6
-rw-r--r--examples/models/resources/shaders/brdf.fs73
-rw-r--r--examples/models/resources/shaders/cubemap.fs4
-rw-r--r--examples/models/resources/shaders/cubemap.vs4
-rw-r--r--examples/models/resources/shaders/skybox.fs4
-rw-r--r--examples/models/resources/shaders/skybox.vs4
-rw-r--r--examples/models/rlights.h10
-rw-r--r--examples/others/raudio_standalone.c (renamed from examples/others/audio_standalone.c)10
-rw-r--r--examples/others/standard_lighting.c25
-rw-r--r--examples/shaders/resources/shaders/glsl100/palette-switch.fs29
-rw-r--r--examples/shaders/resources/shaders/glsl120/palette-switch.fs27
-rw-r--r--examples/shaders/resources/shaders/glsl330/palette-switch.fs30
-rw-r--r--examples/shaders/shaders_custom_uniform.c2
-rw-r--r--examples/shaders/shaders_palette_switch.c165
-rw-r--r--examples/shaders/shaders_raymarching.c12
-rw-r--r--examples/shapes/shapes_logo_raylib_anim.c4
-rw-r--r--examples/text/text_draw_inside_rectangle.c120
-rw-r--r--examples/text/text_draw_inside_rectangle.pngbin0 -> 17844 bytes
-rw-r--r--examples/text/text_writing_anim.c4
-rw-r--r--examples/textures/textures_image_text.c2
-rw-r--r--examples/textures/textures_raw_data.c14
25 files changed, 481 insertions, 118 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 1c0c935c..1d4fdd79 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -52,6 +52,7 @@ if(${PLATFORM} MATCHES "Android")
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_model_shader.c)
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_postprocessing.c)
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_raymarching.c)
+ list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_palette_switch.c)
elseif(${PLATFORM} MATCHES "Web")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1")
diff --git a/examples/Makefile b/examples/Makefile
index 53e8555d..e14762b3 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -118,8 +118,8 @@ endif
ifeq ($(PLATFORM),PLATFORM_WEB)
# Emscripten required variables
EMSDK_PATH = C:/emsdk
- EMSCRIPTEN_VERSION = 1.38.20
- CLANG_VERSION = e1.38.20_64bit
+ EMSCRIPTEN_VERSION = 1.38.21
+ CLANG_VERSION = e1.38.21_64bit
PYTHON_VERSION = 2.7.13.1_64bit\python-2.7.13.amd64
NODE_VERSION = 8.9.1_64bit
export PATH = $(EMSDK_PATH);$(EMSDK_PATH)\clang\$(CLANG_VERSION);$(EMSDK_PATH)\node\$(NODE_VERSION)\bin;$(EMSDK_PATH)\python\$(PYTHON_VERSION);$(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION);C:\raylib\MinGW\bin:$$(PATH)
@@ -130,23 +130,23 @@ endif
# RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version.
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(PLATFORM_OS),WINDOWS)
- RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/win32/mingw32
+ RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src
endif
ifeq ($(PLATFORM_OS),LINUX)
- RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/linux
+ RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src
endif
ifeq ($(PLATFORM_OS),OSX)
- RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx
+ RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src
endif
ifeq ($(PLATFORM_OS),BSD)
- RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd
+ RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src
endif
endif
ifeq ($(PLATFORM),PLATFORM_RPI)
- RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/rpi
+ RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
- RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/html5
+ RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src
endif
# EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries
@@ -249,7 +249,7 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
# -s EMTERPRETIFY_ASYNC=1 # support synchronous loops by emterpreter
# --profiling # include information for code profiling
# --preload-file resources # specify a resources folder for data compilation
- CFLAGS += -Os -s USE_GLFW=3 -s USE_SDL=2 -s ASSERTIONS=1 -s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1
+ CFLAGS += -Os -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1
# NOTE: Simple raylib examples are compiled to be interpreter by emterpreter, that way,
# we can compile same code for ALL platforms with no change required, but, working on bigger
@@ -407,7 +407,7 @@ EXAMPLES = \
models/models_box_collisions \
models/models_billboard \
models/models_obj_loading \
- models/models_obj_viewing \
+ models/models_obj_viewer \
models/models_heightmap \
models/models_cubicmap \
models/models_mesh_picking \
@@ -420,6 +420,7 @@ EXAMPLES = \
shaders/shaders_custom_uniform \
shaders/shaders_postprocessing \
shaders/shaders_raymarching \
+ shaders/shaders_palette_switch \
audio/audio_sound_loading \
audio/audio_music_stream \
audio/audio_module_playing \
diff --git a/examples/audio/audio_module_playing.c b/examples/audio/audio_module_playing.c
index 671a119f..54bfa3d2 100644
--- a/examples/audio/audio_module_playing.c
+++ b/examples/audio/audio_module_playing.c
@@ -30,11 +30,11 @@ int main()
int screenWidth = 800;
int screenHeight = 450;
- SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X
+ SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X
InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)");
- InitAudioDevice(); // Initialize audio device
+ InitAudioDevice(); // Initialize audio device
Color colors[14] = { ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK,
YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE };
@@ -52,7 +52,7 @@ int main()
circles[i].color = colors[GetRandomValue(0, 13)];
}
- Music xm = LoadMusicStream("resources/mini1111.xm");
+ Music xm = LoadMusicStream("resources/chiptun1.mod");
PlayMusicStream(xm);
diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c
index a4a10d60..f93c7a68 100644
--- a/examples/models/models_material_pbr.c
+++ b/examples/models/models_material_pbr.c
@@ -64,7 +64,7 @@ int main()
// Send to material PBR shader camera view position
float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z };
- SetShaderValue(model.material.shader, model.material.shader.locs[LOC_VECTOR_VIEW], cameraPos, 3);
+ SetShaderValue(model.material.shader, model.material.shader.locs[LOC_VECTOR_VIEW], cameraPos, UNIFORM_VEC3);
//----------------------------------------------------------------------------------
// Draw
@@ -148,15 +148,15 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
Shader shdrBRDF = LoadShader(PATH_BRDF_VS, PATH_BRDF_FS);
// Setup required shader locations
- SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1);
- SetShaderValuei(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, 1);
- SetShaderValuei(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, 1);
+ SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
+ SetShaderValue(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT);
+ SetShaderValue(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT);
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
Texture2D cubemap = GenTextureCubemap(shdrCubemap, texHDR, CUBEMAP_SIZE);
mat.maps[MAP_IRRADIANCE].texture = GenTextureIrradiance(shdrIrradiance, cubemap, IRRADIANCE_SIZE);
mat.maps[MAP_PREFILTER].texture = GenTexturePrefilter(shdrPrefilter, cubemap, PREFILTERED_SIZE);
- mat.maps[MAP_BRDF].texture = GenTextureBRDF(shdrBRDF, cubemap, BRDF_SIZE);
+ mat.maps[MAP_BRDF].texture = GenTextureBRDF(shdrBRDF, BRDF_SIZE);
UnloadTexture(cubemap);
UnloadTexture(texHDR);
@@ -174,14 +174,14 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
SetTextureFilter(mat.maps[MAP_OCCLUSION].texture, FILTER_BILINEAR);
// Enable sample usage in shader for assigned textures
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1]){ 1 }, 1);
- SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1]){ 1 }, 1);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
+ SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1]){ 1 }, UNIFORM_INT);
int renderModeLoc = GetShaderLocation(mat.shader, "renderMode");
- SetShaderValuei(mat.shader, renderModeLoc, (int[1]){ 0 }, 1);
+ SetShaderValue(mat.shader, renderModeLoc, (int[1]){ 0 }, UNIFORM_INT);
// Set up material properties color
mat.maps[MAP_ALBEDO].color = albedo;
diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c
index 6f6002b8..c7f76ecf 100644
--- a/examples/models/models_skybox.c
+++ b/examples/models/models_skybox.c
@@ -21,7 +21,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
// Define the camera to look into our 3d world
- Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
+ Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 4.0f, 1.0f, 4.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
// Load skybox model
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
@@ -30,11 +30,11 @@ int main()
// Load skybox shader and set required locations
// NOTE: Some locations are automatically set at shader loading
skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
- SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, 1);
+ SetShaderValue(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, UNIFORM_INT);
// Load cubemap shader and setup required shader locations
Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs");
- SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1);
+ SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT);
// Load HDR panorama (sphere) texture
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
diff --git a/examples/models/resources/shaders/brdf.fs b/examples/models/resources/shaders/brdf.fs
index 59ae384a..3e8777d2 100644
--- a/examples/models/resources/shaders/brdf.fs
+++ b/examples/models/resources/shaders/brdf.fs
@@ -1,12 +1,15 @@
/*******************************************************************************************
*
-* rPBR [shader] - Bidirectional reflectance distribution function fragment shader
+* BRDF LUT Generation - Bidirectional reflectance distribution function fragment shader
+*
+* REF: https://github.com/HectorMF/BRDFGenerator
*
* Copyright (c) 2017 Victor Fisac
*
**********************************************************************************************/
#version 330
+
#define MAX_SAMPLES 1024u
// Input vertex attributes (from vertex shader)
@@ -18,43 +21,30 @@ const float PI = 3.14159265359;
// Output fragment color
out vec4 finalColor;
-float DistributionGGX(vec3 N, vec3 H, float roughness);
-float RadicalInverse_VdC(uint bits);
vec2 Hammersley(uint i, uint N);
-vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness);
+float RadicalInverseVdC(uint bits);
float GeometrySchlickGGX(float NdotV, float roughness);
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness);
+vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness);
vec2 IntegrateBRDF(float NdotV, float roughness);
-float DistributionGGX(vec3 N, vec3 H, float roughness)
-{
- float a = roughness*roughness;
- float a2 = a*a;
- float NdotH = max(dot(N, H), 0.0);
- float NdotH2 = NdotH*NdotH;
-
- float nom = a2;
- float denom = (NdotH2*(a2 - 1.0) + 1.0);
- denom = PI*denom*denom;
-
- return nom/denom;
-}
-
-float RadicalInverse_VdC(uint bits)
+float RadicalInverseVdC(uint bits)
{
- bits = (bits << 16u) | (bits >> 16u);
- bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
- bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
- bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
- bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
- return float(bits) * 2.3283064365386963e-10; // / 0x100000000
+ bits = (bits << 16u) | (bits >> 16u);
+ bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
+ bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
+ bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
+ bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
+ return float(bits) * 2.3283064365386963e-10; // / 0x100000000
}
+// Compute Hammersley coordinates
vec2 Hammersley(uint i, uint N)
{
- return vec2(float(i)/float(N), RadicalInverse_VdC(i));
+ return vec2(float(i)/float(N), RadicalInverseVdC(i));
}
+// Integrate number of importance samples for (roughness and NoV)
vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness)
{
float a = roughness*roughness;
@@ -85,6 +75,7 @@ float GeometrySchlickGGX(float NdotV, float roughness)
return nom/denom;
}
+// Compute the geometry term for the BRDF given roughness squared, NoV, NoL
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
{
float NdotV = max(dot(N, V), 0.0);
@@ -97,29 +88,31 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
vec2 IntegrateBRDF(float NdotV, float roughness)
{
- vec3 V = vec3(sqrt(1.0 - NdotV*NdotV), 0.0, NdotV);
float A = 0.0;
- float B = 0.0;
+ float B = 0.0;
+ vec3 V = vec3(sqrt(1.0 - NdotV*NdotV), 0.0, NdotV);
vec3 N = vec3(0.0, 0.0, 1.0);
- for(uint i = 0u; i < MAX_SAMPLES; i++)
+ for (int i = 0; i < MAX_SAMPLES; i++)
{
// Generate a sample vector that's biased towards the preferred alignment direction (importance sampling)
- vec2 Xi = Hammersley(i, MAX_SAMPLES);
- vec3 H = ImportanceSampleGGX(Xi, N, roughness);
- vec3 L = normalize(2.0*dot(V, H)*H - V);
- float NdotL = max(L.z, 0.0);
- float NdotH = max(H.z, 0.0);
- float VdotH = max(dot(V, H), 0.0);
+
+ vec2 Xi = Hammersley(i, MAX_SAMPLES); // Compute a Hammersely coordinate
+ vec3 H = ImportanceSampleGGX(Xi, N, roughness); // Integrate number of importance samples for (roughness and NoV)
+ vec3 L = normalize(2.0*dot(V, H)*H - V); // Compute reflection vector L
+
+ float NdotL = max(L.z, 0.0); // Compute normal dot light
+ float NdotH = max(H.z, 0.0); // Compute normal dot half
+ float VdotH = max(dot(V, H), 0.0); // Compute view dot half
if (NdotL > 0.0)
{
- float G = GeometrySmith(N, V, L, roughness);
- float G_Vis = (G*VdotH)/(NdotH*NdotV);
- float Fc = pow(1.0 - VdotH, 5.0);
+ float G = GeometrySmith(N, V, L, roughness); // Compute the geometry term for the BRDF given roughness squared, NoV, NoL
+ float GVis = (G*VdotH)/(NdotH*NdotV); // Compute the visibility term given G, VoH, NoH, NoV, NoL
+ float Fc = pow(1.0 - VdotH, 5.0); // Compute the fresnel term given VoH
- A += (1.0 - Fc)*G_Vis;
- B += Fc*G_Vis;
+ A += (1.0 - Fc)*GVis; // Sum the result given fresnel, geometry, visibility
+ B += Fc*GVis;
}
}
diff --git a/examples/models/resources/shaders/cubemap.fs b/examples/models/resources/shaders/cubemap.fs
index 09ae62f5..e8e28536 100644
--- a/examples/models/resources/shaders/cubemap.fs
+++ b/examples/models/resources/shaders/cubemap.fs
@@ -9,7 +9,7 @@
#version 330
// Input vertex attributes (from vertex shader)
-in vec3 fragPos;
+in vec3 fragPosition;
// Input uniform values
uniform sampler2D equirectangularMap;
@@ -28,7 +28,7 @@ vec2 SampleSphericalMap(vec3 v)
void main()
{
// Normalize local position
- vec2 uv = SampleSphericalMap(normalize(fragPos));
+ vec2 uv = SampleSphericalMap(normalize(fragPosition));
// Fetch color from texture map
vec3 color = texture(equirectangularMap, uv).rgb;
diff --git a/examples/models/resources/shaders/cubemap.vs b/examples/models/resources/shaders/cubemap.vs
index 6e0bf4e1..5721eaa2 100644
--- a/examples/models/resources/shaders/cubemap.vs
+++ b/examples/models/resources/shaders/cubemap.vs
@@ -16,12 +16,12 @@ uniform mat4 projection;
uniform mat4 view;
// Output vertex attributes (to fragment shader)
-out vec3 fragPos;
+out vec3 fragPosition;
void main()
{
// Calculate fragment position based on model transformations
- fragPos = vertexPosition;
+ fragPosition = vertexPosition;
// Calculate final vertex position
gl_Position = projection*view*vec4(vertexPosition, 1.0);
diff --git a/examples/models/resources/shaders/skybox.fs b/examples/models/resources/shaders/skybox.fs
index 0bd2f320..053a2517 100644
--- a/examples/models/resources/shaders/skybox.fs
+++ b/examples/models/resources/shaders/skybox.fs
@@ -9,7 +9,7 @@
#version 330
// Input vertex attributes (from vertex shader)
-in vec3 fragPos;
+in vec3 fragPosition;
// Input uniform values
uniform samplerCube environmentMap;
@@ -20,7 +20,7 @@ out vec4 finalColor;
void main()
{
// Fetch color from texture map
- vec3 color = texture(environmentMap, fragPos).rgb;
+ vec3 color = texture(environmentMap, fragPosition).rgb;
// Apply gamma correction
color = color/(color + vec3(1.0));
diff --git a/examples/models/resources/shaders/skybox.vs b/examples/models/resources/shaders/skybox.vs
index f40d615c..dcbe6c3d 100644
--- a/examples/models/resources/shaders/skybox.vs
+++ b/examples/models/resources/shaders/skybox.vs
@@ -16,12 +16,12 @@ uniform mat4 projection;
uniform mat4 view;
// Output vertex attributes (to fragment shader)
-out vec3 fragPos;
+out vec3 fragPosition;
void main()
{
// Calculate fragment position based on model transformations
- fragPos = vertexPosition;
+ fragPosition = vertexPosition;
// Remove translation from the view matrix
mat4 rotView = mat4(mat3(view));
diff --git a/examples/models/rlights.h b/examples/models/rlights.h
index 0da3e2cb..19504473 100644
--- a/examples/models/rlights.h
+++ b/examples/models/rlights.h
@@ -158,20 +158,20 @@ Light CreateLight(int type, Vector3 pos, Vector3 targ, Color color, Shader shade
void UpdateLightValues(Shader shader, Light light)
{
// Send to shader light enabled state and type
- SetShaderValuei(shader, light.enabledLoc, (int[1]){ light.enabled }, 1);
- SetShaderValuei(shader, light.typeLoc, (int[1]){ light.type }, 1);
+ SetShaderValue(shader, light.enabledLoc, &light.enabled, UNIFORM_INT);
+ SetShaderValue(shader, light.typeLoc, &light.type, 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, 3);
+ SetShaderValue(shader, light.posLoc, position, 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, 3);
+ SetShaderValue(shader, light.targetLoc, target, UNIFORM_VEC3);
// Send to shader light color values
float diff[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, diff, 4);
+ SetShaderValue(shader, light.colorLoc, diff, UNIFORM_VEC4);
}
#endif // RLIGHTS_IMPLEMENTATION \ No newline at end of file
diff --git a/examples/others/audio_standalone.c b/examples/others/raudio_standalone.c
index d6e75066..930bde85 100644
--- a/examples/others/audio_standalone.c
+++ b/examples/others/raudio_standalone.c
@@ -1,19 +1,19 @@
/*******************************************************************************************
*
-* raylib [audio] example - Using audio module as standalone module
+* raylib [audio] example - Using raudio module as standalone module
*
* NOTE: This example does not require any graphic device, it can run directly on console.
*
* DEPENDENCIES:
* mini_al.h - Audio device management lib (http://kcat.strangesoft.net/openal.html)
-* stb_vorbis.c - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
+* stb_vorbis.h - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
* jar_xm.h - XM module file loading
* jar_mod.h - MOD audio file loading
* dr_flac.h - FLAC audio file loading
*
* COMPILATION:
* gcc -c ..\..\src\external\mini_al.c -Wall -I.
-* gcc -o audio_standalone.exe audio_standalone.c ..\..\src\audio.c ..\..\src\external\stb_vorbis.c mini_al.o /
+* gcc -o audio_standalone.exe audio_standalone.c ..\..\src\raudio.c mini_al.o /
* -I..\..\src -I..\..\src\external -L. -Wall -std=c99 /
* -DAUDIO_STANDALONE -DSUPPORT_FILEFORMAT_WAV -DSUPPORT_FILEFORMAT_OGG
*
@@ -22,7 +22,7 @@
* This example is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software:
*
-* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5)
+* Copyright (c) 2014-2019 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.
@@ -41,7 +41,7 @@
*
********************************************************************************************/
-#include "audio.h" // Audio library
+#include "raudio.h" // raylib audio library
#include <stdio.h> // Required for: printf()
diff --git a/examples/others/standard_lighting.c b/examples/others/standard_lighting.c
index 72890436..7034aa35 100644
--- a/examples/others/standard_lighting.c
+++ b/examples/others/standard_lighting.c
@@ -350,9 +350,6 @@ static void GetShaderLightsLocations(Shader shader)
// Set shader uniform values for lights
// NOTE: It would be far easier with shader UBOs but are not supported on OpenGL ES 2.0
-// TODO: Replace glUniform1i(), glUniform1f(), glUniform3f(), glUniform4f():
-//SetShaderValue(Shader shader, int uniformLoc, float *value, int size)
-//SetShaderValuei(Shader shader, int uniformLoc, int *value, int size)
static void SetShaderLightsValues(Shader shader)
{
int tempInt[8] = { 0 };
@@ -363,20 +360,20 @@ static void SetShaderLightsValues(Shader shader)
if (i < lightsCount)
{
tempInt[0] = lights[i]->enabled;
- SetShaderValuei(shader, lightsLocs[i][0], tempInt, 1); //glUniform1i(lightsLocs[i][0], lights[i]->enabled);
+ SetShaderValue(shader, lightsLocs[i][0], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][0], lights[i]->enabled);
tempInt[0] = lights[i]->type;
- SetShaderValuei(shader, lightsLocs[i][1], tempInt, 1); //glUniform1i(lightsLocs[i][1], lights[i]->type);
+ SetShaderValue(shader, lightsLocs[i][1], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][1], lights[i]->type);
tempFloat[0] = (float)lights[i]->diffuse.r/255.0f;
tempFloat[1] = (float)lights[i]->diffuse.g/255.0f;
tempFloat[2] = (float)lights[i]->diffuse.b/255.0f;
tempFloat[3] = (float)lights[i]->diffuse.a/255.0f;
- SetShaderValue(shader, lightsLocs[i][5], tempFloat, 4);
+ SetShaderValue(shader, lightsLocs[i][5], tempFloat, UNIFORM_VEC4);
//glUniform4f(lightsLocs[i][5], (float)lights[i]->diffuse.r/255, (float)lights[i]->diffuse.g/255, (float)lights[i]->diffuse.b/255, (float)lights[i]->diffuse.a/255);
tempFloat[0] = lights[i]->intensity;
- SetShaderValue(shader, lightsLocs[i][6], tempFloat, 1);
+ SetShaderValue(shader, lightsLocs[i][6], tempFloat, UNIFORM_FLOAT);
switch (lights[i]->type)
{
@@ -385,10 +382,10 @@ static void SetShaderLightsValues(Shader shader)
tempFloat[0] = lights[i]->position.x;
tempFloat[1] = lights[i]->position.y;
tempFloat[2] = lights[i]->position.z;
- SetShaderValue(shader, lightsLocs[i][2], tempFloat, 3);
+ SetShaderValue(shader, lightsLocs[i][2], tempFloat, UNIFORM_VEC3);
tempFloat[0] = lights[i]->radius;
- SetShaderValue(shader, lightsLocs[i][4], tempFloat, 1);
+ SetShaderValue(shader, lightsLocs[i][4], tempFloat, UNIFORM_FLOAT);
//glUniform3f(lightsLocs[i][2], lights[i]->position.x, lights[i]->position.y, lights[i]->position.z);
//glUniform1f(lightsLocs[i][4], lights[i]->radius);
@@ -401,7 +398,7 @@ static void SetShaderLightsValues(Shader shader)
tempFloat[0] = direction.x;
tempFloat[1] = direction.y;
tempFloat[2] = direction.z;
- SetShaderValue(shader, lightsLocs[i][3], tempFloat, 3);
+ SetShaderValue(shader, lightsLocs[i][3], tempFloat, UNIFORM_VEC3);
//glUniform3f(lightsLocs[i][3], direction.x, direction.y, direction.z);
} break;
@@ -410,7 +407,7 @@ static void SetShaderLightsValues(Shader shader)
tempFloat[0] = lights[i]->position.x;
tempFloat[1] = lights[i]->position.y;
tempFloat[2] = lights[i]->position.z;
- SetShaderValue(shader, lightsLocs[i][2], tempFloat, 3);
+ SetShaderValue(shader, lightsLocs[i][2], tempFloat, UNIFORM_VEC3);
//glUniform3f(lightsLocs[i][2], lights[i]->position.x, lights[i]->position.y, lights[i]->position.z);
@@ -420,11 +417,11 @@ static void SetShaderLightsValues(Shader shader)
tempFloat[0] = direction.x;
tempFloat[1] = direction.y;
tempFloat[2] = direction.z;
- SetShaderValue(shader, lightsLocs[i][3], tempFloat, 3);
+ SetShaderValue(shader, lightsLocs[i][3], tempFloat, UNIFORM_VEC3);
//glUniform3f(lightsLocs[i][3], direction.x, direction.y, direction.z);
tempFloat[0] = lights[i]->coneAngle;
- SetShaderValue(shader, lightsLocs[i][7], tempFloat, 1);
+ SetShaderValue(shader, lightsLocs[i][7], tempFloat, UNIFORM_FLOAT);
//glUniform1f(lightsLocs[i][7], lights[i]->coneAngle);
} break;
default: break;
@@ -433,7 +430,7 @@ static void SetShaderLightsValues(Shader shader)
else
{
tempInt[0] = 0;
- SetShaderValuei(shader, lightsLocs[i][0], tempInt, 1); //glUniform1i(lightsLocs[i][0], 0); // Light disabled
+ SetShaderValue(shader, lightsLocs[i][0], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][0], 0); // Light disabled
}
}
}
diff --git a/examples/shaders/resources/shaders/glsl100/palette-switch.fs b/examples/shaders/resources/shaders/glsl100/palette-switch.fs
new file mode 100644
index 00000000..65a7bd29
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/palette-switch.fs
@@ -0,0 +1,29 @@
+#version 100
+
+precision mediump float;
+
+const int colors = 8;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform ivec3 palette[colors];
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture(texture0, fragTexCoord) * fragColor;
+
+ // Convert the (normalized) texel color RED component (GB would work, too)
+ // to the palette index by scaling up from [0, 1] to [0, 255].
+ int index = int(texelColor.r * 255.0);
+ ivec3 color = palette[index];
+
+ // Calculate final fragment color. Note that the palette color components
+ // are defined in the range [0, 255] and need to be normalized to [0, 1]
+ // for OpenGL to work.
+ gl_FragColor = vec4(color / 255.0, texelColor.a);
+}
diff --git a/examples/shaders/resources/shaders/glsl120/palette-switch.fs b/examples/shaders/resources/shaders/glsl120/palette-switch.fs
new file mode 100644
index 00000000..b4384502
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl120/palette-switch.fs
@@ -0,0 +1,27 @@
+#version 120
+
+const int colors = 8;
+
+// Input fragment attributes (from fragment shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform ivec3 palette[colors];
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture(texture0, fragTexCoord) * fragColor;
+
+ // Convert the (normalized) texel color RED component (GB would work, too)
+ // to the palette index by scaling up from [0, 1] to [0, 255].
+ int index = int(texelColor.r * 255.0);
+ ivec3 color = palette[index];
+
+ // Calculate final fragment color. Note that the palette color components
+ // are defined in the range [0, 255] and need to be normalized to [0, 1]
+ // for OpenGL to work.
+ gl_FragColor = vec4(color / 255.0, texelColor.a);
+}
diff --git a/examples/shaders/resources/shaders/glsl330/palette-switch.fs b/examples/shaders/resources/shaders/glsl330/palette-switch.fs
new file mode 100644
index 00000000..61b532ed
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl330/palette-switch.fs
@@ -0,0 +1,30 @@
+#version 330
+
+const int colors = 8;
+
+// Input fragment attributes (from fragment shader)
+in vec2 fragTexCoord;
+in vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform ivec3 palette[colors];
+
+// Output fragment color
+out vec4 finalColor;
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture(texture0, fragTexCoord)*fragColor;
+
+ // Convert the (normalized) texel color RED component (GB would work, too)
+ // to the palette index by scaling up from [0, 1] to [0, 255].
+ int index = int(texelColor.r * 255.0);
+ ivec3 color = palette[index];
+
+ // Calculate final fragment color. Note that the palette color components
+ // are defined in the range [0, 255] and need to be normalized to [0, 1]
+ // for OpenGL to work.
+ finalColor = vec4(color / 255.0, texelColor.a);
+}
diff --git a/examples/shaders/shaders_custom_uniform.c b/examples/shaders/shaders_custom_uniform.c
index de76a376..fbfd82d0 100644
--- a/examples/shaders/shaders_custom_uniform.c
+++ b/examples/shaders/shaders_custom_uniform.c
@@ -79,7 +79,7 @@ int main()
swirlCenter[1] = screenHeight - mousePosition.y;
// Send new value to the shader to be used on drawing
- SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2);
+ SetShaderValue(shader, swirlCenterLoc, swirlCenter, UNIFORM_VEC2);
UpdateCamera(&camera); // Update camera
//----------------------------------------------------------------------------------
diff --git a/examples/shaders/shaders_palette_switch.c b/examples/shaders/shaders_palette_switch.c
new file mode 100644
index 00000000..d0b56190
--- /dev/null
+++ b/examples/shaders/shaders_palette_switch.c
@@ -0,0 +1,165 @@
+/*******************************************************************************************
+*
+* raylib [shaders] example - Color palette switch
+*
+* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
+* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
+*
+* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
+* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
+* raylib comes with shaders ready for both versions, check raylib/shaders install folder
+*
+* This example has been created using raylib 2.3 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2019 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#if defined(PLATFORM_DESKTOP)
+ #define GLSL_VERSION 330
+#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
+ #define GLSL_VERSION 100
+#endif
+
+#define MAX_PALETTES 3
+#define COLORS_PER_PALETTE 8
+#define VALUES_PER_COLOR 3
+
+static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE*VALUES_PER_COLOR] = {
+ {
+ 0, 0, 0,
+ 255, 0, 0,
+ 0, 255, 0,
+ 0, 0, 255,
+ 0, 255, 255,
+ 255, 0, 255,
+ 255, 255, 0,
+ 255, 255, 255,
+ },
+ {
+ 4, 12, 6,
+ 17, 35, 24,
+ 30, 58, 41,
+ 48, 93, 66,
+ 77, 128, 97,
+ 137, 162, 87,
+ 190, 220, 127,
+ 238, 255, 204,
+ },
+ {
+ 21, 25, 26,
+ 138, 76, 88,
+ 217, 98, 117,
+ 230, 184, 193,
+ 69, 107, 115,
+ 75, 151, 166,
+ 165, 189, 194,
+ 255, 245, 247,
+ }
+};
+
+static const char *paletteText[] = {
+ "3-BIT RGB",
+ "AMMO-8 (GameBoy-like)",
+ "RKBV (2-strip film)"
+};
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shaders] example - color palette switch");
+
+ // Load shader to be used on some parts drawing
+ // NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
+ // NOTE 2: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
+ Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/palette-switch.fs", GLSL_VERSION));
+
+ // Get variable (uniform) location on the shader to connect with the program
+ // NOTE: If uniform variable could not be found in the shader, function returns -1
+ int paletteLoc = GetShaderLocation(shader, "palette");
+
+ // Initial index not set, will be automatically bounded below.
+ int currentPalette = -1;
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ int paletteIndex = currentPalette;
+ if (IsKeyPressed(KEY_RIGHT)) paletteIndex++;
+ else if (IsKeyPressed(KEY_LEFT)) paletteIndex--;
+
+ if (paletteIndex >= MAX_PALETTES) paletteIndex = 0;
+ else if (paletteIndex < 0) paletteIndex = MAX_PALETTES - 1;
+
+ // Send new value to the shader to be used on drawing.
+ // Note that we are sending RGB triplets w/o the alpha channel *only* if the current
+ // palette index has changed (in order to save performances).
+ if (currentPalette != paletteIndex)
+ {
+ currentPalette = paletteIndex;
+ SetShaderValueV(shader, paletteLoc, palettes[currentPalette], UNIFORM_IVEC3, COLORS_PER_PALETTE);
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ BeginShaderMode(shader);
+
+ // Draw horizontal screen-wide rectangles with increasing "palette index".
+ // The used palette index is encoded in the RGB components of the pixel.
+ int linesPerRectangle = screenHeight / COLORS_PER_PALETTE;
+ int leftover = screenHeight % COLORS_PER_PALETTE;
+ int y = 0;
+
+ for (int i = 0; i < COLORS_PER_PALETTE; ++i)
+ {
+ int height = linesPerRectangle;
+
+ if (leftover > 0)
+ {
+ height += 1;
+ leftover -= 1;
+ }
+
+ DrawRectangle(0, y, screenWidth, height, (Color){ i, i, i, 255 });
+
+ y += height;
+ }
+
+ EndShaderMode();
+
+ DrawText("CURRENT PALETTE:", 10, 15, 20, RAYWHITE);
+ DrawText(paletteText[currentPalette], 240, 15, 20, RED);
+ DrawText("< >", 540, 10, 30, DARKBLUE);
+
+ DrawFPS(700, 15);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadShader(shader); // Unload shader
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/examples/shaders/shaders_raymarching.c b/examples/shaders/shaders_raymarching.c
index d1f9d5f8..79868a2a 100644
--- a/examples/shaders/shaders_raymarching.c
+++ b/examples/shaders/shaders_raymarching.c
@@ -48,7 +48,7 @@ int main()
int resolutionLoc = GetShaderLocation(shader, "resolution");
float resolution[2] = { screenWidth, screenHeight };
- SetShaderValue(shader, resolutionLoc, resolution, 2);
+ SetShaderValue(shader, resolutionLoc, resolution, UNIFORM_VEC2);
float runTime = 0.0f;
@@ -70,11 +70,11 @@ int main()
runTime += deltaTime;
// Set shader required uniform values
- SetShaderValue(shader, viewEyeLoc, cameraPos, 3);
- SetShaderValue(shader, viewCenterLoc, cameraTarget, 3);
- SetShaderValue(shader, viewUpLoc, cameraUp, 3);
- SetShaderValue(shader, deltaTimeLoc, &deltaTime, 1);
- SetShaderValue(shader, runTimeLoc, &runTime, 1);
+ SetShaderValue(shader, viewEyeLoc, cameraPos, UNIFORM_VEC3);
+ SetShaderValue(shader, viewCenterLoc, cameraTarget, UNIFORM_VEC3);
+ SetShaderValue(shader, viewUpLoc, cameraUp, UNIFORM_VEC3);
+ SetShaderValue(shader, deltaTimeLoc, &deltaTime, UNIFORM_FLOAT);
+ SetShaderValue(shader, runTimeLoc, &runTime, UNIFORM_FLOAT);
//----------------------------------------------------------------------------------
// Draw
diff --git a/examples/shapes/shapes_logo_raylib_anim.c b/examples/shapes/shapes_logo_raylib_anim.c
index c6d3796e..9be1d963 100644
--- a/examples/shapes/shapes_logo_raylib_anim.c
+++ b/examples/shapes/shapes_logo_raylib_anim.c
@@ -2,7 +2,7 @@
*
* raylib [shapes] example - raylib logo animation
*
-* This example has been created using raylib 1.4 (www.raylib.com)
+* This example has been created using raylib 2.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
@@ -140,7 +140,7 @@ int main()
DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
- DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
+ DrawText(TextSubtext("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
}
else if (state == 4)
{
diff --git a/examples/text/text_draw_inside_rectangle.c b/examples/text/text_draw_inside_rectangle.c
new file mode 100644
index 00000000..e60fa5e5
--- /dev/null
+++ b/examples/text/text_draw_inside_rectangle.c
@@ -0,0 +1,120 @@
+/*******************************************************************************************
+*
+* raylib [text] example - Draw text inside a rectangle
+*
+* This example has been created using raylib 2.3 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2018 Vlad Adrian (@demizdor)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [text] example - draw text inside a rectangle");
+
+ char text[] = "Text cannot escape\tthis container\t...word wrap also works when active so here's\
+ a long text for testing.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\
+ tempor incididunt ut labore et dolore magna aliqua. Nec ullamcorper sit amet risus nullam eget felis eget.";
+
+ bool resizing = false;
+ bool wordWrap = true;
+
+ Rectangle container = { 25, 25, screenWidth - 50, screenHeight - 250};
+ Rectangle resizer = { container.x + container.width - 17, container.y + container.height - 17, 14, 14 };
+
+ // Minimum width and heigh for the container rectangle
+ const int minWidth = 60;
+ const int minHeight = 60;
+ const int maxWidth = screenWidth - 50;
+ const int maxHeight = screenHeight - 160;
+
+ Vector2 lastMouse = { 0, 0 }; // Stores last mouse coordinates
+
+ Color borderColor = MAROON; // Container border color
+
+ Font font = GetFontDefault(); // Get default system font
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ if (IsKeyPressed(KEY_SPACE)) wordWrap = !wordWrap;
+
+ Vector2 mouse = GetMousePosition();
+
+ // Check if the mouse is inside the container and toggle border color
+ if (CheckCollisionPointRec(mouse, container)) borderColor = Fade(MAROON, 0.4f);
+ else if (!resizing) borderColor = MAROON;
+
+ // Container resizing logic
+ if (resizing)
+ {
+ if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) resizing = false;
+
+ int width = container.width + (mouse.x - lastMouse.x);
+ container.width = (width > minWidth)? ((width < maxWidth)? width : maxWidth) : minWidth;
+
+ int height = container.height + (mouse.y - lastMouse.y);
+ container.height = (height > minHeight)? ((height < maxHeight)? height : maxHeight) : minHeight;
+ }
+ else
+ {
+ // Check if we're resizing
+ if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && CheckCollisionPointRec(mouse, resizer)) resizing = true;
+ }
+
+ // Move resizer rectangle properly
+ resizer.x = container.x + container.width - 17;
+ resizer.y = container.y + container.height - 17;
+
+ lastMouse = mouse; // Update mouse
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawRectangleLinesEx(container, 3, borderColor); // Draw container border
+
+ // Draw text in container (add some padding)
+ DrawTextRec(font, text,
+ (Rectangle){ container.x + 4, container.y + 4, container.width - 4, container.height - 4 },
+ 20.0f, 2.0f, wordWrap, GRAY);
+
+ DrawRectangleRec(resizer, borderColor); // Draw the resize box
+
+ // Draw info
+ DrawText("Word Wrap: ", 313, screenHeight-115, 20, BLACK);
+ if (wordWrap) DrawText("ON", 447, screenHeight - 115, 20, RED);
+ else DrawText("OFF", 447, screenHeight - 115, 20, BLACK);
+ DrawText("Press [SPACE] to toggle word wrap", 218, screenHeight - 91, 20, GRAY);
+
+ DrawRectangle(0, screenHeight - 54, screenWidth, 54, GRAY);
+ DrawText("Click hold & drag the to resize the container", 155, screenHeight - 38, 20, RAYWHITE);
+ DrawRectangleRec((Rectangle){ 382, screenHeight - 34, 12, 12 }, MAROON);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/text/text_draw_inside_rectangle.png b/examples/text/text_draw_inside_rectangle.png
new file mode 100644
index 00000000..f46b1096
--- /dev/null
+++ b/examples/text/text_draw_inside_rectangle.png
Binary files differ
diff --git a/examples/text/text_writing_anim.c b/examples/text/text_writing_anim.c
index 5563b561..b2aba697 100644
--- a/examples/text/text_writing_anim.c
+++ b/examples/text/text_writing_anim.c
@@ -2,7 +2,7 @@
*
* raylib [text] example - Text Writing Animation
*
-* This example has been created using raylib 1.4 (www.raylib.com)
+* This example has been created using raylib 2.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
@@ -44,7 +44,7 @@ int main()
ClearBackground(RAYWHITE);
- DrawText(SubText(message, 0, framesCounter/10), 210, 160, 20, MAROON);
+ DrawText(TextSubtext(message, 0, framesCounter/10), 210, 160, 20, MAROON);
DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, LIGHTGRAY);
DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, LIGHTGRAY);
diff --git a/examples/textures/textures_image_text.c b/examples/textures/textures_image_text.c
index fb99e827..ce91fbf2 100644
--- a/examples/textures/textures_image_text.c
+++ b/examples/textures/textures_image_text.c
@@ -21,7 +21,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing");
// TTF Font loading with custom generation parameters
- Font font = LoadFontEx("resources/KAISG.ttf", 64, 95, 0);
+ Font font = LoadFontEx("resources/KAISG.ttf", 64, 0, 0);
Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM)
diff --git a/examples/textures/textures_raw_data.c b/examples/textures/textures_raw_data.c
index b038792b..481bd66a 100644
--- a/examples/textures/textures_raw_data.c
+++ b/examples/textures/textures_raw_data.c
@@ -32,8 +32,8 @@ int main()
UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data
// Generate a checked texture by code (1024x1024 pixels)
- int width = 1024;
- int height = 1024;
+ int width = 960;
+ int height = 480;
// Dynamic memory allocation to store pixels data (Color type)
Color *pixels = (Color *)malloc(width*height*sizeof(Color));
@@ -42,8 +42,8 @@ int main()
{
for (int x = 0; x < width; x++)
{
- if (((x/32+y/32)/1)%2 == 0) pixels[y*height + x] = ORANGE;
- else pixels[y*height + x] = GOLD;
+ if (((x/32+y/32)/1)%2 == 0) pixels[y*width + x] = ORANGE;
+ else pixels[y*width + x] = GOLD;
}
}
@@ -73,9 +73,9 @@ int main()
DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.5f));
DrawTexture(fudesumi, 430, -30, WHITE);
- DrawText("CHECKED TEXTURE ", 84, 100, 30, BROWN);
- DrawText("GENERATED by CODE", 72, 164, 30, BROWN);
- DrawText("and RAW IMAGE LOADING", 46, 226, 30, BROWN);
+ DrawText("CHECKED TEXTURE ", 84, 85, 30, BROWN);
+ DrawText("GENERATED by CODE", 72, 148, 30, BROWN);
+ DrawText("and RAW IMAGE LOADING", 46, 210, 30, BROWN);
DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screenHeight - 20, 10, BROWN);