summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2017-05-16 15:23:01 +0200
committerRay <[email protected]>2017-05-16 15:23:01 +0200
commita5bfd7db228b90b5ddc183a03e1f0630d7321091 (patch)
treebf3bdc6d20e55e7a54c72e426245156b75f30c15
parente563ebe240c16c142157c3d21df50c72fe27ff14 (diff)
downloadraylib-a5bfd7db228b90b5ddc183a03e1f0630d7321091.tar.gz
raylib-a5bfd7db228b90b5ddc183a03e1f0630d7321091.zip
Some reviews for RPI
-rw-r--r--docs/examples/src/shaders/shaders_postprocessing.c89
-rw-r--r--docs/examples/web/shaders/shaders_postprocessing.pngbin237145 -> 193424 bytes
-rw-r--r--examples/Makefile15
-rw-r--r--examples/models/models_mesh_picking.c26
-rw-r--r--examples/shaders/shaders_postprocessing.pngbin237145 -> 193424 bytes
-rw-r--r--examples/text/text_ttf_loading.c10
-rw-r--r--src/physac.h4
7 files changed, 113 insertions, 31 deletions
diff --git a/docs/examples/src/shaders/shaders_postprocessing.c b/docs/examples/src/shaders/shaders_postprocessing.c
index 43d1af72..bb239efa 100644
--- a/docs/examples/src/shaders/shaders_postprocessing.c
+++ b/docs/examples/src/shaders/shaders_postprocessing.c
@@ -18,6 +18,48 @@
#include "raylib.h"
+#if defined(PLATFORM_DESKTOP)
+ #define GLSL_VERSION 330
+ #define DEFAULT_VERTEX_SHADER "resources/shaders/glsl330/base.vs"
+#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
+ #define GLSL_VERSION 100
+ #define DEFAULT_VERTEX_SHADER "resources/shaders/glsl100/base.vs"
+#endif
+
+#define MAX_POSTPRO_SHADERS 12
+
+typedef enum {
+ FX_GRAYSCALE = 0,
+ FX_POSTERIZATION,
+ FX_DREAM_VISION,
+ FX_PIXELIZER,
+ FX_CROSS_HATCHING,
+ FX_CROSS_STITCHING,
+ FX_PREDATOR_VIEW,
+ FX_SCANLINES,
+ FX_FISHEYE,
+ FX_SOBEL,
+ FX_BLOOM,
+ FX_BLUR,
+ //FX_FXAA
+} PostproShader;
+
+static const char *postproShaderText[] = {
+ "GRAYSCALE",
+ "POSTERIZATION",
+ "DREAM_VISION",
+ "PIXELIZER",
+ "CROSS_HATCHING",
+ "CROSS_STITCHING",
+ "PREDATOR_VIEW",
+ "SCANLINES",
+ "FISHEYE",
+ "SOBEL",
+ "BLOOM",
+ "BLUR",
+ //"FXAA"
+};
+
int main()
{
// Initialization
@@ -38,8 +80,25 @@ int main()
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
- Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
- "resources/shaders/glsl330/bloom.fs"); // Load postpro shader
+ // Load all postpro shaders
+ // NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER)
+ // NOTE 2: We load the correct shader depending on GLSL version
+ Shader shaders[MAX_POSTPRO_SHADERS];
+
+ shaders[FX_GRAYSCALE] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION));
+ shaders[FX_POSTERIZATION] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/posterization.fs", GLSL_VERSION));
+ shaders[FX_DREAM_VISION] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/dream_vision.fs", GLSL_VERSION));
+ shaders[FX_PIXELIZER] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/pixelizer.fs", GLSL_VERSION));
+ shaders[FX_CROSS_HATCHING] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/cross_hatching.fs", GLSL_VERSION));
+ shaders[FX_CROSS_STITCHING] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/cross_stitching.fs", GLSL_VERSION));
+ shaders[FX_PREDATOR_VIEW] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/predator.fs", GLSL_VERSION));
+ shaders[FX_SCANLINES] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/scanlines.fs", GLSL_VERSION));
+ shaders[FX_FISHEYE] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/fisheye.fs", GLSL_VERSION));
+ shaders[FX_SOBEL] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/sobel.fs", GLSL_VERSION));
+ shaders[FX_BLOOM] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/bloom.fs", GLSL_VERSION));
+ shaders[FX_BLUR] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/blur.fs", GLSL_VERSION));
+
+ int currentShader = FX_GRAYSCALE;
// Create a RenderTexture2D to be used for render to texture
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
@@ -56,6 +115,12 @@ int main()
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update camera
+
+ if (IsKeyPressed(KEY_RIGHT)) currentShader++;
+ else if (IsKeyPressed(KEY_LEFT)) currentShader--;
+
+ if (currentShader >= MAX_POSTPRO_SHADERS) currentShader = 0;
+ else if (currentShader < 0) currentShader = MAX_POSTPRO_SHADERS - 1;
//----------------------------------------------------------------------------------
// Draw
@@ -73,21 +138,26 @@ int main()
DrawGrid(10, 1.0f); // Draw a grid
End3dMode();
-
- DrawText("HELLO POSTPROCESSING!", 70, 190, 50, RED);
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
- BeginShaderMode(shader);
+ // Render previously generated texture using selected postpro shader
+ BeginShaderMode(shaders[currentShader]);
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
EndShaderMode();
+ DrawRectangle(0, 9, 580, 30, Fade(LIGHTGRAY, 0.7f));
+
DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, DARKGRAY);
-
- DrawFPS(10, 10);
+
+ DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, BLACK);
+ DrawText(postproShaderText[currentShader], 330, 15, 20, RED);
+ DrawText("< >", 540, 10, 30, DARKBLUE);
+
+ DrawFPS(700, 15);
EndDrawing();
//----------------------------------------------------------------------------------
@@ -95,7 +165,10 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
- UnloadShader(shader); // Unload shader
+
+ // Unload all postpro shaders
+ for (int i = 0; i < MAX_POSTPRO_SHADERS; i++) UnloadShader(shaders[i]);
+
UnloadTexture(texture); // Unload texture
UnloadModel(dwarf); // Unload model
UnloadRenderTexture(target); // Unload render texture
diff --git a/docs/examples/web/shaders/shaders_postprocessing.png b/docs/examples/web/shaders/shaders_postprocessing.png
index 684cbd41..628ab810 100644
--- a/docs/examples/web/shaders/shaders_postprocessing.png
+++ b/docs/examples/web/shaders/shaders_postprocessing.png
Binary files differ
diff --git a/examples/Makefile b/examples/Makefile
index c3728b3b..969edd0c 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -162,9 +162,9 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(PLATFORM_OS),WINDOWS)
# external libraries to link with
# GLFW3
- LFLAGS += -L$(RAYLIB_PATH)/src/external/glfw3/lib/$(LIBPATH)
+ LFLAGS += -L$(RAYLIB_PATH)/src/external/glfw3/lib/$(LIBPATH)
# OpenAL Soft
- LFLAGS += -L$(RAYLIB_PATH)/src/external/openal_soft/lib/$(LIBPATH)
+ LFLAGS += -L$(RAYLIB_PATH)/src/external/openal_soft/lib/$(LIBPATH)
endif
endif
@@ -195,6 +195,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
else
LIBS += -lopenal32dll
endif
+ PHYSAC_LIBS = -static -lpthread
endif
endif
endif
@@ -524,23 +525,23 @@ audio/audio_raw_stream: audio/audio_raw_stream.c
# compile [physac] example - physics demo
physac/physics_demo: physac/physics_demo.c
- $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -static -lpthread -D$(PLATFORM) $(WINFLAGS)
+ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) $(PHYSAC_LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [physac] example - physics friction
physac/physics_friction: physac/physics_friction.c
- $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -static -lpthread -D$(PLATFORM) $(WINFLAGS)
+ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) $(PHYSAC_LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [physac] example - physics movement
physac/physics_movement: physac/physics_movement.c
- $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -static -lpthread -D$(PLATFORM) $(WINFLAGS)
+ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) $(PHYSAC_LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [physac] example - physics restitution
physac/physics_restitution: physac/physics_restitution.c
- $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -static -lpthread -D$(PLATFORM) $(WINFLAGS)
+ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) $(PHYSAC_LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [physac] example - physics shatter
physac/physics_shatter: physac/physics_shatter.c
- $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -static -lpthread -D$(PLATFORM) $(WINFLAGS)
+ $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) $(PHYSAC_LIBS) -D$(PLATFORM) $(WINFLAGS)
ifeq ($(PLATFORM),PLATFORM_ANDROID)
external/native_app_glue.o : native_app_glue.c native_app_glue.h
diff --git a/examples/models/models_mesh_picking.c b/examples/models/models_mesh_picking.c
index 0b5247ec..ec151599 100644
--- a/examples/models/models_mesh_picking.c
+++ b/examples/models/models_mesh_picking.c
@@ -89,7 +89,7 @@ int main()
cursorColor = PURPLE;
hitObjectName = "Triangle";
- bary = VectorBarycenter(nearestHit.hitPosition, ta, tb, tc);
+ bary = VectorBarycenter(nearestHit.position, ta, tb, tc);
hitTriangle = true;
}
else hitTriangle = false;
@@ -136,15 +136,15 @@ int main()
// If we hit something, draw the cursor at the hit point
if (nearestHit.hit)
{
- DrawCube(nearestHit.hitPosition, 0.3, 0.3, 0.3, cursorColor);
- DrawCubeWires(nearestHit.hitPosition, 0.3, 0.3, 0.3, RED);
+ DrawCube(nearestHit.position, 0.3, 0.3, 0.3, cursorColor);
+ DrawCubeWires(nearestHit.position, 0.3, 0.3, 0.3, RED);
Vector3 normalEnd;
- normalEnd.x = nearestHit.hitPosition.x + nearestHit.hitNormal.x;
- normalEnd.y = nearestHit.hitPosition.y + nearestHit.hitNormal.y;
- normalEnd.z = nearestHit.hitPosition.z + nearestHit.hitNormal.z;
+ normalEnd.x = nearestHit.position.x + nearestHit.normal.x;
+ normalEnd.y = nearestHit.position.y + nearestHit.normal.y;
+ normalEnd.z = nearestHit.position.z + nearestHit.normal.z;
- DrawLine3D(nearestHit.hitPosition, normalEnd, RED);
+ DrawLine3D(nearestHit.position, normalEnd, RED);
}
DrawRay(ray, MAROON);
@@ -163,14 +163,14 @@ int main()
DrawText(FormatText("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK);
DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f",
- nearestHit.hitPosition.x,
- nearestHit.hitPosition.y,
- nearestHit.hitPosition.z), 10, ypos + 15, 10, BLACK);
+ nearestHit.position.x,
+ nearestHit.position.y,
+ nearestHit.position.z), 10, ypos + 15, 10, BLACK);
DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f",
- nearestHit.hitNormal.x,
- nearestHit.hitNormal.y,
- nearestHit.hitNormal.z), 10, ypos + 30, 10, BLACK);
+ nearestHit.normal.x,
+ nearestHit.normal.y,
+ nearestHit.normal.z), 10, ypos + 30, 10, BLACK);
if (hitTriangle) DrawText(FormatText("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK);
}
diff --git a/examples/shaders/shaders_postprocessing.png b/examples/shaders/shaders_postprocessing.png
index 684cbd41..628ab810 100644
--- a/examples/shaders/shaders_postprocessing.png
+++ b/examples/shaders/shaders_postprocessing.png
Binary files differ
diff --git a/examples/text/text_ttf_loading.c b/examples/text/text_ttf_loading.c
index 02b7f95f..c9c2fb27 100644
--- a/examples/text/text_ttf_loading.c
+++ b/examples/text/text_ttf_loading.c
@@ -38,8 +38,11 @@ int main()
SetTextureFilter(font.texture, FILTER_POINT);
int currentFontFilter = 0; // FILTER_POINT
+ // NOTE: Drag and drop support only available for desktop platforms: Windows, Linux, OSX
+#if defined(PLATFORM_DESKTOP)
int count = 0;
char **droppedFiles;
+#endif
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@@ -74,6 +77,7 @@ int main()
if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10;
else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10;
+#if defined(PLATFORM_DESKTOP)
// Load a dropped TTF file dynamically (at current fontSize)
if (IsFileDropped())
{
@@ -86,6 +90,7 @@ int main()
ClearDroppedFiles();
}
}
+#endif
//----------------------------------------------------------------------------------
// Draw
@@ -119,10 +124,11 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
+#if defined(PLATFORM_DESKTOP)
+ ClearDroppedFiles(); // Clear internal buffers
+#endif
UnloadSpriteFont(font); // SpriteFont unloading
- ClearDroppedFiles(); // Clear internal buffers
-
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
diff --git a/src/physac.h b/src/physac.h
index b71f2877..d3fdaca4 100644
--- a/src/physac.h
+++ b/src/physac.h
@@ -246,12 +246,14 @@ PHYSACDEF void ClosePhysics(void);
#include <stdlib.h> // Required for: malloc(), free(), srand(), rand()
#include <math.h> // Required for: cosf(), sinf(), fabs(), sqrtf()
+#include "raymath.h" // Required for: Vector2Add(), Vector2Subtract()
+
#if defined(_WIN32)
// Functions required to query time on Windows
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
#elif defined(__linux__) || defined(PLATFORM_WEB)
- #define _DEFAULT_SOURCE // Enables BSD function definitions and C99 POSIX compliance
+ //#define _DEFAULT_SOURCE // Enables BSD function definitions and C99 POSIX compliance
#include <sys/time.h> // Required for: timespec
#include <time.h> // Required for: clock_gettime()
#include <stdint.h>