Posted May 29, 20196 yr Hello. In the process of creating a GUI, I went on trying to give it a custom background. It works well except that, the image stretches itself to fit on the screen, which makes it look weird and impractical. I wonder if there was a way to make it fill the screen without being stretched. Pretty similar to how it appears here: . I'm mainly using Gui#drawModalRectWithCustomSizedTexture() to draw the resource (I tried using the BufferBuilder which roughly brought the same exact result). The image I would like to render has dimensions of 1280x720. I don't know if any other dimension would look better, so if you are aware of any more appropriate size then I'd love to know. Which looks on screen like that: (Blacked out parts are just hidden, however they are a part of the screen. The gradients are extra effects.). Here's the code I'm using: Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation); Gui.drawModalRectWithCustomSizedTexture(0, 0, scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight()); I tried replacing all references to scaledResolution with the image's dimensions, which did not really change anything. Any idea on how to make it display normally without being stretched?
May 29, 20196 yr Author 4 hours ago, diesieben07 said: https://stackoverflow.com/a/10285523/3638966 Thanks! It now renders much better. Here's the code in case anyone ran into the same problem: float imgRatio = (720F / 1280F); float containerRatio = ((float) sr.getScaledHeight() / (float) sr.getScaledWidth()); float finalWidth; float finalHeight; if (containerRatio > imgRatio) { finalHeight = sr.getScaledHeight(); finalWidth = (sr.getScaledHeight() * imgRatio); } else { finalHeight = (sr.getScaledWidth() * imgRatio); finalWidth = sr.getScaledWidth(); } Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation); finalWidth += 400F; // Extend the image display by 400 pixels Gui.drawModalRectWithCustomSizedTexture(0, 0, finalWidth, finalHeight, (int) finalWidth, (int) finalHeight, finalWidth, finalHeight); Edited May 29, 20196 yr by Reflxction
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.