Posted June 26, 20178 yr 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 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. Basic GUI class: I don't think I have to explain this, just create your Gui with everything you want in it. 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(); } 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.
July 7, 20178 yr 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?
July 8, 20178 yr Author 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.
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.