Added new template (upscaled pixel art)
This commit is contained in:
parent
9b0a4513a7
commit
bcfd9909a7
|
@ -0,0 +1 @@
|
|||
__PROGNAME
|
|
@ -0,0 +1,11 @@
|
|||
CFLAGS += -Wall -Wextra `exec pkg-config --cflags raylib`
|
||||
LDFLAGS := -lm `pkg-config --libs raylib`
|
||||
|
||||
__PROGNAME: main.c
|
||||
$(CC) $(CFLAGS) main.c $(LDFLAGS) -o __PROGNAME
|
||||
|
||||
clean:
|
||||
$(RM) __PROGNAME
|
||||
|
||||
run: __PROGNAME
|
||||
./__PROGNAME
|
|
@ -0,0 +1,45 @@
|
|||
// 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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
name = "Raylib project with fancy pixel-art scaling and software-rendered canvas"
|
||||
templates = [
|
||||
"Makefile",
|
||||
"main.c",
|
||||
".gitignore"
|
||||
]
|
||||
|
||||
[params.WINDOW_WIDTH]
|
||||
prompt = "Initial window width"
|
||||
default = "480"
|
||||
|
||||
[params.WINDOW_HEIGHT]
|
||||
prompt = "Initial window height"
|
||||
default = "320"
|
|
@ -0,0 +1,15 @@
|
|||
#version 330
|
||||
uniform sampler2D texture0;
|
||||
uniform ivec2 texture0_size;
|
||||
uniform float px_per_tx;
|
||||
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
out vec4 finalColor;
|
||||
|
||||
void main() { vec2 uv = vec2(fragTexCoord.x, fragTexCoord.y);
|
||||
vec2 tx = uv * vec2(texture0_size);
|
||||
vec2 off = clamp(fract(tx) * px_per_tx, 0, 0.5) - clamp((1 - fract(tx)) * px_per_tx, 0, 0.5);
|
||||
vec2 pos = (floor(tx) + 0.5 + off) / vec2(texture0_size);
|
||||
finalColor = texture(texture0, pos);
|
||||
}
|
Loading…
Reference in New Issue