Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16] Transparent Picture Render in GUI
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
monkeysHK

[1.16] Transparent Picture Render in GUI

By monkeysHK, January 17 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

monkeysHK    0

monkeysHK

monkeysHK    0

  • Tree Puncher
  • monkeysHK
  • Members
  • 0
  • 17 posts
Posted January 17

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.

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted January 17

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.

  • Quote

Share this post


Link to post
Share on other sites

monkeysHK    0

monkeysHK

monkeysHK    0

  • Tree Puncher
  • monkeysHK
  • Members
  • 0
  • 17 posts
Posted January 18 (edited)
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 January 18 by monkeysHK
  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted January 18

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.

  • Quote

Share this post


Link to post
Share on other sites

monkeysHK    0

monkeysHK

monkeysHK    0

  • Tree Puncher
  • monkeysHK
  • Members
  • 0
  • 17 posts
Posted January 18

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

 

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted January 18

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.

  • Quote

Share this post


Link to post
Share on other sites

monkeysHK    0

monkeysHK

monkeysHK    0

  • Tree Puncher
  • monkeysHK
  • Members
  • 0
  • 17 posts
Posted January 19

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

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Deadlocked47
      Can't get into forge discord

      By Deadlocked47 · Posted 4 minutes ago

      bump
    • IntentScarab
      (SOLVED)[1.16.4] Block entity invalid

      By IntentScarab · Posted 19 minutes ago

      I've been coding for like four years and it seems like I still don't know what it means. I'm gonna research what it means now cause it's been too long 😅   I've took off the static property and commented out all the code that was complaining for the meantime. That has cleared up the problem about the error showing.   Thank you for the help!!
    • diesieben07
      (SOLVED)[1.16.4] Block entity invalid

      By diesieben07 · Posted 30 minutes ago

      This field must not be static. Please learn what static means and why it is not appropriate here.
    • BeardlessBrady
      [1.16.4] Copying file from assets to config folder

      By BeardlessBrady · Posted 33 minutes ago

      I am trying to create a resource pack on mod load. I have everything but creating the default assets, Is there a way to grab an asset file and copy it to the config folder without going through the jar and copy/pasting it?
    • IntentScarab
      (SOLVED)[1.16.4] Block entity invalid

      By IntentScarab · Posted 38 minutes ago

      Sweet, made those changes now, thank you   https://github.com/RhysGrabany/Experienced Here you go, the changes I've made rn are under the tile_passing branch
  • Topics

    • Deadlocked47
      1
      Can't get into forge discord

      By Deadlocked47
      Started 21 hours ago

    • IntentScarab
      6
      (SOLVED)[1.16.4] Block entity invalid

      By IntentScarab
      Started 1 hour ago

    • BeardlessBrady
      0
      [1.16.4] Copying file from assets to config folder

      By BeardlessBrady
      Started 33 minutes ago

    • ISenseHostility
      10
      [1.16.5] Couldn't parse loot modifier error

      By ISenseHostility
      Started 17 hours ago

    • NorthWestWind
      3
      [UNSOLVED][1.16.5] Make item render like bow in thirdperson

      By NorthWestWind
      Started Yesterday at 02:49 PM

  • Who's Online (See full list)

    • BeardlessBrady
    • Deadlocked47
    • DrummingTom12
    • vemerion
    • IntentScarab
    • diesieben07
    • starlite_moon
    • samjviana
    • filips
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16] Transparent Picture Render in GUI
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community