Jump to content

[1.12]Full Screen / Fixed Gui Elements


Recommended Posts

So I often had this Problem with Gui textures resizing upon rescaling the window or changing the guiScale.
This is also problematic if other players with a different Resolution use your Guis which are meant to have fixed points.

In this tutorial I want to show you how to make a fixed ModalRect which will take up the whole Minecraft-Screen, no matter whether you are in fullscreen-mode

or only are using a small window.

 

Tutorial starts here

  1. Creating a texture file:
    In order to make a good Gui, you need to know what you are making. I always
    create a texture with some pattern scratched on to it to see if all of it is shown.
    You probably will be using a 4:3 Format, for me it is 512x384.
     
  2. Basic GUI class:
    I don't think I have to explain this, just create your Gui with everything you want in it.
     
  3. Scaling properly:
    So first you Need to call
    GlStateManager.pushMatrix();

    where you draw your Rect, to be able to scale your Image.
    Then, you create two floats, which I will simply call x and y here

    float x = (float)width/512;  //512 -> my texture size
    float y = (float)height/384; //384 -> my texture size

    These two floats are equal to the factor by which you have to scale your Image.
    If you are asking yourself why that is, well, it is because if you divide the Resolution of your current
    Screen(which may be for example 1024 * 768) by your texture size, you get the exact number of how many
    times it fits into your Screen. After that, you can call the scale method:

    GlStateManager.scale(x, y, 1.0);

    This should scale your texture to your width and height.
    Now you can simply call the common bindTexture() and drawRect() methods.

    this.mc.renderEngine.bindTexture(cmbase);
    this.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 512, 384, 512, 384);

    and Pop the Matrix

    GlStateManager.popMatrix();

    Now you should have your whole texture on the Screen.

    This is an example of how I did it:

    package armamenthaki.duelmonsters.gui;
    
    import armamenthaki.duelmonsters.util.Log;
    import ca.weblite.objc.Client;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.gui.GuiButton;
    import net.minecraft.client.gui.GuiScreen;
    import net.minecraft.client.gui.ScaledResolution;
    import net.minecraft.client.renderer.GlStateManager;
    import net.minecraft.util.ResourceLocation;
    
    public class GuiCardManager extends GuiScreen
    {
    	private static final ResourceLocation cmbase = new ResourceLocation("duelmonsters", "textures/textures/gui/guicmbase.png");
    	private GuiButton button1;
    	
    	@Override
        public void drawScreen(int mouseX, int mouseY, float partialTicks)
    	{
    		GlStateManager.pushMatrix();
    		float x = (float)width/512;  //512 -> my texture size
    		float y = (float)height/384; //384 -> my texture size
    		GlStateManager.scale(x, y, 1.0);
    		this.mc.renderEngine.bindTexture(cmbase);
    		this.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 512, 384, 512, 384);
    		GlStateManager.popMatrix();
    	}
        

     

  4. I hope this helps, I know it isn't well explained but I saw many Posts(including myself) on the Internet by
    People who where trying that, and I didn't find another tutorial.
    If you have any questions feel free to ask, though I am no expert at modding.

    Finally, this is a Screenshot of my example, which shows that the 512/384 texture fills the whole Screen.
    A screenshot in Minecraft

Link to comment
Share on other sites

  • 2 weeks later...
On ‎07‎.‎07‎.‎2017 at 3:23 AM, fuzzybat23 said:

Where exactly do you put your png in the file structure, though?  Like, I'm going to assume you're using eclipse?  Would it go in src/main/resources, where mcmod.info is located?

I am not sure if I understand you correctly, but the file is located in src/main/resources/duelmonsters/textures/textures/gui/cmbase.png.
I have two texture Folders, one for textures in General, and one for textures which belong to minecraft related textures.
The Resource Location is defined at the beginning of the class.

Link to comment
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I used multiple biomes by setting the type to minecraft:multi_noise. The dimension is working fine now, but I was wondering if there is a way to supress this warning when creating a new world: Warning! These settings are using experimental features. These settings are experimental and could one day stop working. Do you wish to proceed?
    • Hi. Please help. Forge keep crashing on my pc (error code 1). This happened after i updated my PC to the latest windows 11 update. I have tried updating my GPU driver, reinstall java and reinstall minecraft, but i still got this error code 1. Any help is appreciated. Thanks.  
    • here are the logs https://gist.github.com/Myrious/13e16642c4afe9c0286691571bd136f0
    • I Start Up the game get a crash before forge even starts to load Crash Log-https://gist.github.com/keepinitreal247/c1024110beca289019a0177ddecfc910
    • The game crashed whilst initializing game. Error: net.minecraftforge.fml.ModLoadingExceptionForge encountered an error during the sided_setup event phase . Got crash exit code -1 for minecraft forge 1.19.3 It works before i instal my mods the list of mods i got are: Macaw's: paintings, paths, lights, roofs, windows, trapdoors, fences, doors + optifine 1.19.3  +  Shaders: BSL, Sildurs-high,extreme, extreme VL + Resource packs: SFT_FREE, HelHeim R29, SkylineArt free, Clear_Glass_Pack, Unity, Round trees, Fresh animations, Better-Leaves  ---- Minecraft Crash Report ---- // Hi. I'm Minecraft, and I'm a crashaholic. Time: 2023-01-29 01:34:45 Description: Rendering overlay java.lang.NoClassDefFoundError: net/minecraftforge/common/extensions/IForgeModelBaker     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {}     at cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:119) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:135) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {}     at cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:119) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:135) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at net.minecraft.client.resources.model.ModelBakery.lambda$bakeModels$9(ModelBakery.java:209) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:accesstransformer:B,xf:OptiFine:default}     at java.util.HashMap$KeySet.forEach(HashMap.java:1008) ~[?:?] {}     at net.minecraft.client.resources.model.ModelBakery.m_245909_(ModelBakery.java:204) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:accesstransformer:B,xf:OptiFine:default}     at net.minecraft.client.resources.model.ModelManager.m_245476_(ModelManager.java:166) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.resources.model.ModelManager.m_246937_(ModelManager.java:89) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:runtimedistcleaner:A}     at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646) ~[?:?] {}     at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483) ~[?:?] {}     at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}     at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}     at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {re:computing_frames}     at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {re:computing_frames}     at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {} Caused by: java.lang.ClassNotFoundException: net.minecraftforge.common.extensions.IForgeModelBaker     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:141) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     ... 28 more A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {}     at cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:119) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.lambda$findClass$15(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:229) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:219) ~[securejarhandler-2.1.4.jar:?] {}     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:135) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?] {}     at java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[?:?] {} -- Overlay render details -- Details:     Overlay name: net.minecraft.client.gui.screens.LoadingOverlay Stacktrace:     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:1337) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:mixin,pl:accesstransformer:B,xf:OptiFine:default,re:classloading,pl:accesstransformer:B,xf:OptiFine:default,pl:mixin:APP:mtr.mixins.json:GameRendererMixin,pl:mixin:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1135) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:713) ~[client-1.19.3-20221207.122022-srg.jar%23168!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.m_239872_(Main.java:212) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:51) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:27) ~[fmlloader-1.19.3-44.1.0.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {} -- Last reload -- Details:     Reload number: 1     Reload reason: initial     Finished: No     Packs: vanilla
  • Topics

×
×
  • Create New...

Important Information

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