Skip to content

Commit 54473e2

Browse files
committed
REVIEWED: Example shaders_normalmap, it crashes #5032
1 parent 47d1cc2 commit 54473e2

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

examples/shaders/shaders_normalmap.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
********************************************************************************************/
2020

2121
#include <raylib.h>
22+
2223
#include <raymath.h>
2324

2425
#if defined(PLATFORM_DESKTOP)
25-
#define GLSL_VERSION 330
26-
#else // PLATFORM_ANDROID, PLATFORM_WEB
27-
#define GLSL_VERSION 100
26+
#define GLSL_VERSION 330
27+
#else // PLATFORM_ANDROID, PLATFORM_WEB
28+
#define GLSL_VERSION 100
2829
#endif
2930

3031
//------------------------------------------------------------------------------------
@@ -34,14 +35,16 @@ int main(void)
3435
{
3536
// Initialization
3637
//--------------------------------------------------------------------------------------
38+
const int screenWidth = 800;
39+
const int screenHeight = 450;
3740

3841
SetConfigFlags(FLAG_MSAA_4X_HINT);
39-
InitWindow(800, 450, "Normal Map");
42+
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - normal map");
4043

41-
Camera camera = {0};
42-
camera.position = (Vector3){0.0f, 2.0f, -4.0f};
43-
camera.target = (Vector3){0.0f, 0.0f, 0.0f};
44-
camera.up = (Vector3){0.0f, 1.0f, 0.0f};
44+
Camera camera = { 0 };
45+
camera.position = (Vector3){ 0.0f, 2.0f, -4.0f };
46+
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
47+
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
4548
camera.fovy = 45.0f;
4649
camera.projection = CAMERA_PERSPECTIVE;
4750

@@ -52,12 +55,13 @@ int main(void)
5255
// Get some required shader locations
5356
shader.locs[SHADER_LOC_MAP_NORMAL] = GetShaderLocation(shader, "normalMap");
5457
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
58+
5559
// NOTE: "matModel" location name is automatically assigned on shader loading,
5660
// no need to get the location again if using that uniform name
5761
// shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
5862

59-
// This example uses just 1 point light.
60-
Vector3 lightPosition = {0.0f, 1.0f, 0.0f};
63+
// This example uses just 1 point light
64+
Vector3 lightPosition = { 0.0f, 1.0f, 0.0f };
6165
int lightPosLoc = GetShaderLocation(shader, "lightPos");
6266

6367
// Load a plane model that has proper normals and tangents
@@ -91,26 +95,25 @@ int main(void)
9195
{
9296
// Update
9397
//----------------------------------------------------------------------------------
94-
9598
// Move the light around on the X and Z axis using WASD keys
96-
Vector3 direction = {0};
97-
if (IsKeyDown(KEY_W)) direction = Vector3Add(direction, (Vector3){0.0f, 0.0f, 1.0f});
98-
if (IsKeyDown(KEY_S)) direction = Vector3Add(direction, (Vector3){0.0f, 0.0f, -1.0f});
99-
if (IsKeyDown(KEY_D)) direction = Vector3Add(direction, (Vector3){-1.0f, 0.0f, 0.0f});
100-
if (IsKeyDown(KEY_A)) direction = Vector3Add(direction, (Vector3){1.0f, 0.0f, 0.0f});
99+
Vector3 direction = { 0 };
100+
if (IsKeyDown(KEY_W)) direction = Vector3Add(direction, (Vector3){ 0.0f, 0.0f, 1.0f });
101+
if (IsKeyDown(KEY_S)) direction = Vector3Add(direction, (Vector3){ 0.0f, 0.0f, -1.0f });
102+
if (IsKeyDown(KEY_D)) direction = Vector3Add(direction, (Vector3){ -1.0f, 0.0f, 0.0f });
103+
if (IsKeyDown(KEY_A)) direction = Vector3Add(direction, (Vector3){ 1.0f, 0.0f, 0.0f });
101104

102105
direction = Vector3Normalize(direction);
103-
lightPosition = Vector3Add(lightPosition, Vector3Scale(direction, GetFrameTime() * 3.0f));
106+
lightPosition = Vector3Add(lightPosition, Vector3Scale(direction, GetFrameTime()*3.0f));
104107

105108
// Increase/Decrease the specular exponent(shininess)
106-
if (IsKeyDown(KEY_UP)) specularExponent = Clamp(specularExponent + 40.0f * GetFrameTime(), 2.0f, 128.0f);
107-
if (IsKeyDown(KEY_DOWN)) specularExponent = Clamp(specularExponent - 40.0f * GetFrameTime(), 2.0f, 128.0f);
109+
if (IsKeyDown(KEY_UP)) specularExponent = Clamp(specularExponent + 40.0f*GetFrameTime(), 2.0f, 128.0f);
110+
if (IsKeyDown(KEY_DOWN)) specularExponent = Clamp(specularExponent - 40.0f*GetFrameTime(), 2.0f, 128.0f);
108111

109112
// Toggle normal map on and off
110113
if (IsKeyPressed(KEY_N)) useNormalMap = !useNormalMap;
111114

112115
// Spin plane model at a constant rate
113-
plane.transform = MatrixRotateY(GetTime() * 0.5f);
116+
plane.transform = MatrixRotateY(GetTime()*0.5f);
114117

115118
// Update shader values
116119
float lightPos[3] = {lightPosition.x, lightPosition.y, lightPosition.z};
@@ -138,19 +141,19 @@ int main(void)
138141

139142
EndShaderMode();
140143

141-
//Draw sphere to show light position
144+
// Draw sphere to show light position
142145
DrawSphereWires(lightPosition, 0.2f, 8, 8, ORANGE);
143146

144147
EndMode3D();
145148

146149
Color textColor = (useNormalMap) ? DARKGREEN : RED;
147150
const char *toggleStr = (useNormalMap) ? "On" : "Off";
148-
DrawText(TextFormat("Use key [N] to toggle normal map: %s", toggleStr), 10, 30, 20, textColor);
151+
DrawText(TextFormat("Use key [N] to toggle normal map: %s", toggleStr), 10, 30, 10, textColor);
149152

150153
int yOffset = 24;
151-
DrawText("Use keys [W][A][S][D] to move the light", 10, 30 + yOffset * 1, 20, BLACK);
152-
DrawText("Use keys [Up][Down] to change specular exponent", 10, 30 + yOffset * 2, 20, BLACK);
153-
DrawText(TextFormat("Specular Exponent: %.2f", specularExponent), 10, 30 + yOffset * 3, 20, BLUE);
154+
DrawText("Use keys [W][A][S][D] to move the light", 10, 30 + yOffset*1, 10, BLACK);
155+
DrawText("Use keys [Up][Down] to change specular exponent", 10, 30 + yOffset*2, 10, BLACK);
156+
DrawText(TextFormat("Specular Exponent: %.2f", specularExponent), 10, 30 + yOffset*3, 10, BLUE);
154157

155158
DrawFPS(10, 10);
156159

examples/textures/textures_image_kernel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//------------------------------------------------------------------------------------
2323
// Module functions declaration
2424
//------------------------------------------------------------------------------------
25-
void NormalizeKernel(float *kernel, int size);
25+
static void NormalizeKernel(float *kernel, int size);
2626

2727
//------------------------------------------------------------------------------------
2828
// Program main entry point

0 commit comments

Comments
 (0)