Jump to content

[Solved][1.16.5] Issue with rendering texture using Tessellator and BufferBuilder


Recommended Posts

Posted (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 by MonkeyKnight
Posted

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?

  • MonkeyKnight changed the title to [1.16.5] Issue with rendering texture using Tessellator and BufferBuilder
Posted

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?

bug.png.1dc7046e9156a87a0a2cd9a15608bc5c.png

  • MonkeyKnight changed the title to [Solved][1.16.5] Issue with rendering texture using Tessellator and BufferBuilder
Posted

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

 

  • Thanks 1

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.