MonkeyKnight Posted May 5, 2021 Posted May 5, 2021 (edited) I have coded a little test to experiment with rendering fullscreen overlays for my mod in Minecraft. As it is my first time delving into this kind of rendering, I started off simple, basically copying the renderPumpkin() method but I am having issues. My goal is to render textures that will show up on a player's screen in certain situations. For this test, I just went with the standard pumpkinblur. I used a RenderGameOverlayEvent.Post to trigger the rendering of the pumpkin. Here is my event code: @EventBusSubscriber(modid = Epidemics.MOD_ID, bus = Bus.FORGE) public class GuiRenderEvents { @SubscribeEvent public static void renderGameOverlay(RenderGameOverlayEvent.Post event) { if (event.getType() == RenderGameOverlayEvent.ElementType.HOTBAR) { //System.out.println("Event Triggered"); new RenderTest(Minecraft.getInstance()); } } } I then created a class that extends InGameGUI to render the pumpkin. It almost directly copies the renderPumpkin() method in InGameGUI. import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.IngameGui; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; public class RenderTest extends IngameGui{ public RenderTest(Minecraft minecraft) { super(minecraft); renderTest(minecraft); } private void renderTest(Minecraft minecraft) { RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.defaultBlendFunc(); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.disableAlphaTest(); minecraft.getTextureManager().bind(PUMPKIN_BLUR_LOCATION); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuilder(); bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX); bufferbuilder.vertex(0.0D, (double)this.screenHeight, -90.0D).uv(0.0F, 1.0F).endVertex(); bufferbuilder.vertex((double)this.screenWidth, (double)this.screenHeight, -90.0D).uv(1.0F, 1.0F).endVertex(); bufferbuilder.vertex((double)this.screenWidth, 0.0D, -90.0D).uv(1.0F, 0.0F).endVertex(); bufferbuilder.vertex(0.0D, 0.0D, -90.0D).uv(0.0F, 0.0F).endVertex(); tessellator.end(); RenderSystem.depthMask(true); RenderSystem.enableDepthTest(); RenderSystem.enableAlphaTest(); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); } } The renderTest() method is being triggered but I do not see anything on my screen. Can you spot where I might have forgotten something? Edited May 6, 2021 by MonkeyKnight Quote
MonkeyKnight Posted May 6, 2021 Author Posted May 6, 2021 I have a quick update. I have narrowed down the issue to the renderGameOverlay.post event. I changed the code of the renderTest constructor to just trigger the vanilla renderPumpkin() method and there still was no pumpkin face shown. public RenderTest(Minecraft minecraft) { super(minecraft); renderPumpkin(); /* screenWidth = minecraft.getWindow().getGuiScaledWidth(); screenHeight = minecraft.getWindow().getGuiScaledHeight(); renderTest(minecraft); */ } Do you have any suggestions on what I should change in my render event? Quote
MonkeyKnight Posted May 6, 2021 Author Posted May 6, 2021 I have another update! I changed my render event code to this: @EventBusSubscriber(modid = Epidemics.MOD_ID, bus = Bus.FORGE) public class GuiRenderEvents { @SubscribeEvent public static void renderGameOverlay(RenderGameOverlayEvent.Post event) { if (event.getType() == RenderGameOverlayEvent.ElementType.HOTBAR) { System.out.println(1); RenderTest render = new RenderTest(Minecraft.getInstance()); render.renderTestPumpkin(Minecraft.getInstance()); } } } public class RenderTest extends IngameGui{ private int screenWidth; private int screenHeight; public RenderTest(Minecraft minecraft) { super(minecraft); screenWidth = minecraft.getWindow().getGuiScaledWidth(); screenHeight = minecraft.getWindow().getGuiScaledHeight(); /* renderTest(minecraft); */ } public void renderTestPumpkin(Minecraft minecraft) { RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.defaultBlendFunc(); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.disableAlphaTest(); minecraft.getTextureManager().bind(PUMPKIN_BLUR_LOCATION); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuilder(); bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX); bufferbuilder.vertex(0.0D, (double)screenHeight, -90.0D).uv(0.0F, 1.0F).endVertex(); bufferbuilder.vertex((double)screenWidth, (double)screenHeight, -90.0D).uv(1.0F, 1.0F).endVertex(); bufferbuilder.vertex((double)screenWidth, 0.0D, -90.0D).uv(1.0F, 0.0F).endVertex(); bufferbuilder.vertex(0.0D, 0.0D, -90.0D).uv(0.0F, 0.0F).endVertex(); tessellator.end(); RenderSystem.depthMask(true); RenderSystem.enableDepthTest(); RenderSystem.enableAlphaTest(); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); } } Now it is showing up n the game, just as a black screen though. Do you know what is causing the black screen? Quote
MonkeyKnight Posted May 6, 2021 Author Posted May 6, 2021 Never mind, it works fine now. I just forgot to blend it. Quote
eggpasta Posted May 6, 2021 Posted May 6, 2021 On 5/6/2021 at 3:10 PM, MonkeyKnight said: Never mind, it works fine now. I just forgot to blend it. Expand Can you show what that looks like? I would like to try this Quote
MonkeyKnight Posted May 6, 2021 Author Posted May 6, 2021 Sure, here are my two classes that I used. The render event: @EventBusSubscriber(modid = Epidemics.MOD_ID, bus = Bus.FORGE) public class GuiRenderEvents { @SubscribeEvent public static void renderGameOverlay(RenderGameOverlayEvent.Post event) { if (event.getType() == RenderGameOverlayEvent.ElementType.ALL) { System.out.println(1); RenderTest render = new RenderTest(Minecraft.getInstance()); render.renderTestPumpkin(Minecraft.getInstance()); } } } The renderer: public class RenderTest extends IngameGui{ public static final ResourceLocation NEW_PUMPKIN_LOCATION = new ResourceLocation(Epidemics.MOD_ID + ":textures/gui/pumpkinblurtest.png"); private int screenWidth; private int screenHeight; public RenderTest(Minecraft minecraft) { super(minecraft); screenWidth = minecraft.getWindow().getGuiScaledWidth(); screenHeight = minecraft.getWindow().getGuiScaledHeight(); } public void renderTestPumpkin(Minecraft minecraft) { RenderSystem.disableDepthTest(); RenderSystem.enableBlend(); RenderSystem.depthMask(false); RenderSystem.defaultBlendFunc(); RenderSystem.blendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.disableAlphaTest(); minecraft.getTextureManager().bind(NEW_PUMPKIN_LOCATION); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuilder(); bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX); bufferbuilder.vertex(0.0D, (double)screenHeight, -90.0D).uv(0.0F, 1.0F).endVertex(); bufferbuilder.vertex((double)screenWidth, (double)screenHeight, -90.0D).uv(1.0F, 1.0F).endVertex(); bufferbuilder.vertex((double)screenWidth, 0.0D, -90.0D).uv(1.0F, 0.0F).endVertex(); bufferbuilder.vertex(0.0D, 0.0D, -90.0D).uv(0.0F, 0.0F).endVertex(); tessellator.end(); RenderSystem.depthMask(true); RenderSystem.enableDepthTest(); RenderSystem.enableAlphaTest(); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); } } 1 Quote
Recommended Posts
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.