2019-04-11 17:53:20 +03:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
2019-05-14 01:08:21 +03:00
|
|
|
* raylib [textures] example - Texture drawing
|
2019-04-11 17:53:20 +03:00
|
|
|
*
|
2022-07-20 02:28:37 +03:00
|
|
|
* NOTE: This example illustrates how to draw into a blank texture using a shader
|
2019-04-11 17:53:20 +03:00
|
|
|
*
|
2022-07-20 02:28:37 +03:00
|
|
|
* Example originally created with raylib 2.0, last time updated with raylib 3.7
|
2019-04-11 17:53:20 +03:00
|
|
|
*
|
2019-05-14 16:34:23 +03:00
|
|
|
* Example contributed by Michał Ciesielski and reviewed by Ramon Santamaria (@raysan5)
|
|
|
|
*
|
2022-07-20 02:28:37 +03:00
|
|
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
|
|
* BSD-like license that allows static linking with closed source software
|
|
|
|
*
|
2024-01-02 22:58:12 +03:00
|
|
|
* Copyright (c) 2019-2024 Michał Ciesielski and Ramon Santamaria (@raysan5)
|
2019-04-11 17:53:20 +03:00
|
|
|
*
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
|
2019-05-14 01:08:21 +03:00
|
|
|
#if defined(PLATFORM_DESKTOP)
|
|
|
|
#define GLSL_VERSION 330
|
2023-09-07 18:42:28 +03:00
|
|
|
#else // PLATFORM_ANDROID, PLATFORM_WEB
|
2019-05-14 01:08:21 +03:00
|
|
|
#define GLSL_VERSION 100
|
|
|
|
#endif
|
|
|
|
|
2022-06-21 20:53:18 +03:00
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Program main entry point
|
|
|
|
//------------------------------------------------------------------------------------
|
2019-05-20 17:36:42 +03:00
|
|
|
int main(void)
|
2019-04-11 17:53:20 +03:00
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
2019-05-20 17:36:42 +03:00
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 450;
|
2019-04-11 17:53:20 +03:00
|
|
|
|
2019-05-14 01:08:21 +03:00
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture drawing");
|
2019-04-11 17:53:20 +03:00
|
|
|
|
|
|
|
Image imBlank = GenImageColor(1024, 1024, BLANK);
|
|
|
|
Texture2D texture = LoadTextureFromImage(imBlank); // Load blank texture to fill on shader
|
|
|
|
UnloadImage(imBlank);
|
|
|
|
|
|
|
|
// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
2020-08-16 12:28:15 +03:00
|
|
|
Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/cubes_panning.fs", GLSL_VERSION));
|
2019-04-11 17:53:20 +03:00
|
|
|
|
|
|
|
float time = 0.0f;
|
|
|
|
int timeLoc = GetShaderLocation(shader, "uTime");
|
2021-03-14 13:05:51 +03:00
|
|
|
SetShaderValue(shader, timeLoc, &time, SHADER_UNIFORM_FLOAT);
|
2019-04-11 17:53:20 +03:00
|
|
|
|
2019-05-20 17:36:42 +03:00
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
|
|
// -------------------------------------------------------------------------------------------------------------
|
2019-04-11 17:53:20 +03:00
|
|
|
|
2019-05-20 17:36:42 +03:00
|
|
|
// Main game loop
|
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
2019-04-11 17:53:20 +03:00
|
|
|
{
|
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
2021-03-23 09:51:52 +03:00
|
|
|
time = (float)GetTime();
|
2021-03-14 13:05:51 +03:00
|
|
|
SetShaderValue(shader, timeLoc, &time, SHADER_UNIFORM_FLOAT);
|
2019-04-11 17:53:20 +03:00
|
|
|
//----------------------------------------------------------------------------------
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2019-04-11 17:53:20 +03:00
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
BeginDrawing();
|
|
|
|
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
|
|
|
|
BeginShaderMode(shader); // Enable our custom shader for next shapes/textures drawings
|
|
|
|
DrawTexture(texture, 0, 0, WHITE); // Drawing BLANK texture, all magic happens on shader
|
|
|
|
EndShaderMode(); // Disable our custom shader, return to default shader
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2019-04-11 17:53:20 +03:00
|
|
|
DrawText("BACKGROUND is PAINTED and ANIMATED on SHADER!", 10, 10, 20, MAROON);
|
|
|
|
|
|
|
|
EndDrawing();
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
}
|
2019-05-20 17:36:42 +03:00
|
|
|
|
2019-04-11 17:53:20 +03:00
|
|
|
// De-Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
UnloadShader(shader);
|
|
|
|
|
|
|
|
CloseWindow(); // Close window and OpenGL context
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|