things/_templates/raylib/pixelart/main.c

46 lines
1.8 KiB
C
Raw Permalink Normal View History

// x-run: make run
#include <math.h>
#include <raylib.h>
int main(int argc, char **argv) {
SetTraceLogLevel(LOG_ERROR);
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(__WINDOW_WIDTH * 2, __WINDOW_HEIGHT * 2, "__PROJECT");
const int _window_size[2] = { __WINDOW_WIDTH, __WINDOW_HEIGHT };
Image canvas = GenImageColor(__WINDOW_WIDTH, __WINDOW_HEIGHT, BLANK);
Texture2D t_canvas = LoadTextureFromImage(canvas);
SetTextureFilter(t_canvas, TEXTURE_FILTER_BILINEAR);
Shader shd_upscale = LoadShader(0, "upscale.frag");
int shdloc_texsize = GetShaderLocation(shd_upscale, "texture0_size");
int shdloc_scale = GetShaderLocation(shd_upscale, "px_per_tx");
for (int frame = 0; !WindowShouldClose(); frame++) {
BeginDrawing();
int window_width = GetScreenWidth(), window_height = GetScreenHeight();
float scale = fminf(window_width / (float)__WINDOW_WIDTH, window_height / (float)__WINDOW_HEIGHT);
{ // BEGIN frame
ImageClearBackground(&canvas, GetColor(0x1A1A1AFF));
ImageDrawText(&canvas, TextFormat("scale: %7.2fx", scale), 20, 20, 20, WHITE);
} // END frame
{ // BEGIN update
UpdateTexture(t_canvas, canvas.data);
BeginShaderMode(shd_upscale);
SetShaderValue(shd_upscale, shdloc_texsize, _window_size, SHADER_UNIFORM_IVEC2);
SetShaderValue(shd_upscale, shdloc_scale, &scale, SHADER_UNIFORM_FLOAT);
int texture_width = scale * __WINDOW_WIDTH, texture_height = scale * __WINDOW_HEIGHT;
ClearBackground(BLACK);
DrawTexturePro(t_canvas, (Rectangle) {
0, 0, __WINDOW_WIDTH, __WINDOW_HEIGHT
}, (Rectangle) {
floorf((window_width - texture_width) / 2.0),
floorf((window_height - texture_height) / 2.0),
texture_width, texture_height
}, (Vector2) { 0, 0 }, 0.0, WHITE);
EndShaderMode();
} // END update
EndDrawing();
}
}