From 1f37e1d422066454e4e3b50bfb5253c6bff97be3 Mon Sep 17 00:00:00 2001 From: JuiceyDev Date: Fri, 6 Mar 2026 00:28:53 +0100 Subject: [PATCH] some updates --- 4J.Render/4J_Render.cpp | 37 ++++++++++- 4J.Render/4J_Render.h | 4 ++ .../Platform/Linux/Linux_Minecraft.cpp | 33 +++++++++- README.md | 66 ++++++++++++++++++- 4 files changed, 134 insertions(+), 6 deletions(-) diff --git a/4J.Render/4J_Render.cpp b/4J.Render/4J_Render.cpp index 65b408e1e..21d689ace 100644 --- a/4J.Render/4J_Render.cpp +++ b/4J.Render/4J_Render.cpp @@ -15,8 +15,11 @@ C4JRender RenderManager; static GLFWwindow *s_window = nullptr; static int s_textureLevels = 1; -static int s_windowWidth = 1920; -static int s_windowHeight = 1080; +static int s_windowWidth = 1280; // updated to actual framebuffer size each frame +static int s_windowHeight = 720; +static int s_reqWidth = 0; // 0 = auto-detect from primary monitor +static int s_reqHeight = 0; +static bool s_fullscreen = false; // Thread-local storage for per-thread shared GL contexts. // The main thread uses s_window directly; worker threads get invisible @@ -54,12 +57,29 @@ void C4JRender::Initialise() return; } + // Resolve window dimensions: use caller-requested size, or fall back to + // the primary monitor's native resolution so the window fits any display. + GLFWmonitor *primaryMonitor = glfwGetPrimaryMonitor(); + const GLFWvidmode *mode = primaryMonitor ? glfwGetVideoMode(primaryMonitor) : nullptr; + + if (s_reqWidth > 0 && s_reqHeight > 0) { + s_windowWidth = s_reqWidth; + s_windowHeight = s_reqHeight; + } else if (mode) { + s_windowWidth = mode->width; + s_windowHeight = mode->height; + } + fprintf(stderr, "[4J_Render] Window %dx%d fullscreen=%s\n", + s_windowWidth, s_windowHeight, s_fullscreen ? "yes" : "no"); + fflush(stderr); + // opengl 2.1!!! glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); + GLFWmonitor *fsMonitor = s_fullscreen ? primaryMonitor : nullptr; s_window = glfwCreateWindow(s_windowWidth, s_windowHeight, - "Minecraft Console Edition", nullptr, nullptr); + "Minecraft Console Edition", fsMonitor, nullptr); if (!s_window) { fprintf(stderr, "[4J_Render] Failed to create GLFW window\n"); glfwTerminate(); @@ -171,6 +191,17 @@ void C4JRender::Present() glfwPollEvents(); } +void C4JRender::SetWindowSize(int w, int h) +{ + s_reqWidth = (w > 0) ? w : 0; + s_reqHeight = (h > 0) ? h : 0; +} + +void C4JRender::SetFullscreen(bool fs) +{ + s_fullscreen = fs; +} + bool C4JRender::ShouldClose() { return !s_window || glfwWindowShouldClose(s_window); diff --git a/4J.Render/4J_Render.h b/4J.Render/4J_Render.h index d16df4112..63bfb3471 100644 --- a/4J.Render/4J_Render.h +++ b/4J.Render/4J_Render.h @@ -63,6 +63,10 @@ public: // Core void Initialise(); void InitialiseContext(); + // Call before Initialise() to override window size and/or fullscreen mode. + // If not called, the primary monitor's native resolution is used. + void SetWindowSize(int w, int h); + void SetFullscreen(bool fs); void StartFrame(); void DoScreenGrabOnNextPresent(); void Present(); diff --git a/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp b/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp index 8fdb60aca..64128fc45 100644 --- a/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp +++ b/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp @@ -587,6 +587,28 @@ int main(int argc, const char *argv[] ) #endif app.DebugPrintf("---main()\n"); + // ---- Parse CLI arguments ---- + // Usage: Minecraft.Client [--width W] [--height H] [--fullscreen] + // If --width/--height are omitted the primary monitor's native resolution + // is used automatically. + { + int reqW = 0, reqH = 0; + bool fs = false; + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "--fullscreen") == 0) { + fs = true; + } else if (strcmp(argv[i], "--width") == 0 && i + 1 < argc) { + reqW = atoi(argv[++i]); + } else if (strcmp(argv[i], "--height") == 0 && i + 1 < argc) { + reqH = atoi(argv[++i]); + } + } + if (reqW > 0 && reqH > 0) + RenderManager.SetWindowSize(reqW, reqH); + if (fs) + RenderManager.SetFullscreen(true); + } + #if 0 // Main message loop MSG msg = {0}; @@ -647,8 +669,15 @@ app.DebugPrintf("---ReadProductCodes()\n"); app.loadMediaArchive(); app.loadStringTable(); -ui.init(1920,1080); - + // Use the actual framebuffer dimensions so the UI scales to whatever + // window/fullscreen resolution was chosen at startup. + { + int uiW = 1920, uiH = 1080; + RenderManager.GetFramebufferSize(uiW, uiH); + if (uiW < 1) uiW = 1920; + if (uiH < 1) uiH = 1080; + ui.init(uiW, uiH); + } // storage manager is needed for the trial key check StorageManager.Init(0,app.GetString(IDS_DEFAULT_SAVENAME),"savegame.dat",FIFTY_ONE_MB,&CConsoleMinecraftApp::DisplaySavingMessage,(LPVOID)&app,""); diff --git a/README.md b/README.md index 4ecccdb7f..4216b534d 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,73 @@ Join our community: * Steam: https://steamcommunity.com/groups/4JCraft ## Planned platforms to be supported: -- Linux (~95%) +- Linux (~85%) - Emscripten (not started) - PS3 - macOS (not started) - iOS (not started) - Android (not started) +--- + +## Building (Linux) + +### Dependencies + +Install the following packages before building (Debian/Ubuntu names shown): + +```bash +sudo apt install \ + build-essential cmake \ + libglfw3-dev libgl-dev libglu1-mesa-dev \ + libopenal-dev libvorbis-dev \ + libpthread-stubs0-dev +``` + +On Arch/Manjaro: + +```bash +sudo pacman -S base-devel gcc pkgconf cmake glfw-x11 mesa openal libvorbis glu +``` + +If you are on wayland, swap glfw-x11 to glfw-wayland, but its doesn't matter cuz xwayland got yourself covered + +### Configure & Build + +```bash +# 1. Configure (only needed once, or after CMakeLists changes) +cmake . + +# 2. Build (use -jN with your core count) +make -j$(nproc) +``` + +The binary is output to: + +``` +Linux/Debug/Minecraft.Client +``` + +### Clean + +```bash +make clean +``` + +To fully reset the CMake configuration (removes cache + generated Makefiles): + +```bash +rm -rf CMakeCache.txt CMakeFiles cmake_install.cmake Makefile +# Then re-run: cmake . && make -j$(nproc) +``` + +--- + +## Running + +```bash +# Default — window opens at your primary monitor's native resolution (windowed) +./Linux/Debug/Minecraft.Client + +``` + +(todo refactor) \ No newline at end of file