From b8fcb14d0cc1f9acb240626a110ccf4073f56554 Mon Sep 17 00:00:00 2001 From: Bobby Lucero Date: Fri, 19 Apr 2024 14:31:11 -0400 Subject: [PATCH] Testing out render texture pixel manipulation and fixed full screen resize bug --- main.cpp | 65 ++++++++++++++++++++++++++++++++----------- resources/palette.hex | 64 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 16 deletions(-) create mode 100644 resources/palette.hex diff --git a/main.cpp b/main.cpp index 199fdb8..3b5cb69 100644 --- a/main.cpp +++ b/main.cpp @@ -4,11 +4,15 @@ using namespace std; -const int virtualScreenWidth = 240; -const int virtualScreenHeight = 136; +const int virtualScreenWidth = 360; +const int virtualScreenHeight = 203; +const int initialScale = 3; -int screenWidth = virtualScreenWidth * 4; -int screenHeight = virtualScreenHeight * 4; +int startupScreenWidth = virtualScreenWidth * initialScale; +int startupScreenHeight = virtualScreenHeight * initialScale; + +int screenWidth = startupScreenWidth; +int screenHeight = startupScreenHeight; void calculateBounds(Rectangle& bounds, Vector2& origin) { @@ -29,12 +33,15 @@ void calculateBounds(Rectangle& bounds, Vector2& origin) { } int main() { - const float virtualRatio = (float)screenWidth/(float)virtualScreenWidth; + + SetTraceLogLevel(LOG_ERROR); + + bool flip = false; SetConfigFlags(FLAG_WINDOW_RESIZABLE); - InitWindow(screenWidth, screenHeight, "test"); - SetTargetFPS(60); + InitWindow(startupScreenWidth, startupScreenHeight, "test"); + SetTargetFPS(-1); RenderTexture2D virtualScreen = LoadRenderTexture(virtualScreenWidth, virtualScreenHeight); Rectangle sourceRec = { 0.0f, 0.0f, (float)virtualScreen.texture.width, -(float)virtualScreen.texture.height }; @@ -44,7 +51,6 @@ int main() { pkpy::VM* vm = new pkpy::VM(); - Texture2D logo = LoadTexture("resources/img.png"); try { @@ -65,18 +71,27 @@ int main() { } if (IsKeyPressed(KEY_F)) { - int monitor = GetCurrentMonitor(); - SetWindowSize(GetMonitorWidth(monitor), GetMonitorHeight(monitor)); - screenWidth = GetScreenWidth(); - screenHeight = GetScreenHeight(); + if(IsWindowFullscreen()){ + ToggleFullscreen(); + SetWindowSize(startupScreenWidth, startupScreenHeight); + screenWidth = startupScreenWidth; + screenHeight = startupScreenHeight; + }else{ + int monitor = GetCurrentMonitor(); + SetWindowSize(GetMonitorWidth(monitor), GetMonitorHeight(monitor)); + screenWidth = GetMonitorWidth(monitor); + screenHeight = GetMonitorHeight(monitor); + ToggleFullscreen(); + } calculateBounds(virtualScreenBounds, origin); - ToggleFullscreen(); + }else if(IsKeyPressed(KEY_I)){ + flip = !flip; } BeginTextureMode(virtualScreen); - ClearBackground(GRAY); - DrawText("Hello World", 5, 5, 5, RAYWHITE); - DrawTexture(logo, 5, 20, WHITE); + ClearBackground(BLUE); + DrawText(("Hello World " + to_string(GetFPS()) + " FPS").c_str(), 5, 5, 5, RAYWHITE); + DrawTexture(logo, 80 + cos(GetTime()) * (virtualScreenHeight / 4), (virtualScreenHeight / 2) + sin(GetTime()) * (virtualScreenHeight / 4) - 29, WHITE); DrawLineBezier((Vector2){80, 20}, (Vector2){virtualScreenWidth - 5, virtualScreenHeight - 5}, 1, GREEN); DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 15, GREEN); DrawCircle(virtualScreenWidth / 2, virtualScreenHeight / 2, 13, YELLOW); @@ -87,6 +102,24 @@ int main() { EndTextureMode(); + if(flip){ + // Get texture data + Image img = LoadImageFromTexture(virtualScreen.texture); + Color* pixels = LoadImageColors(img); + + // Modify pixel data + for (int y = 0; y < img.height; y++) { + for (int x = 0; x < img.width; x++) { + // Example: Invert colors + Color pixel = pixels[y * img.width + x]; + pixels[y * img.width + x] = { (unsigned char)(255 - pixel.g), (unsigned char)(255 - pixel.r), (unsigned char)(255 - pixel.b), pixel.a }; + } + } + + // Update texture with modified data + UpdateTexture(virtualScreen.texture, pixels); + } + BeginDrawing(); ClearBackground(BLACK); DrawTexturePro(virtualScreen.texture, sourceRec, virtualScreenBounds, origin, 0.0f, WHITE); diff --git a/resources/palette.hex b/resources/palette.hex new file mode 100644 index 0000000..66c170c --- /dev/null +++ b/resources/palette.hex @@ -0,0 +1,64 @@ +211d25 +413d42 +5c5b63 +7c808b +a5b0b6 +d6dede +ffffff +dcded1 +aab1a1 +7b8375 +585f57 +3c3c3c +635d5a +8d837d +b4aea4 +dedcd1 +eadedf +bcacb1 +8f8189 +685d66 +643747 +b2434d +e55858 +fa8971 +ffb999 +ffe0b7 +ffbdc1 +ef93b5 +c971a2 +944e89 +4c3d57 +5d558f +777dc4 +96b1e7 +bedef6 +aae3db +5ac5ce +4694a8 +346376 +2a3b4a +29684a +379648 +79b547 +b8cf61 +f3db6f +f4ba7a +e79055 +ce6442 +944940 +91555d +b76f6b +cd9383 +e1ba9e +facafb +d49ce5 +9f76b8 +725689 +edb762 +fcfbc9 +de9463 +b66a4d +333f29 +4e5c2c +708939