examples review

This commit is contained in:
Ray 2019-05-17 01:17:40 +02:00
parent ce87d2ced4
commit 970f1e8ff1
19 changed files with 64 additions and 36 deletions

View file

@ -81,7 +81,7 @@ int main()
// Load shader to be used on some parts drawing
// NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
// NOTE 2: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/palette-switch.fs", GLSL_VERSION));
Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/palette_switch.fs", GLSL_VERSION));
// Get variable (uniform) location on the shader to connect with the program
// NOTE: If uniform variable could not be found in the shader, function returns -1

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -38,22 +38,19 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture waves");
// Load space texture to apply shaders
Texture2D space = LoadTexture("resources/space.png");
// Load texture texture to apply shaders
Texture2D texture = LoadTexture("resources/space.png");
// Load shader and setup location points and values
Shader wave = LoadShader(0, FormatText("resources/shaders/glsl%i/wave.fs", GLSL_VERSION));
Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/wave.fs", GLSL_VERSION));
float screenSizeLoc = GetShaderLocation(wave, "size");
float secondsLoc = GetShaderLocation(wave, "secondes");
float freqXLoc = GetShaderLocation(wave, "freqX");
float freqYLoc = GetShaderLocation(wave, "freqY");
float ampXLoc = GetShaderLocation(wave, "ampX");
float ampYLoc = GetShaderLocation(wave, "ampY");
float speedXLoc = GetShaderLocation(wave, "speedX");
float speedYLoc = GetShaderLocation(wave, "speedY");
float screenSize[2] = { 800, 450 };
int secondsLoc = GetShaderLocation(shader, "secondes");
int freqXLoc = GetShaderLocation(shader, "freqX");
int freqYLoc = GetShaderLocation(shader, "freqY");
int ampXLoc = GetShaderLocation(shader, "ampX");
int ampYLoc = GetShaderLocation(shader, "ampY");
int speedXLoc = GetShaderLocation(shader, "speedX");
int speedYLoc = GetShaderLocation(shader, "speedY");
// Shader uniform values that can be updated at any time
float freqX = 25.0f;
@ -63,13 +60,14 @@ int main()
float speedX = 8.0f;
float speedY = 8.0f;
SetShaderValue(wave, screenSizeLoc, &screenSize, UNIFORM_VEC2);
SetShaderValue(wave, freqXLoc, &freqX, UNIFORM_FLOAT);
SetShaderValue(wave, freqYLoc, &freqY, UNIFORM_FLOAT);
SetShaderValue(wave, ampXLoc, &ampX, UNIFORM_FLOAT);
SetShaderValue(wave, ampYLoc, &ampY, UNIFORM_FLOAT);
SetShaderValue(wave, speedXLoc, &speedX, UNIFORM_FLOAT);
SetShaderValue(wave, speedYLoc, &speedY, UNIFORM_FLOAT);
float screenSize[2] = { (float)GetScreenWidth(), (float)GetScreenHeight() };
SetShaderValue(shader, GetShaderLocation(shader, "size"), &screenSize, UNIFORM_VEC2);
SetShaderValue(shader, freqXLoc, &freqX, UNIFORM_FLOAT);
SetShaderValue(shader, freqYLoc, &freqY, UNIFORM_FLOAT);
SetShaderValue(shader, ampXLoc, &ampX, UNIFORM_FLOAT);
SetShaderValue(shader, ampYLoc, &ampY, UNIFORM_FLOAT);
SetShaderValue(shader, speedXLoc, &speedX, UNIFORM_FLOAT);
SetShaderValue(shader, speedYLoc, &speedY, UNIFORM_FLOAT);
float seconds = 0.0f;
@ -83,7 +81,7 @@ int main()
//----------------------------------------------------------------------------------
seconds += GetFrameTime();
SetShaderValue(wave, secondsLoc, &seconds, UNIFORM_FLOAT);
SetShaderValue(shader, secondsLoc, &seconds, UNIFORM_FLOAT);
//----------------------------------------------------------------------------------
// Draw
@ -92,10 +90,10 @@ int main()
ClearBackground(RAYWHITE);
BeginShaderMode(wave);
BeginShaderMode(shader);
DrawTexture(space, 0, 0, WHITE);
DrawTexture(space, space.width, 0, WHITE);
DrawTexture(texture, 0, 0, WHITE);
DrawTexture(texture, texture.width, 0, WHITE);
EndShaderMode();
@ -105,8 +103,8 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadShader(wave); // Unload shader
UnloadTexture(space); // Unload texture
UnloadShader(shader); // Unload shader
UnloadTexture(texture); // Unload texture
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------