Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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: unknown.png. 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.

1.jpg

Which looks on screen like that:

FXQ4ovO.png

(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?

  • Author
4 hours ago, diesieben07 said:

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 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.