Jump to content

[1.16] Transparent Picture Render in GUI


monkeysHK

Recommended Posts

Hello. I am having trouble making a picture render transparent on my Screen and I am not sure what the problem is. It renders correctly but not transparent.

Here is my code in MyScreen::render

Also I want to know how to remove the effect of RenderSystem afterwards for further renders.

                TextureManager tm = minecraft.getTextureManager();
                ResourceLocation rl = new ResourceLocation("minecraft", "textures/gui/widgets.png");
                tm.bindTexture(rl);
                matrixStack.push();
                {
                    RenderSystem.colorMask(true, true, true, true);
                    RenderSystem.blendColor(1f, 1f, 1f, 0.5f);
                    RenderSystem.enableBlend();
                    matrixStack.translate(instru_pos[currentNbo.ordinal()][0], instru_pos[currentNbo.ordinal()][1], 0);
                    matrixStack.scale(scale, scale, scale);
                    this.blit(matrixStack, 0, 0, 0, 146, 20, 20);
                }
                matrixStack.pop();

Any replies will be appreciated.

Link to comment
Share on other sites

Whenever trying to use RenderSystem, a good reference is the RenderState class as it shows you the startup and teardown methods needed to handle what you need. In this case, I would suggest looking at RenderState#TRANSLUCENT_TRANSPARENCY. As a side note, whenever possible, IRenderTypeBuffer should be used to handle drawing objects to the screen, although in this case it is not that applicable.

Link to comment
Share on other sites

On 1/17/2021 at 9:42 AM, ChampionAsh5357 said:

a good reference is the RenderState

It was a really good reference to look at.

I am trying to define a RenderState and use their constructor and their setup and clear functions. But it still wouldn't work.

    private static final RenderState.AlphaState HALF_ALPHA = new RenderState.AlphaState(0.5F);

                minecraft.getTextureManager().bindTexture(new ResourceLocation("minecraft", "textures/gui/widgets.png"));
                matrixStack.push();
                HALF_ALPHA.setupRenderState();
                {
                    matrixStack.translate(instru_pos[currentNbo.ordinal()][0], instru_pos[currentNbo.ordinal()][1], 0);
                    matrixStack.scale((255/20f)*scale, (255/20f)*scale, (255/20f)*scale);
                    this.blit(matrixStack, 0, 0, 0, 146, 20, 20);
                }
                HALF_ALPHA.clearRenderState();
                matrixStack.pop();

 

Edited by monkeysHK
Link to comment
Share on other sites

Hi. I tried translucent_transparency. I copied code from it to setup and clear the renderstate.

Still doesn't work, texture is not transparent. Am I missing something?

 

                minecraft.getTextureManager().bindTexture(TEXTURE_LOC);

                matrixStack.push();
                {
                    RenderSystem.enableBlend();
                    RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
                    RenderSystem.blendColor(1f, 1f, 1f, 0.5f);
                    matrixStack.translate(instru_pos[currentNbo.ordinal()][0], instru_pos[currentNbo.ordinal()][1], 0);
                    matrixStack.scale((255/20f)*scale, (255/20f)*scale, (255/20f)*scale);
                    this.blit(matrixStack, 0, 0, 0, 146, 20, 20);
                    RenderSystem.disableBlend();
                    RenderSystem.defaultBlendFunc();
                }
                matrixStack.pop();

 

Link to comment
Share on other sites

Ok, I tried that a few more ways, but the only way worked is to replace blendColor with the depreciated color4f. (Not sure if that's the best way to go for but that worked)

Thank you @ChampionAsh5357 for all the suggestions/help

    private static final RenderState.TransparencyState TRANSLUCENT_TRANSPARENCY = new RenderState.TransparencyState("translucent_transparency", () -> {
        RenderSystem.enableBlend();
        RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
    }, () -> {
        RenderSystem.disableBlend();
        RenderSystem.defaultBlendFunc();
    });

                    TRANSLUCENT_TRANSPARENCY.setupRenderState();
                    RenderSystem.color4f(1f, 1f, 1f, 0.3f);
                    matrixStack.translate(instru_pos[currentNbo.ordinal()][0], instru_pos[currentNbo.ordinal()][1], 0);
                    matrixStack.scale((255/20f)*scale, (255/20f)*scale, (255/20f)*scale);
                    this.blit(matrixStack, 0, 0, 0, 146, 20, 20);
                    TRANSLUCENT_TRANSPARENCY.clearRenderState();
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.

Announcements



×
×
  • Create New...

Important Information

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