opengl33 -> opengl43 | нормальный HiDPI !!!!

This commit is contained in:
Kaehvaman 2024-12-28 17:04:16 +04:00
parent 3b3bf34b74
commit 7eefa8c1fd
24 changed files with 18156 additions and 117 deletions

View File

@ -139,6 +139,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\main.c" />
<ClCompile Include="..\src\tinyfiledialogs.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -29,5 +29,8 @@
<ClCompile Include="..\src\main.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="..\src\tinyfiledialogs.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -2,9 +2,11 @@
#include "raymath.h"
#include <stdbool.h>
#include <iso646.h>
#include <stdlib.h>
#include <string.h>
#define MAP_X 20
#define MAP_Y 20
#define MAP_X 100
#define MAP_Y 50
#define CELL_SIZE 20
#define FCELL_SIZE (float)CELL_SIZE
@ -19,11 +21,11 @@ static bool map[MAP_X][MAP_Y] = { 0 };
static bool tempMap[MAP_X][MAP_Y] = { 0 };
static inline int checkCell(int x, int y) {
if (x > 0 and y > 0 and x < MAP_X - 1 and y < MAP_Y - 1) {
return map[x][y];
if (x < 0 or y < 0 or x > MAP_X - 1 or y > MAP_Y - 1) {
return 0;
}
else {
return 0;
return map[x][y];
}
}
@ -45,42 +47,43 @@ void celluralAutomata()
if (neighbours == 3) {
tempMap[x][y] = true;
}
else if (neighbours < 2 or neighbours > 3) {
tempMap[x][y] = false;
else if (neighbours == 2) {
tempMap[x][y] = map[x][y];
}
else {
tempMap[x][y] = map[x][y];
tempMap[x][y] = false;
}
}
}
for (int x = 0; x < MAP_X; x++) {
for (int y = 0; y < MAP_Y; y++) {
map[x][y] = tempMap[x][y];
}
}
memcpy(map, tempMap, MAP_X * MAP_Y * sizeof(bool));
}
void drawMap()
{
for (int x = 0; x < MAP_X; x++) {
for (int y = 0; y < MAP_Y; y++) {
int posX = x * CELL_SIZE;
int posY = y * CELL_SIZE;
Color color;
if (map[x][y]) {
color = BLACK;
int posX = x * CELL_SIZE;
int posY = y * CELL_SIZE;
DrawRectangle(posX, posY, CELL_SIZE, CELL_SIZE, BLACK);
}
else {
color = RAYWHITE;
}
DrawRectangle(posX, posY, CELL_SIZE, CELL_SIZE, color);
}
}
}
void drawNet() {
for (int i = 0; i <= MAP_X * CELL_SIZE; i += CELL_SIZE) {
DrawLine(i, 0, i, MAP_Y * CELL_SIZE, GRAY);
DrawLine(i+1, 0, i+1, MAP_Y * CELL_SIZE, GRAY);
}
for (int i = 0; i <= MAP_Y * CELL_SIZE; i += CELL_SIZE) {
DrawLine(0, i, MAP_X * CELL_SIZE, i, GRAY);
DrawLine(0, i-1, MAP_X * CELL_SIZE, i-1, GRAY);
}
}
void drawBottomBar()
{
DrawRectangle(0, MAP_Y * CELL_SIZE, MAP_X * CELL_SIZE, BOTTOM_BAR_HEIGHT, BLACKGRAY);
@ -91,21 +94,27 @@ int main()
const int screenWidth = MAP_X * CELL_SIZE;
const int screenHeight = MAP_Y * CELL_SIZE + BOTTOM_BAR_HEIGHT;
SetConfigFlags(FLAG_VSYNC_HINT);
InitWindow(screenWidth, screenHeight, "Game of Life");
SetTargetFPS(15);
//SetTargetFPS(60);
Vector2 mousePos = { 0 };
int mouseCellX = 0;
int mouseCellY = 0;
bool editMap = true;
bool netToggle = false;
while (!WindowShouldClose())
{
if (IsKeyPressed(KEY_SPACE)) {
editMap = !editMap;
}
if (IsKeyPressed(KEY_N)) {
netToggle = !netToggle;
}
if (editMap)
{
@ -130,17 +139,22 @@ int main()
drawMap();
drawBottomBar();
if (netToggle) drawNet();
if (editMap)
{
Rectangle rec = {
mouseCellX * CELL_SIZE,
mouseCellY * CELL_SIZE,
mouseCellX * FCELL_SIZE,
mouseCellY * FCELL_SIZE,
FCELL_SIZE, FCELL_SIZE
};
DrawRectangleLinesEx(rec, 2, GREEN);
}
DrawFPS(0, 0);
EndDrawing();
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,40 +0,0 @@
#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;
}

View File

@ -1,27 +0,0 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec3 vertexPos;
in vec2 fragTexCoord;
in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform vec4 colDiffuse;
uniform float divider = 0.5;
out vec4 finalColor;
void main()
{
// Texel color fetching from texture sampler
vec4 texelColor0 = texture(texture0, fragTexCoord);
vec4 texelColor1 = texture(texture1, fragTexCoord);
float x = fract(fragTexCoord.s);
float final = smoothstep(divider - 0.1, divider + 0.1, x);
finalColor = mix(texelColor0, texelColor1, final);
}

View File

@ -20,11 +20,12 @@
#pragma warning(disable: 4116)
#include "raylib-nuklear.h"
Vector2 scaleDPI = { 1.0f, 1.0f };
#define M 10
#define N 15
#define HEIGHT 50
#define WIDTH 50
#define VOFFSET 52
#define HEIGHT (int)(50 * scaleDPI.y)
#define WIDTH (int)(50 * scaleDPI.x)
#define VOFFSET (int)(52 * scaleDPI.y)
#define FWIDTH (float)WIDTH
#define FHEIGHT (float)HEIGHT
@ -234,9 +235,9 @@ void drawBottomBar(Font font, float fontSize) {
if (selected_element == gold) gold_string[0] = '>';
else if (selected_element == wall) wall_string[0] = '>';
Vector2 goldpos = { WIDTH / 4, HEIGHT * M };
Vector2 wallpos = { WIDTH / 4, HEIGHT * M + fontSize };
Vector2 helppos = { WIDTH * N - 550 , HEIGHT * M };
Vector2 goldpos = { FWIDTH / 4, FHEIGHT * M };
Vector2 wallpos = { FWIDTH / 4, FHEIGHT * M + fontSize };
Vector2 helppos = { FWIDTH * N - MeasureTextEx(font, help_string, fontSize, 0).x - 20 * scaleDPI.x, FHEIGHT * M};
DrawTextEx(font, gold_string, goldpos, fontSize, 0, VSGREEN);
DrawTextEx(font, wall_string, wallpos, fontSize, 0, VSGREEN);
@ -391,7 +392,7 @@ void handleKeys() {
}
void drawRayguiErrorBoxes() {
const Rectangle errorBoxRect = { N * WIDTH / 2 - 200, M * HEIGHT / 2 - 75, 400, 150 };
const Rectangle errorBoxRect = { N * FWIDTH / 2 - 200, M * FHEIGHT / 2 - 75, 400, 150 };
int btn = -1;
switch (errorCode)
@ -436,7 +437,7 @@ int nk_error_box(struct nk_context* ctx, const char* title, const char* error, c
{
int result = -1;
if (nk_begin(ctx, title,
nk_rect(N * WIDTH / 2 - 200, M * HEIGHT / 2 - 72, 400, 144),
nk_rect(N * FWIDTH / 2 - 200, M * FHEIGHT / 2 - 72, 400, 144),
NK_WINDOW_TITLE | NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR))
{
nk_layout_row_dynamic(ctx, 24, 1);
@ -501,16 +502,23 @@ void callNKErrorBoxes(struct nk_context* ctx) {
#define CPSIZE 213
int main()
{
SetConfigFlags(FLAG_WINDOW_HIGHDPI);
//SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow( 1280, 720, "lab16 with raylib");
scaleDPI = GetWindowScaleDPI();
const int screenWidth = N * WIDTH;
const int screenHeight = M * HEIGHT + VOFFSET;
const float screenWidthF = (float)screenWidth;
const float screenHeightF = (float)screenHeight;
const Vector2 resolution = { screenWidthF, screenHeightF };
int monitor = GetCurrentMonitor();
int monitorCenterX = GetMonitorWidth(monitor) / 2;
int monitorCenterY = GetMonitorHeight(monitor) / 2;
InitWindow(screenWidth, screenHeight, "lab16 with raylib");
int screenWidth = N * WIDTH;
int screenHeight = M * HEIGHT + VOFFSET;
float screenWidthF = (float)screenWidth;
float screenHeightF = (float)screenHeight;
Vector2 resolution = { screenWidthF, screenHeightF };
SetWindowSize(screenWidth, screenHeight);
SetWindowPosition(monitorCenterX - screenWidth/2, monitorCenterY - screenHeight/2);
SetTargetFPS(60);
@ -530,7 +538,7 @@ int main()
//SetTextureFilter(Arial.texture, TEXTURE_FILTER_BILINEAR);
RenderTexture2D canvas = LoadRenderTexture(screenWidth, screenHeight);
SetTextureFilter(canvas.texture, TEXTURE_FILTER_BILINEAR);
//SetTextureFilter(canvas.texture, TEXTURE_FILTER_BILINEAR);
SetTextureWrap(canvas.texture, TEXTURE_WRAP_CLAMP);
RenderTexture2D canvasBlurX = LoadRenderTexture(screenWidth, screenHeight);
@ -547,12 +555,11 @@ int main()
Shader watershader = LoadShader(0, "watershader.frag");
int waterBumpMapLoc = GetShaderLocation(watershader, "waterBumpMap");
int watershaderSecondsLoc = GetShaderLocation(watershader, "seconds");
int waterResolutionLoc = GetShaderLocation(watershader, "resolution");
SetShaderValue(watershader, waterResolutionLoc, &resolution, SHADER_UNIFORM_VEC2);
int watershaderResolutionLoc = GetShaderLocation(watershader, "resolution");
SetShaderValue(watershader, watershaderResolutionLoc, &resolution, SHADER_UNIFORM_VEC2);
Texture waterBump = LoadTexture("waterbump_blur.png");
SetTextureFilter(waterBump, TEXTURE_FILTER_BILINEAR);
SetShaderValueTexture(watershader, waterBumpMapLoc, waterBump);
Shader blur13 = LoadShader(0, "blur13.frag");
int blur13resolution = GetShaderLocation(blur13, "resolution");
@ -578,7 +585,6 @@ int main()
//------------------------------------------------------------------
// Update game logic
//------------------------------------------------------------------
float frametime = GetFrameTime();
if (errorCode == OK)
@ -622,7 +628,7 @@ int main()
drawMap();
drawPlayer();
drawBottomBar(InconsolataBold, 24);
drawBottomBar(InconsolataBold, 24 * scaleDPI.y);
if (editMap) {
Rectangle rec = {
@ -668,12 +674,12 @@ int main()
SetShaderValue(watershader, watershaderSecondsLoc, &timeF, SHADER_UNIFORM_FLOAT);
Rectangle rec = { 0, 0, (float)canvas.texture.width, (float)(-canvas.texture.height) };
BeginShaderMode(watershader);
//BeginShaderMode(watershader);
{
SetShaderValueTexture(watershader, waterBumpMapLoc, waterBump);
DrawTextureRec(canvas.texture, rec, (Vector2) { 0.0f, 0.0f }, WATERBLUE);
DrawTextureRec(canvas.texture, rec, (Vector2) { 0.0f, 0.0f }, WHITE);
}
EndShaderMode();
//EndShaderMode();
//BeginTextureMode(canvasBlurX);
//{

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff