mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-03 12:49:17 -05:00
REVIEWED: Example shaders_normalmap, it crashes #5032
This commit is contained in:
@ -19,6 +19,7 @@
|
|||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP)
|
#if defined(PLATFORM_DESKTOP)
|
||||||
@ -34,9 +35,11 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
InitWindow(800, 450, "Normal Map");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - normal map");
|
||||||
|
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3){ 0.0f, 2.0f, -4.0f };
|
camera.position = (Vector3){ 0.0f, 2.0f, -4.0f };
|
||||||
@ -52,11 +55,12 @@ int main(void)
|
|||||||
// Get some required shader locations
|
// Get some required shader locations
|
||||||
shader.locs[SHADER_LOC_MAP_NORMAL] = GetShaderLocation(shader, "normalMap");
|
shader.locs[SHADER_LOC_MAP_NORMAL] = GetShaderLocation(shader, "normalMap");
|
||||||
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
||||||
|
|
||||||
// NOTE: "matModel" location name is automatically assigned on shader loading,
|
// NOTE: "matModel" location name is automatically assigned on shader loading,
|
||||||
// no need to get the location again if using that uniform name
|
// no need to get the location again if using that uniform name
|
||||||
// shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
// shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
||||||
|
|
||||||
// This example uses just 1 point light.
|
// This example uses just 1 point light
|
||||||
Vector3 lightPosition = { 0.0f, 1.0f, 0.0f };
|
Vector3 lightPosition = { 0.0f, 1.0f, 0.0f };
|
||||||
int lightPosLoc = GetShaderLocation(shader, "lightPos");
|
int lightPosLoc = GetShaderLocation(shader, "lightPos");
|
||||||
|
|
||||||
@ -91,7 +95,6 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Move the light around on the X and Z axis using WASD keys
|
// Move the light around on the X and Z axis using WASD keys
|
||||||
Vector3 direction = { 0 };
|
Vector3 direction = { 0 };
|
||||||
if (IsKeyDown(KEY_W)) direction = Vector3Add(direction, (Vector3){ 0.0f, 0.0f, 1.0f });
|
if (IsKeyDown(KEY_W)) direction = Vector3Add(direction, (Vector3){ 0.0f, 0.0f, 1.0f });
|
||||||
@ -145,12 +148,12 @@ int main(void)
|
|||||||
|
|
||||||
Color textColor = (useNormalMap) ? DARKGREEN : RED;
|
Color textColor = (useNormalMap) ? DARKGREEN : RED;
|
||||||
const char *toggleStr = (useNormalMap) ? "On" : "Off";
|
const char *toggleStr = (useNormalMap) ? "On" : "Off";
|
||||||
DrawText(TextFormat("Use key [N] to toggle normal map: %s", toggleStr), 10, 30, 20, textColor);
|
DrawText(TextFormat("Use key [N] to toggle normal map: %s", toggleStr), 10, 30, 10, textColor);
|
||||||
|
|
||||||
int yOffset = 24;
|
int yOffset = 24;
|
||||||
DrawText("Use keys [W][A][S][D] to move the light", 10, 30 + yOffset * 1, 20, BLACK);
|
DrawText("Use keys [W][A][S][D] to move the light", 10, 30 + yOffset*1, 10, BLACK);
|
||||||
DrawText("Use keys [Up][Down] to change specular exponent", 10, 30 + yOffset * 2, 20, BLACK);
|
DrawText("Use keys [Up][Down] to change specular exponent", 10, 30 + yOffset*2, 10, BLACK);
|
||||||
DrawText(TextFormat("Specular Exponent: %.2f", specularExponent), 10, 30 + yOffset * 3, 20, BLUE);
|
DrawText(TextFormat("Specular Exponent: %.2f", specularExponent), 10, 30 + yOffset*3, 10, BLUE);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Module functions declaration
|
// Module functions declaration
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
void NormalizeKernel(float *kernel, int size);
|
static void NormalizeKernel(float *kernel, int size);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
|
|||||||
Reference in New Issue
Block a user