Example review
This commit is contained in:
parent
3e0e91013f
commit
2ddc4bacba
4 changed files with 106 additions and 126 deletions
|
@ -29,7 +29,7 @@
|
|||
#define VALUES_PER_COLOR 3
|
||||
|
||||
static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE*VALUES_PER_COLOR] = {
|
||||
{
|
||||
{ // 3-BIT RGB
|
||||
0, 0, 0,
|
||||
255, 0, 0,
|
||||
0, 255, 0,
|
||||
|
@ -39,7 +39,7 @@ static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE*VALUES_PER_COLOR] = {
|
|||
255, 255, 0,
|
||||
255, 255, 255,
|
||||
},
|
||||
{
|
||||
{ // AMMO-8 (GameBoy-like)
|
||||
4, 12, 6,
|
||||
17, 35, 24,
|
||||
30, 58, 41,
|
||||
|
@ -49,7 +49,7 @@ static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE*VALUES_PER_COLOR] = {
|
|||
190, 220, 127,
|
||||
238, 255, 204,
|
||||
},
|
||||
{
|
||||
{ // RKBV (2-strip film)
|
||||
21, 25, 26,
|
||||
138, 76, 88,
|
||||
217, 98, 117,
|
||||
|
@ -85,8 +85,8 @@ int main()
|
|||
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
||||
int paletteLoc = GetShaderLocation(shader, "palette");
|
||||
|
||||
// Initial index not set, will be automatically bounded below.
|
||||
int currentPalette = -1;
|
||||
int currentPalette = 0;
|
||||
int lineHeight = screenHeight/COLORS_PER_PALETTE;
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
@ -96,21 +96,15 @@ int main()
|
|||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
int paletteIndex = currentPalette;
|
||||
if (IsKeyPressed(KEY_RIGHT)) paletteIndex++;
|
||||
else if (IsKeyPressed(KEY_LEFT)) paletteIndex--;
|
||||
if (IsKeyPressed(KEY_RIGHT)) currentPalette++;
|
||||
else if (IsKeyPressed(KEY_LEFT)) currentPalette--;
|
||||
|
||||
if (paletteIndex >= MAX_PALETTES) paletteIndex = 0;
|
||||
else if (paletteIndex < 0) paletteIndex = MAX_PALETTES - 1;
|
||||
if (currentPalette >= MAX_PALETTES) currentPalette = 0;
|
||||
else if (currentPalette < 0) currentPalette = MAX_PALETTES - 1;
|
||||
|
||||
// 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)
|
||||
{
|
||||
currentPalette = paletteIndex;
|
||||
// NOTE: We are sending RGB triplets w/o the alpha channel
|
||||
SetShaderValueV(shader, paletteLoc, palettes[currentPalette], UNIFORM_IVEC3, COLORS_PER_PALETTE);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
@ -121,32 +115,18 @@ int main()
|
|||
|
||||
BeginShaderMode(shader);
|
||||
|
||||
// Draw horizontal screen-wide rectangles with increasing "palette index".
|
||||
// The used palette index is encoded in the RGB components of the pixel.
|
||||
int linesPerRectangle = screenHeight / COLORS_PER_PALETTE;
|
||||
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)
|
||||
{
|
||||
height += 1;
|
||||
leftover -= 1;
|
||||
}
|
||||
|
||||
DrawRectangle(0, y, screenWidth, height, (Color){ i, i, i, 255 });
|
||||
|
||||
y += height;
|
||||
// Draw horizontal screen-wide rectangles with increasing "palette index"
|
||||
// The used palette index is encoded in the RGB components of the pixel
|
||||
DrawRectangle(0, lineHeight*i, GetScreenWidth(), lineHeight, (Color){ i, i, i, 255 });
|
||||
}
|
||||
|
||||
EndShaderMode();
|
||||
|
||||
DrawText("CURRENT PALETTE:", 10, 15, 20, RAYWHITE);
|
||||
DrawText(paletteText[currentPalette], 240, 15, 20, RED);
|
||||
DrawText("< >", 540, 10, 30, DARKBLUE);
|
||||
DrawText("< >", 10, 10, 30, DARKBLUE);
|
||||
DrawText("CURRENT PALETTE:", 60, 15, 20, RAYWHITE);
|
||||
DrawText(paletteText[currentPalette], 300, 15, 20, RED);
|
||||
|
||||
DrawFPS(700, 15);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue