diff --git a/lab16 with raylib/lib/raylib43.lib b/lab16 with raylib/lib/raylib43.lib new file mode 100644 index 0000000..dcece83 Binary files /dev/null and b/lab16 with raylib/lib/raylib43.lib differ diff --git a/lab16 with raylib/resources/bloom.frag b/lab16 with raylib/resources/bloom.frag new file mode 100644 index 0000000..56eadb5 --- /dev/null +++ b/lab16 with raylib/resources/bloom.frag @@ -0,0 +1,40 @@ +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; +in vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// Output fragment color +out vec4 finalColor; + +// NOTE: Add here your custom variables + +const vec2 size = vec2(800, 450); // Framebuffer size +const float samples = 5.0; // Pixels per axis; higher = bigger glow, worse performance +const float quality = 2.5; // Defines size factor: Lower = smaller glow, better quality + +void main() +{ + vec4 sum = vec4(0); + vec2 sizeFactor = vec2(1)/size*quality; + + // Texel color fetching from texture sampler + vec4 source = texture(texture0, fragTexCoord); + + const int range = 2; // should be = (samples - 1)/2; + + for (int x = -range; x <= range; x++) + { + for (int y = -range; y <= range; y++) + { + sum += texture(texture0, fragTexCoord + vec2(x, y)*sizeFactor); + } + } + + // Calculate final fragment color + finalColor = ((sum/(samples*samples)) + source)*colDiffuse; +} \ No newline at end of file diff --git a/lab16 with raylib/resources/blur.frag b/lab16 with raylib/resources/blur.frag new file mode 100644 index 0000000..6aa854a --- /dev/null +++ b/lab16 with raylib/resources/blur.frag @@ -0,0 +1,44 @@ +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; +in vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// Output fragment color +out vec4 finalColor; + +// NOTE: Add here your custom variables + +// NOTE: values must be passed from code +uniform float renderWidth; +uniform float renderHeight; +uniform float seconds; + +float offset[3] = float[](0.0, 1.3846153846, 3.2307692308); +float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703); + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord).rgba*weight[0]; + + for (int i = 1; i < 3; i++) + { + texelColor += texture(texture0, fragTexCoord + vec2(offset[i], offset[i]) / renderWidth).rgba * weight[i] / 2; + texelColor += texture(texture0, fragTexCoord - vec2(offset[i], offset[i]) / renderWidth).rgba * weight[i] / 2; + texelColor += texture(texture0, fragTexCoord + vec2(-offset[i], offset[i]) / renderWidth).rgba * weight[i] / 2; + texelColor += texture(texture0, fragTexCoord - vec2(-offset[i], offset[i]) / renderWidth).rgba * weight[i] / 2; + } + + vec4 red = vec4(1.0, 0.5, 0.5, 1.0); + vec4 blue = vec4(0.0, 0.5, 0.5, 1.0); + + finalColor = mix(red, blue, (sin(fragTexCoord.x * 24 + seconds * 4.0) + 1.0) / 2.0); + + //finalColor = texelColor; + //finalColor = vec4((sin(fragTexCoord.x * 24 + seconds * 4.0) + 1.0) / 2.0, 0.5, 0.5, 1.0); +} \ No newline at end of file diff --git a/lab16 with raylib/src/main.c b/lab16 with raylib/src/main.c index 8e18ac1..45d65a5 100644 --- a/lab16 with raylib/src/main.c +++ b/lab16 with raylib/src/main.c @@ -284,7 +284,7 @@ void load() { u8"Невозможно создать файл\nПроверьте целостность сохранения", u8"ok", "error", 1); - errorCode = loadError1; + //errorCode = loadError1; return; } int m, n; @@ -501,9 +501,14 @@ void callNKErrorBoxes(struct nk_context* ctx) { int main() { //SetConfigFlags(FLAG_WINDOW_HIGHDPI); - SetConfigFlags(FLAG_WINDOW_RESIZABLE); + //SetConfigFlags(FLAG_WINDOW_RESIZABLE); - InitWindow(N * WIDTH, M * HEIGHT + VOFFSET, "lab16 with raylib"); + const int screenWidth = N * WIDTH; + const int screenHeight = M * HEIGHT + VOFFSET; + const float screenWidthF = (float)screenWidth; + const float screenHeightF = (float)screenHeight; + + InitWindow(screenWidth, screenHeight, "lab16 with raylib"); SetTargetFPS(60); @@ -522,6 +527,15 @@ int main() //Font Arial = LoadFontEx("arial.ttf", 36, codepoints, CPSIZE); //SetTextureFilter(Arial.texture, TEXTURE_FILTER_BILINEAR); + RenderTexture2D canvas = LoadRenderTexture(screenWidth, screenHeight); + + Shader blur = LoadShader(0, "blur.frag"); + int renderWidthLoc = GetShaderLocation(blur, "renderWidth"); + int renderHeightLoc = GetShaderLocation(blur, "renderHeight"); + int secondsLoc = GetShaderLocation(blur, "seconds"); + SetShaderValue(blur, renderWidthLoc, &screenWidthF, SHADER_UNIFORM_FLOAT); + SetShaderValue(blur, renderHeightLoc, &screenHeightF, SHADER_UNIFORM_FLOAT); + GuiSetFont(InconsolataBold); GuiSetStyle(DEFAULT, TEXT_SIZE, 24); GuiSetStyle(DEFAULT, TEXT_SPACING, 0); @@ -542,8 +556,6 @@ int main() // Update game logic //------------------------------------------------------------------ - printf("lol"); - if (errorCode == OK) { handleKeys(); @@ -578,7 +590,9 @@ int main() //------------------------------------------------------------------ BeginDrawing(); // Setup the back buffer for drawing (clear color and depth buffers) - ClearBackground(WHITE); + //ClearBackground(WHITE); + + //BeginTextureMode(canvas); drawMap(); drawPlayer(); @@ -610,12 +624,32 @@ int main() // Render the Nuklear GUI //DrawNuklear(ctx); - drawRayguiErrorBoxes(); + //drawRayguiErrorBoxes(); } - Rectangle roundRect = { 100, 250, 185, 36 }; - DrawRectangleRounded(roundRect, 0.5f, 6, BLACK); - DrawRectangleRoundedLines(roundRect, 0.5f, 6, ORANGE); + BeginTextureMode(canvas); + { + ClearBackground((Color) { 255, 255, 255, 0 }); + //ClearBackground(BLANK); + Rectangle roundRect = { 100, 260, 185, 36 }; + DrawRectangleRounded(roundRect, 0.5f, 6, BLACK); + DrawRectangleRoundedLines(roundRect, 0.5f, 6, ORANGE); + } + EndTextureMode(); + + float timeF = (float)GetTime(); + SetShaderValue(blur, secondsLoc, &timeF, SHADER_UNIFORM_FLOAT); + + BeginShaderMode(blur); + { + Rectangle rec = { 0, 0, canvas.texture.width, -canvas.texture.height }; + DrawTextureRec(canvas.texture, rec, (Vector2) { 0.0f, 0.0f }, WHITE); + } + EndShaderMode(); + + //drawBottomBar(InconsolataBold, 24); + + //DrawTextureEx(canvas.texture, (Vector2) { 0.0f, 0.0f }, 0.0f, 1.0f, WHITE); //DrawTextEx(Consolas, u8"Файл не найден\nПопробуйте сначала сохранить игру", (Vector2) { 100, 100 }, 24, 0, BLACK); @@ -636,6 +670,9 @@ int main() //UnloadFont(Arial); //UnloadFont(InconsolataBold); + UnloadShader(blur); + UnloadRenderTexture(canvas); + // De-initialize the Nuklear GUI UnloadNuklear(ctx); diff --git a/raylib files/raylib43.lib b/raylib files/raylib43.lib new file mode 100644 index 0000000..a19608d Binary files /dev/null and b/raylib files/raylib43.lib differ