Posted January 17, 20214 yr 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.
January 17, 20214 yr 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.
January 18, 20214 yr 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 January 18, 20214 yr by monkeysHK
January 18, 20214 yr 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.
January 18, 20214 yr 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();
January 18, 20214 yr 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.
January 19, 20214 yr 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.