Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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.

  • Author
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

Setting the alpha state does not enable transparency. You need to set up the blend function in such a way such that the rgba inputs are being blended correctly. This is why I mentioned TRANSLUCENT_TRANSPARENCY.

  • Author

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();

 

Try without RenderSystem::blendColor. If not, try disabling the depth test (disableDepthTest) and depth mask (depthMask). Remember that these should be reset during the teardown phase.

  • Author

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();

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.