WARNING: Redesigned SetShaderValue()
This commit is contained in:
parent
7c4a0f963d
commit
55f8dbc755
10 changed files with 119 additions and 97 deletions
|
@ -16,7 +16,7 @@ out vec4 finalColor;
|
|||
void main()
|
||||
{
|
||||
// Texel color fetching from texture sampler
|
||||
vec4 texelColor = texture(texture0, fragTexCoord) * fragColor;
|
||||
vec4 texelColor = texture(texture0, fragTexCoord)*fragColor;
|
||||
|
||||
// Convert the (normalized) texel color RED component (GB would work, too)
|
||||
// to the palette index by scaling up from [0, 1] to [0, 255].
|
||||
|
|
|
@ -79,7 +79,7 @@ int main()
|
|||
swirlCenter[1] = screenHeight - mousePosition.y;
|
||||
|
||||
// Send new value to the shader to be used on drawing
|
||||
SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2);
|
||||
SetShaderValue(shader, swirlCenterLoc, swirlCenter, UNIFORM_VEC2);
|
||||
|
||||
UpdateCamera(&camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [shaders] example - Apply a postprocessing shader to a scene
|
||||
* raylib [shaders] example - Color palette switch
|
||||
*
|
||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
||||
|
@ -9,10 +9,10 @@
|
|||
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||
* raylib comes with shaders ready for both versions, check raylib/shaders install folder
|
||||
*
|
||||
* This example has been created using raylib 2.x (www.raylib.com)
|
||||
* This example has been created using raylib 2.3 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2019 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
|||
#define COLORS_PER_PALETTE 8
|
||||
#define VALUES_PER_COLOR 3
|
||||
|
||||
static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE * VALUES_PER_COLOR] = {
|
||||
static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE*VALUES_PER_COLOR] = {
|
||||
{
|
||||
0, 0, 0,
|
||||
255, 0, 0,
|
||||
|
@ -74,7 +74,7 @@ int main()
|
|||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - palette-switch shader");
|
||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - color palette switch");
|
||||
|
||||
// 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
|
||||
|
@ -106,9 +106,10 @@ int main()
|
|||
// Send new value to the shader to be used on drawing.
|
||||
// Note that we are sending RGB triplets w/o the alpha channel *only* if the current
|
||||
// palette index has changed (in order to save performances).
|
||||
if (currentPalette != paletteIndex) {
|
||||
if (currentPalette != paletteIndex)
|
||||
{
|
||||
currentPalette = paletteIndex;
|
||||
SetShaderValueArrayi(shader, paletteLoc, palettes[currentPalette], VALUES_PER_COLOR, COLORS_PER_PALETTE);
|
||||
SetShaderValueV(shader, paletteLoc, palettes[currentPalette], UNIFORM_IVEC3, COLORS_PER_PALETTE);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
@ -126,14 +127,17 @@ int main()
|
|||
int leftover = screenHeight % COLORS_PER_PALETTE;
|
||||
int y = 0;
|
||||
|
||||
for (int i = 0; i < COLORS_PER_PALETTE; ++i) {
|
||||
for (int i = 0; i < COLORS_PER_PALETTE; ++i)
|
||||
{
|
||||
int height = linesPerRectangle;
|
||||
if (leftover > 0) {
|
||||
|
||||
if (leftover > 0)
|
||||
{
|
||||
height += 1;
|
||||
leftover -= 1;
|
||||
}
|
||||
|
||||
DrawRectangle(0, y, screenWidth, height, CLITERAL{ i, i, i, 255 });
|
||||
DrawRectangle(0, y, screenWidth, height, (Color){ i, i, i, 255 });
|
||||
|
||||
y += height;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ int main()
|
|||
int resolutionLoc = GetShaderLocation(shader, "resolution");
|
||||
|
||||
float resolution[2] = { screenWidth, screenHeight };
|
||||
SetShaderValue(shader, resolutionLoc, resolution, 2);
|
||||
SetShaderValue(shader, resolutionLoc, resolution, UNIFORM_VEC2);
|
||||
|
||||
float runTime = 0.0f;
|
||||
|
||||
|
@ -70,11 +70,11 @@ int main()
|
|||
runTime += deltaTime;
|
||||
|
||||
// Set shader required uniform values
|
||||
SetShaderValue(shader, viewEyeLoc, cameraPos, 3);
|
||||
SetShaderValue(shader, viewCenterLoc, cameraTarget, 3);
|
||||
SetShaderValue(shader, viewUpLoc, cameraUp, 3);
|
||||
SetShaderValue(shader, deltaTimeLoc, &deltaTime, 1);
|
||||
SetShaderValue(shader, runTimeLoc, &runTime, 1);
|
||||
SetShaderValue(shader, viewEyeLoc, cameraPos, UNIFORM_VEC3);
|
||||
SetShaderValue(shader, viewCenterLoc, cameraTarget, UNIFORM_VEC3);
|
||||
SetShaderValue(shader, viewUpLoc, cameraUp, UNIFORM_VEC3);
|
||||
SetShaderValue(shader, deltaTimeLoc, &deltaTime, UNIFORM_FLOAT);
|
||||
SetShaderValue(shader, runTimeLoc, &runTime, UNIFORM_FLOAT);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue