summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile1
-rw-r--r--examples/Makefile.Web13
-rw-r--r--examples/shaders/resources/shaders/glsl100/lightmap.fs22
-rw-r--r--examples/shaders/resources/shaders/glsl100/lightmap.vs31
-rw-r--r--examples/shaders/resources/shaders/glsl120/lightmap.fs20
-rw-r--r--examples/shaders/resources/shaders/glsl120/lightmap.vs31
-rw-r--r--examples/shaders/shaders_lightmap.c1
-rw-r--r--examples/textures/textures_image_kernel.c127
8 files changed, 241 insertions, 5 deletions
diff --git a/examples/Makefile b/examples/Makefile
index 5cd8e6bb..11669e3a 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -490,6 +490,7 @@ TEXTURES = \
textures/textures_gif_player \
textures/textures_image_drawing \
textures/textures_image_generation \
+ textures/textures_image_kernel \
textures/textures_image_loading \
textures/textures_image_processing \
textures/textures_image_rotate \
diff --git a/examples/Makefile.Web b/examples/Makefile.Web
index e8a72661..a3c2bb72 100644
--- a/examples/Makefile.Web
+++ b/examples/Makefile.Web
@@ -396,6 +396,7 @@ TEXTURES = \
textures/textures_gif_player \
textures/textures_image_drawing \
textures/textures_image_generation \
+ textures/textures_image_kernel \
textures/textures_image_loading \
textures/textures_image_processing \
textures/textures_image_rotate \
@@ -702,6 +703,10 @@ textures/textures_image_drawing: textures/textures_image_drawing.c
textures/textures_image_generation: textures/textures_image_generation.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -s TOTAL_MEMORY=67108864
+
+textures/textures_image_kernel: textures/textures_image_kernel.c
+ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
+ --preload-file textures/resources/cat.png@resources/cat.png
textures/textures_image_loading: textures/textures_image_loading.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
@@ -968,10 +973,10 @@ shaders/shaders_julia_set: shaders/shaders_julia_set.c
shaders/shaders_lightmap: shaders/shaders_lightmap.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -s FORCE_FILESYSTEM=1 \
- --preload-file shaders/resources/shaders/glsl330/lightmap.vs \
- --preload-file shaders/resources/shaders/glsl330/lightmap.fs \
- --preload-file shaders/resources/cubicmap_atlas.png \
- --preload-file shaders/resources/spark_flame.png
+ --preload-file shaders/resources/shaders/glsl100/lightmap.vs@resources/shaders/glsl100/lightmap.vs \
+ --preload-file shaders/resources/shaders/glsl100/lightmap.fs@resources/shaders/glsl100/lightmap.fs \
+ --preload-file shaders/resources/cubicmap_atlas.png@resources/cubicmap_atlas.png \
+ --preload-file shaders/resources/spark_flame.png@resources/spark_flame.png
shaders/shaders_mesh_instancing: shaders/shaders_mesh_instancing.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
diff --git a/examples/shaders/resources/shaders/glsl100/lightmap.fs b/examples/shaders/resources/shaders/glsl100/lightmap.fs
new file mode 100644
index 00000000..9f0bcd27
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/lightmap.fs
@@ -0,0 +1,22 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec2 fragTexCoord2;
+varying vec3 fragPosition;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform sampler2D texture1;
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture2D(texture0, fragTexCoord);
+ vec4 texelColor2 = texture2D(texture1, fragTexCoord2);
+
+ gl_FragColor = texelColor * texelColor2;
+}
diff --git a/examples/shaders/resources/shaders/glsl100/lightmap.vs b/examples/shaders/resources/shaders/glsl100/lightmap.vs
new file mode 100644
index 00000000..f5d87b3e
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl100/lightmap.vs
@@ -0,0 +1,31 @@
+#version 100
+
+// Input vertex attributes
+attribute vec3 vertexPosition;
+attribute vec2 vertexTexCoord;
+attribute vec2 vertexTexCoord2;
+attribute vec4 vertexColor;
+
+// Input uniform values
+uniform mat4 mvp;
+uniform mat4 matModel;
+
+// Output vertex attributes (to fragment shader)
+varying vec3 fragPosition;
+varying vec2 fragTexCoord;
+varying vec2 fragTexCoord2;
+varying vec4 fragColor;
+
+// NOTE: Add here your custom variables
+
+void main()
+{
+ // Send vertex attributes to fragment shader
+ fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
+ fragTexCoord = vertexTexCoord;
+ fragTexCoord2 = vertexTexCoord2;
+ fragColor = vertexColor;
+
+ // Calculate final vertex position
+ gl_Position = mvp*vec4(vertexPosition, 1.0);
+}
diff --git a/examples/shaders/resources/shaders/glsl120/lightmap.fs b/examples/shaders/resources/shaders/glsl120/lightmap.fs
new file mode 100644
index 00000000..93a0609e
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl120/lightmap.fs
@@ -0,0 +1,20 @@
+#version 120
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec2 fragTexCoord2;
+varying vec3 fragPosition;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform sampler2D texture1;
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture2D(texture0, fragTexCoord);
+ vec4 texelColor2 = texture2D(texture1, fragTexCoord2);
+
+ gl_FragColor = texelColor * texelColor2;
+}
diff --git a/examples/shaders/resources/shaders/glsl120/lightmap.vs b/examples/shaders/resources/shaders/glsl120/lightmap.vs
new file mode 100644
index 00000000..9847b253
--- /dev/null
+++ b/examples/shaders/resources/shaders/glsl120/lightmap.vs
@@ -0,0 +1,31 @@
+#version 120
+
+// Input vertex attributes
+attribute vec3 vertexPosition;
+attribute vec2 vertexTexCoord;
+attribute vec2 vertexTexCoord2;
+attribute vec4 vertexColor;
+
+// Input uniform values
+uniform mat4 mvp;
+uniform mat4 matModel;
+
+// Output vertex attributes (to fragment shader)
+varying vec3 fragPosition;
+varying vec2 fragTexCoord;
+varying vec2 fragTexCoord2;
+varying vec4 fragColor;
+
+// NOTE: Add here your custom variables
+
+void main()
+{
+ // Send vertex attributes to fragment shader
+ fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
+ fragTexCoord = vertexTexCoord;
+ fragTexCoord2 = vertexTexCoord2;
+ fragColor = vertexColor;
+
+ // Calculate final vertex position
+ gl_Position = mvp*vec4(vertexPosition, 1.0);
+}
diff --git a/examples/shaders/shaders_lightmap.c b/examples/shaders/shaders_lightmap.c
index c5ed6094..445d81d2 100644
--- a/examples/shaders/shaders_lightmap.c
+++ b/examples/shaders/shaders_lightmap.c
@@ -170,4 +170,3 @@ int main(void)
return 0;
}
-
diff --git a/examples/textures/textures_image_kernel.c b/examples/textures/textures_image_kernel.c
new file mode 100644
index 00000000..cbc75e18
--- /dev/null
+++ b/examples/textures/textures_image_kernel.c
@@ -0,0 +1,127 @@
+/*******************************************************************************************
+*
+* raylib [textures] example - Image loading and texture creation
+*
+* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
+*
+* Example originally created with raylib 1.3, last time updated with raylib 1.3
+*
+* Example 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) 2015-2023 Karim Salem (@kimo-s)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+//------------------------------------------------------------------------------------
+// Program main entry point
+//------------------------------------------------------------------------------------
+void normalizeKernel(float *kernel, int size){
+ float sum = 0.0f;
+ for(int i = 0; i < size; i++)
+ {
+ sum += kernel[i];
+ }
+
+ if(sum != 0.0f)
+ {
+ for(int i = 0; i < size; i++)
+ {
+ kernel[i] /= sum;
+ }
+ }
+}
+
+int main(void)
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+
+ Image image = LoadImage("resources/cat.png"); // Loaded in CPU memory (RAM)
+
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [textures] example - image convolution");
+
+ float gaussiankernel[] = {1.0, 2.0, 1.0,
+ 2.0, 4.0, 2.0,
+ 1.0, 2.0, 1.0};
+
+ float sobelkernel[] = {1.0, 0.0, -1.0,
+ 2.0, 0.0, -2.0,
+ 1.0, 0.0, -1.0};
+
+ float sharpenkernel[] = {0.0, -1.0, 0.0,
+ -1.0, 5.0, -1.0,
+ 0.0, -1.0, 0.0};
+
+ normalizeKernel(gaussiankernel, 9);
+ normalizeKernel(sharpenkernel, 9);
+ normalizeKernel(sobelkernel, 9);
+
+ Image catSharpend = ImageCopy(image);
+ ImageKernelConvolution(&catSharpend, sharpenkernel, 9);
+
+ Image catSobel = ImageCopy(image);
+ ImageKernelConvolution(&catSobel, sobelkernel, 9);
+
+ Image catGaussian = ImageCopy(image);
+ for(int i = 0; i < 6; i++)
+ {
+ ImageKernelConvolution(&catGaussian, gaussiankernel, 9);
+ }
+
+ ImageCrop(&image, (Rectangle){ 0, 0, (float)200, (float)450 });
+ ImageCrop(&catGaussian, (Rectangle){ 0, 0, (float)200, (float)450 });
+ ImageCrop(&catSobel, (Rectangle){ 0, 0, (float)200, (float)450 });
+ ImageCrop(&catSharpend, (Rectangle){ 0, 0, (float)200, (float)450 });
+ Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
+ Texture2D catSharpendTexture = LoadTextureFromImage(catSharpend);
+ Texture2D catSobelTexture = LoadTextureFromImage(catSobel);
+ Texture2D catGaussianTexture = LoadTextureFromImage(catGaussian);
+ UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
+ UnloadImage(catGaussian);
+ UnloadImage(catSobel);
+ UnloadImage(catSharpend);
+
+ 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
+ //----------------------------------------------------------------------------------
+ // TODO: Update your variables here
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawTexture(catSharpendTexture, 0, 0, WHITE);
+ DrawTexture(catSobelTexture, 200, 0, WHITE);
+ DrawTexture(catGaussianTexture, 400, 0, WHITE);
+ DrawTexture(texture, 600, 0, WHITE);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(texture); // Texture unloading
+ UnloadTexture(catGaussianTexture);
+ UnloadTexture(catSobelTexture);
+ UnloadTexture(catSharpendTexture);
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}