0
\$\begingroup\$

I want to draw an image that I created but the image is too big. Now I want the Gui to scale the image to a reasonable size, but when I change the width and height it doesn't make the image scale down/up but only the texture.

Code where I draw the image on screen:

@Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
    {
        this.drawDefaultBackground();
        super.drawScreen(mouseX, mouseY, partialTicks);
        this.renderHoveredToolTip(mouseX, mouseY);
        Slot slot = getSlotAtPosition(mouseX, mouseY);

        if(slot != null) {
            if(slot.getStack().getItem() instanceof MonsterCard) {
                this.mc.getTextureManager().bindTexture(new ResourceLocation(Reference.MODID + ":textures/items/" + ((MonsterCard) slot.getStack().getItem()).getName() + ".png"));
                int i = (this.width - this.xSize) / 4;
                int j = (this.height - this.ySize) / 2;
                this.drawTexturedModalRect(0, 0, 0, 0, 154, 226);
            }
        }
    }

Image I want to draw which is 154px x 226px:

enter image description here

Output:

enter image description here

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$
int i = (this.width - this.xSize) / 4;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(0, 0, 0, 0, 154, 226);

Warning: unused variables i and j

Additionally, drawTexturedModalRect() assumes that the texture is 256x256 pixels exactly, so the last two parameters are divided by 256 to compute the size-agnostic UV coordinates, but your image is not 256x256, which is why it is cut off and stretched (your drawing 60% of the width and 88% of the height). There is a similar, but differently named, method that allows you to specify the texture size as well, but I can never remember the name of it.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .