Как растянуть изображение? :\

svk

1,185
3
Есть код, который рендерить что-то на главном экране, пытаюсь растянуть 1 штуковину, а она, вместо растягивания - перемещается. Help!
Код:
package com.svk.industrialGuns.Overlays;

import org.lwjgl.opengl.GL11;

import com.svk.industrialGuns.base.ModInfo;
import com.svk.industrialGuns.gunZak.Gun1;
import com.svk.industrialGuns.guns.Guns;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;

public class IconOverlay extends Gui
{
    private double percentage = 0.0F;
    private double percentage2 = 0.0F;
    
    public void renderOverlay(RenderGameOverlayEvent e)
    {
        ResourceLocation icon = new ResourceLocation(ModInfo.MODID, "textures/gui/gunsbar.png");
        
        Minecraft mc = Minecraft.getMinecraft();
        
        int x = 200;
        int y = 36;
        
        mc.renderEngine.bindTexture(icon);
        if(Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem() != null)
        {
            if(Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getItem() instanceof Guns)
            {
                Guns gun = (Guns) Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getItem();
                ItemStack gunStack = Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem();
                
                double durability = gunStack.getTagCompound().getInteger("ammoCount");
                double isDurability = gunStack.getTagCompound().getInteger("count") ;
                percentage = isDurability / durability;
                double health = gunStack.getTagCompound().getInteger("heating");
                double maxHealth = gunStack.getTagCompound().getInteger("maxHeating");
                percentage = isDurability / durability;
                
                percentage2 = health / maxHealth;
                
                GL11.glPushMatrix();
                GL11.glEnable(GL11.GL_BLEND);
                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                this.drawTexturedModalRect(e.resolution.getScaledWidth() - 201, e.resolution.getScaledHeight() - 33, 0, 0, x, y);

                this.drawTexturedModalRect((int) (e.resolution.getScaledWidth() - 201 + 9 ), e.resolution.getScaledHeight() - 33 + 9, (int) (0 - 95 * ((percentage - 1)*(-1))), 36, 95, 6);
                if(maxHealth >= health)
                {
                    this.drawTexturedModalRect((int) (e.resolution.getScaledWidth() - 201 + 9 ), e.resolution.getScaledHeight() - 33 + 9 + 10, (int) (0 - 95 * ((percentage2 - 1)*(-1))), 42, 95, 6);
                }
                else
                {
                    this.drawTexturedModalRect((int) (e.resolution.getScaledWidth() - 201 + 9 ), e.resolution.getScaledHeight() - 33 + 9 + 10, 0, 42, 95, 6);
                }
                this.drawTexturedModalRect(e.resolution.getScaledWidth() - 201 + 9, e.resolution.getScaledHeight() - 33 + 9, 0, 54, 95, 6);
                this.drawTexturedModalRect(e.resolution.getScaledWidth() - 201 + 9, e.resolution.getScaledHeight() - 33 + 9 + 10, 0, 54, 95, 6);

                GL11.glPushMatrix();
                GL11.glEnable(GL11.GL_BLEND);
                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                GL11.glScalef(1.0F, 1.0F, 1.0F); //Вот
                this.drawTexturedModalRect((int) (e.resolution.getScaledWidth() - 201 + 9 ), e.resolution.getScaledHeight() - 100, 197, 7, 3, 10);
                GL11.glPopMatrix();
                
                //Текст
                if(Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getTagCompound().getInteger("count") < 10)
                {
                    drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getTagCompound().getInteger("count")) + " / " + String.valueOf(Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getTagCompound().getInteger("ammoCount")), e.resolution.getScaledWidth() - 62, e.resolution.getScaledHeight() - 18, 3468175);
                }
                else if (Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getTagCompound().getInteger("count") < 100)
                {
                    drawString(Minecraft.getMinecraft().fontRenderer, " / " + String.valueOf(Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getTagCompound().getInteger("ammoCount")), e.resolution.getScaledWidth() - 55, e.resolution.getScaledHeight() - 18, 3468175);
                    drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getTagCompound().getInteger("count")), e.resolution.getScaledWidth() - 62, e.resolution.getScaledHeight() - 18, 3468175);
                }
                else if (Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getTagCompound().getInteger("count") < 1000)
                {
                    drawString(Minecraft.getMinecraft().fontRenderer, String.valueOf(Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getTagCompound().getInteger("count")), e.resolution.getScaledWidth() - 68, e.resolution.getScaledHeight() - 18, 3468175);
                    drawString(Minecraft.getMinecraft().fontRenderer, " / " + String.valueOf(Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getTagCompound().getInteger("ammoCount")), e.resolution.getScaledWidth() - 56, e.resolution.getScaledHeight() - 18, 3468175);
                }
                
                GL11.glPopMatrix();
            }
        }
    }
}
[merge_posts_bbcode]Добавлено: 11.04.2015 17:36:55[/merge_posts_bbcode]

Строка:
Код:
GL11.glScalef(1.0F, 1.0F, 1.0F); //Вот
 
Не надо использовать ни glScale, ни drawTexturedModalRect. Рисуй ручками через тесселлатор. Что-то вроде:
Код:
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(x, y + height, zLevel, minU, maxV);
tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, maxV);
tessellator.addVertexWithUV(x + width, y, zLevel, maxU, minV);    
tessellator.addVertexWithUV(x, y, zLevel, minU, minV);
tessellator.draw();
 
GloomyFolken написал(а):
Не надо использовать ни glScale, ни drawTexturedModalRect. Рисуй ручками через тесселлатор. Что-то вроде:
Код:
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV(x, y + height, zLevel, minU, maxV);
tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, maxV);
tessellator.addVertexWithUV(x + width, y, zLevel, maxU, minV);    
tessellator.addVertexWithUV(x, y, zLevel, minU, minV);
tessellator.draw();
Столько параметров :\
Я так понял, что нефига не понял :)
tessellator.addVertexWithUV(x, y + height, zLevel, minU, maxV);

Что за аргументы? И это замена drawTexturedModalRect?
А растягивать как? И что за аргументы?
Мне надо нарисовать палочку (кусочек из .png) и растянуть её по вертикали.
 
x и y - координаты на экране, где рисовать изображение
width и height - ширина и высота на экране
zLevel - "уровень глубины", на котором рисовать. Если поставишь 0, то ничего сломаться не должно.
minU, maxU, minV, maxV - координаты на текстуре от 0 до 1. Если тебе нужно просто растянуть изображение целиком, то minU и minV ставишь на 0, а maxU и maxV на 1.
 
GloomyFolken написал(а):
x и y - координаты на экране, где рисовать изображение
width и height - ширина и высота на экране
zLevel - "уровень глубины", на котором рисовать. Если поставишь 0, то ничего сломаться не должно.
minU, maxU, minV, maxV - координаты на текстуре от 0 до 1. Если тебе нужно просто растянуть изображение целиком, то minU и minV ставишь на 0, а maxU и maxV на 1.
А растягивать-то как?
[merge_posts_bbcode]Добавлено: 11.04.2015 19:25:59[/merge_posts_bbcode]

И почему, вообще, у нас 4 штуки?
Код:
tessellator.addVertexWithUV(x, y + height, zLevel, minU, maxV);
tessellator.addVertexWithUV(x + width, y + height, zLevel, maxU, maxV);
tessellator.addVertexWithUV(x + width, y, zLevel, maxU, minV);    
tessellator.addVertexWithUV(x, y, zLevel, minU, minV);
 
4 штуки - потому что рисуешь 4 вершины. Четырехугольник.
Растягивать - как хочешь. Если нужно "просто растянуть палочку по вертикали", то установи нужную height для этого "растягивания по вертикали".
 
А можете дать пример? Как я могу кусок текстуры рисовать таким образом, если нет параметров размера текстуры на общей текстуры. (X, Y, Размер X, Размер Y)
 
Тебе не нужно знать разрешение текстуры. Координаты на текстуре в openGL всегда находятся между 0 и 1. Например, если нужно отрендерить верхнюю правую четверть текстуры, то будет так:
minU = 0.5
maxU = 1
minV = 0
maxV = 0.5

Рендерит в левом верхнем углу экрана вертикальную полосу шириной 50 и высотой 500, текстуру берет из верхней правой четверти текстуры.
Код:
tessellator.addVertexWithUV(0, 500, 0, 0.5f, 1.0f);
tessellator.addVertexWithUV(50, 500, 0, 1.0f, 1.0f);
tessellator.addVertexWithUV(50, 0, 0, 1.0f, 0.5f);    
tessellator.addVertexWithUV(0, 0, 0, 0.5f, 0.5f);
 
Ой, сколько гемороя, ещё и процентно, а не пиксельно...
 
Назад
Сверху