summaryrefslogtreecommitdiffhomepage
path: root/examples/web/shaders/shaders_postprocessing.c
diff options
context:
space:
mode:
authorRay <[email protected]>2019-05-20 16:40:30 +0200
committerRay <[email protected]>2019-05-20 16:40:30 +0200
commit3d7d174c70b2d00fd879ade64c5085d4ff34d4aa (patch)
tree3b690948f186f855aa2ee8bab312b3ca28a56200 /examples/web/shaders/shaders_postprocessing.c
parent0b56b996bd053ec875c229e9793f7806b666839c (diff)
downloadraylib.com-3d7d174c70b2d00fd879ade64c5085d4ff34d4aa.tar.gz
raylib.com-3d7d174c70b2d00fd879ade64c5085d4ff34d4aa.zip
Review and recompile ALL examples
Diffstat (limited to 'examples/web/shaders/shaders_postprocessing.c')
-rw-r--r--examples/web/shaders/shaders_postprocessing.c93
1 files changed, 47 insertions, 46 deletions
diff --git a/examples/web/shaders/shaders_postprocessing.c b/examples/web/shaders/shaders_postprocessing.c
index 5b5aec2..10ce35d 100644
--- a/examples/web/shaders/shaders_postprocessing.c
+++ b/examples/web/shaders/shaders_postprocessing.c
@@ -24,10 +24,8 @@
#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
@@ -67,21 +65,21 @@ static const char *postproShaderText[] = {
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
-int screenWidth = 800;
-int screenHeight = 450;
+const int screenWidth = 800;
+const int screenHeight = 450;
// Define the camera to look into our 3d world
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
-Model dwarf; // OBJ model
-Texture2D texture; // Model texture
+Model model = { 0 }; // OBJ model
+Texture2D texture = { 0 }; // Model texture
-Shader shaders[MAX_POSTPRO_SHADERS]; // Postpro shaders
-int currentShader = FX_GRAYSCALE; // Current shader selected
+Shader shaders[MAX_POSTPRO_SHADERS] = { 0 }; // Postpro shaders
+int currentShader = FX_GRAYSCALE = { 0 }; // Current shader selected
-Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
+Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
-RenderTexture2D target;
+RenderTexture2D target = { 0 };
//----------------------------------------------------------------------------------
// Module Functions Declaration
@@ -89,7 +87,7 @@ RenderTexture2D target;
void UpdateDrawFrame(void); // Update and Draw one frame
//----------------------------------------------------------------------------------
-// Main Enry Point
+// Program Main Entry Point
//----------------------------------------------------------------------------------
int main(void)
{
@@ -98,29 +96,29 @@ int main(void)
SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available)
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader");
- dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
- texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
- dwarf.material.maps[MAP_DIFFUSE].texture = texture; // Set dwarf model diffuse texture
+ model = LoadModel("resources/models/church.obj"); // Load OBJ model
+ texture = LoadTexture("resources/models/church_diffuse.png"); // Load model texture
+ model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set model diffuse texture
// 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
- 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));
+ shaders[FX_GRAYSCALE] = LoadShader(0, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION));
+ shaders[FX_POSTERIZATION] = LoadShader(0, FormatText("resources/shaders/glsl%i/posterization.fs", GLSL_VERSION));
+ shaders[FX_DREAM_VISION] = LoadShader(0, FormatText("resources/shaders/glsl%i/dream_vision.fs", GLSL_VERSION));
+ shaders[FX_PIXELIZER] = LoadShader(0, FormatText("resources/shaders/glsl%i/pixelizer.fs", GLSL_VERSION));
+ shaders[FX_CROSS_HATCHING] = LoadShader(0, FormatText("resources/shaders/glsl%i/cross_hatching.fs", GLSL_VERSION));
+ shaders[FX_CROSS_STITCHING] = LoadShader(0, FormatText("resources/shaders/glsl%i/cross_stitching.fs", GLSL_VERSION));
+ shaders[FX_PREDATOR_VIEW] = LoadShader(0, FormatText("resources/shaders/glsl%i/predator.fs", GLSL_VERSION));
+ shaders[FX_SCANLINES] = LoadShader(0, FormatText("resources/shaders/glsl%i/scanlines.fs", GLSL_VERSION));
+ shaders[FX_FISHEYE] = LoadShader(0, FormatText("resources/shaders/glsl%i/fisheye.fs", GLSL_VERSION));
+ shaders[FX_SOBEL] = LoadShader(0, FormatText("resources/shaders/glsl%i/sobel.fs", GLSL_VERSION));
+ shaders[FX_BLOOM] = LoadShader(0, FormatText("resources/shaders/glsl%i/bloom.fs", GLSL_VERSION));
+ shaders[FX_BLUR] = LoadShader(0, FormatText("resources/shaders/glsl%i/blur.fs", GLSL_VERSION));
// Create a RenderTexture2D to be used for render to texture
target = LoadRenderTexture(screenWidth, screenHeight);
-
+
// Setup orbital camera
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
@@ -129,7 +127,7 @@ int main(void)
#else
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
-
+
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
@@ -139,12 +137,12 @@ int main(void)
// De-Initialization
//--------------------------------------------------------------------------------------
-
+
// Unload all postpro shaders
for (int i = 0; i < MAX_POSTPRO_SHADERS; i++) UnloadShader(shaders[i]);
-
+
UnloadTexture(texture); // Unload texture
- UnloadModel(dwarf); // Unload model
+ UnloadModel(model); // Unload model
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
@@ -160,10 +158,10 @@ void UpdateDrawFrame(void)
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update internal camera and our 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;
//----------------------------------------------------------------------------------
@@ -174,34 +172,37 @@ void UpdateDrawFrame(void)
ClearBackground(RAYWHITE);
- BeginTextureMode(target); // Enable drawing to texture
+ BeginTextureMode(target); // Enable drawing to texture
- Begin3dMode(camera);
+ ClearBackground(RAYWHITE); // Clear texture background
- DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
+ BeginMode3D(camera); // Begin 3d mode drawing
+
+ DrawModel(model, position, 0.1f, WHITE); // Draw 3d model with texture
DrawGrid(10, 1.0f); // Draw a grid
- End3dMode();
-
+ EndMode3D(); // End 3d mode drawing, returns to orthographic 2d mode
+
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
-
+
// 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();
-
+
+ // Draw 2d shapes and text over drawn texture
DrawRectangle(0, 9, 580, 30, Fade(LIGHTGRAY, 0.7f));
-
- DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, DARKGRAY);
-
+
+ DrawText("(c) Church 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
+
DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, BLACK);
DrawText(postproShaderText[currentShader], 330, 15, 20, RED);
DrawText("< >", 540, 10, 30, DARKBLUE);
-
+
DrawFPS(700, 15);
EndDrawing();