Jump to content

(1.16.5 MCP) Render overlay error(background black)


ElTotisPro50

Recommended Posts

so im rendering an icon FROM A .PNG IMAGE, and is doing it well but the background of the icon is black when I change what i have in my hand, this is not TOO bad but if i want to render a image that covers the entire screen every time i select a diferent item the background will turn black(MY IMAGE IS .PNG AND THE BACKGROUND IS NOT BLACK)

 

https://imgur.com/a/M0KgTaG (from imgur the background looks black but download the image and open it in a photo editor and you will see that is transparent)

 

public static final ResourceLocation ICONS = new ResourceLocation(TotisMod.MOD_ID,"textures/gui/icons.png");

@SubscribeEvent
    public static void renderOverlay(RenderGameOverlayEvent event) //i cant use .Pre or .Post because the survival hunger and health bars will bug
    {
        Minecraft mc = Minecraft.getInstance();
        if(event.getType() == RenderGameOverlayEvent.ElementType.TEXT) //if i use .ALL the background will ALWAYS be black and i HAVE to put this if statement or hunger and health bars will bug
        {
            mc.getTextureManager().bindTexture(ICONS);
            drawTexturedModalRect(0,0,144,0,16,16,1); //i tried to put for example 100 and 0 in Z level but apparently it doesnt change anything
        }
    }

 

Link to comment
Share on other sites

4 hours ago, diesieben07 said:

To draw something on the HUD you must use RenderGameOverlayEvent.Post with ElementType.ALL. Subscribing to a parent event class (like RenderGameOverlayEvent) directly almost never achieves useful results.

When drawing on the HUD with a different texture, you must switch back to the normal HUD texture (AbstractGui.GUI_ICONS_LOCATION) afterwards.

where i put AbstractGui.ICONS, and what do you mean with "subscribing to a parent event class", is like this?

@SubscribeEvent
public static void render1(RenderGameOverlayEvent.Post event)
{
		Minecraft mc = Minecraft.getInstance();
        if(event.getType() == RenderGameOverlayEvent.ElementType.ALL)
        {
            mc.getTextureManager().bindTexture(ICONS);
            drawTexturedModalRect(0,0,144,0,16,16,1);
        }
}

@SubscribeEvent
public static void render2(RenderGameOverlayEvent.Post event)
{
		render1()
		AbstractGui.ICONS;
}

 

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

After rendering your stuff, bind that texture.

RenderGameOverlayEvent is the parent class for RenderGameOverlayEvent.Pre and RenderGameOverlayEvent.Post. If you subscribe RenderGameOverlayEvent, you'll receive all subclasses, which is usually not useful at all.

Why do you have two event handlers now? Why is one calling the other? Nothing of this makes any sense.

dude you didnt explained me anything, "After rendering your stuff, bind that texture.", what does that mean??? i put drawTexturedModalRect and AFTER THAT mc.getTextureManager().bindTexture(ICONS);?? and you didnt tell me where i put the abstract gui thingy, and you told me to parent RenderGameOverlayEvent

 

AbstractGui.GUI_ICONS_LOCATION; what is this how i implement this

Edited by ElTotisPro50
Link to comment
Share on other sites

1 hour ago, diesieben07 said:

You already know how to bind a texture (I mean, you are binding your own texture... so I assumed you know...). So I don't really know what else to explain here.

Yes.

What?

@SubscribeEvent
    public static void renderOverlay(RenderGameOverlayEvent.Post event)
    {
        Minecraft mc = Minecraft.getInstance();
        GuiUtils gui = new GuiUtils();
        if(event.getType() == RenderGameOverlayEvent.ElementType.ALL)
        {
            drawTexturedModalRect(0,0,144,0,16,16,0);
            mc.getTextureManager().bindTexture(ICONS);
        }
    }

it DIDNT WORK

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

I have not said this. I used the term "parent" and "parent class". If you do not know what these means, you need to learn Java basics.

Why are you making a random GuiUtils instance?

Why are you no longer binding your own texture?

im binding my texture, ICONS is my texture:

public static final ResourceLocation ICONS = new ResourceLocation(TotisMod.MOD_ID,"textures/gui/icons.png")

the random GuiUtil instance is because is for another thing ignore it, then why is not working is showing me like the texture of the hearts that you have when the wither affects you?(like the black hearts) but only one and a half because i said that the texture is 16x16

Link to comment
Share on other sites

6 hours ago, diesieben07 said:

You have to first bind your texture. Then render your stuff. Then bind the vanilla icons texture again, because that is what the rest of the HUD code expect. The vanilla hud texture is AbstractGui.ICONS.

It worked!!!(you could have told me just that instead of "subscribing parenting RenderGameOverlayEvent" and that things)

 

this is the code that works:

@SubscribeEvent
    public static void renderOverlay(RenderGameOverlayEvent.Post event)
    {
        Minecraft mc = Minecraft.getInstance();

        if(event.getType() == RenderGameOverlayEvent.ElementType.ALL)
        {
            mc.getTextureManager().bindTexture(ICONS);
            drawTexturedModalRect(0,0,144,0,16,16,0);
            mc.getTextureManager().bindTexture(AbstractGui.GUI_ICONS_LOCATION);
        }
    }

 

Link to comment
Share on other sites

59 minutes ago, diesieben07 said:

I... did?

To draw something on the HUD you must use RenderGameOverlayEvent.Post with ElementType.ALL. Subscribing to a parent event class (like RenderGameOverlayEvent) directly almost never achieves useful results.

When drawing on the HUD with a different texture, you must switch back to the normal HUD texture (AbstractGui.GUI_ICONS_LOCATION) afterwards.

you should have said different words, instead of "switch back to the normal HUD TEXTURE AbstractGui.ICONS",        "bind your Icons,draw your stuff and bind AbstractGui.ICONS", I could have understood that perfectly because you didnt say me BIND AbstractGui just SWITCH, i know it sound stupid but idk is easier even is an overlay is not so basic

Link to comment
Share on other sites

On 1/16/2022 at 11:27 AM, diesieben07 said:

I... did?

hi, im here againt because i need something, the all my overlays are 256x256, even those from some overlay tutorials, but i've seen some people that uses overlays of 1920x1080 and i tried but it kind of duplicate (my overlays of 256x256 works)

 

(1920x1080)

this is how it should look: https://imgur.com/a/p8pXEzn

and this is how IT LOOKS: https://imgur.com/a/4F35AAP

mc.getTextureManager().bindTexture(textureLocation);
//gui.drawTexturedModalRect(x, y, imageOffsetX, imageOffsetY, imageSizeX, imageSizeY,zLevel);
gui.drawTexturedModalRect(x, y, 0, 0, 1920, 1080,100);
mc.getTextureManager().bindTexture(AbstractGui.GUI_ICONS_LOCATION);

 

Edited by ElTotisPro50
Link to comment
Share on other sites

12 hours ago, poopoodice said:

You have to declare the dimension of the texture, the default value is 256x256 (from the method you are using)

dude see me code, drawTexturedModalRect(X,Y,IMAGEOFFSETX,IMAGEOFFSETY,1920,1080,ZLEVEL)

with drawTexturedModalRect the max size of the image is 1920x1080?, what method should i use

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

drawTexturedModalRect assumes that by default your texture is 256x256. There are variants that let you specify the total texture size (as opposed to just the part you want to draw) as well. You need to do use those if you want a texture that is not 256x256. Note also that your texture file should be a power of 2.

which method i have to use, there are a lot and i only learned drawTexturedModalRect

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

It's also called drawTexturedModalRect, just with more parameters.

there are only 2 drawTexturedModalRect, the ONLY DIFFERENCE between those 2 is that one has a MatrixStack at the beginning, 

The one i use for 256x256
public static void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, float zLevel)

the one u told me (do i have to use this one right?)
public static void drawTexturedModalRect(MatrixStack matrixStack, int x, int y, int u, int v, int width, int height, float zLevel)

 

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

It's also called drawTexturedModalRect, just with more parameters.

it didnt work: 

MatrixStack stack = new MatrixStack();
mc.getTextureManager().bindTexture(textureLocation);
gui.drawTexturedModalRect(stack,x, y, imageOffsetX, imageOffsetY, imageSizeX, imageSizeY,zLevel);
mc.getTextureManager().bindTexture(AbstractGui.GUI_ICONS_LOCATION);

 

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

You have not changed anything...?

yeah, the one i used before i told about the 1920x1080 doesnt have the MatrixStack, 

THIS IS WHAT I WAS USING
public static void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, float zLevel)

THIS IS WHAT YOU TOLD ME(there are only 2 drawTexturedModalRect and you said that i have to use the one with "different parameters, this has an extra parameter which is MatrixStack")
public static void drawTexturedModalRect(MatrixStack matrixStack, int x, int y, int u, int v, int width, int height, float zLevel)

 

Link to comment
Share on other sites

1 hour ago, poopoodice said:

AbstractGui.blit

   public static void blit(MatrixStack matrixStack, int x, int y, float uOffset, float vOffset, int width, int height, int textureWidth, int textureHeight) {

 

there are 2 new values, int width ant height, i tried to put 1920x1080 and 50x50 but it didnt work, what those values do? i guess is not the size of the image or the offset because them are already defined

 

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.



×
×
  • Create New...

Important Information

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