Jump to content

[Solved] [1.12.2] Using the Tessellator to draw a Quad in the world


Recommended Posts

Posted (edited)

As the title says, I'm trying to use the Tessellator to draw a Quad in the world. My aim is to eventually draw lines in front of the player as they're casting a spell, as an cool effect, but I'm currently just trying to draw a Quad in a static location to learn my way around the Tessellator before getting fancy. I want the Quad to have a flat color instead of a block texture, which I think is achievable through the POSITION_COLOR and BufferBuilder#color methods.

 

My code is posted below. It doesn't actually render anything in any of the locations I would expect from any combination of the translation methods / vertex positions. (I'm not sure exactly how those things work, so there's a good chance that's where I'm going wrong here. My assumption would be that the BufferBuilder#setTranslation method sets the location that the vertices are placed in relation to, and that the GlStateManager#translate method translates that location, but nothing renders in the location 0, (70 + 60), 0, so I might be wrong.)

However, it doesn't give any errors, or wreck the rendering of other things, and it is being run, since the print method prints whenever I set i to 1.

 

It would be great if someone could tell me which bit I'm missing/misunderstanding, as I've spent a considerable time looking through source code and open source mods without seeing much difference that I can discern with my inexperienced eyeballs.

 

Spoiler

package artificialartificing;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.RenderTickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EventHandlerMain
{
	public static int i = 1;
	
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void renderTickEvent(RenderTickEvent event)
	{
		GlStateManager.pushMatrix();
		GlStateManager.disableTexture2D();
		GlStateManager.enableBlend();
		GlStateManager.disableAlpha();
		GlStateManager.translate(0, 60, 0);
		
		Tessellator tessellator = Tessellator.getInstance();
		BufferBuilder buffer = tessellator.getBuffer();
		
		buffer.setTranslation(0, 70, 0);
		
		buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
		
		buffer.pos(-1, 60, -1).color(250, 250, 250, 100).endVertex();
		buffer.pos(-1, 60, 1).color(250, 250, 250, 100).endVertex();
		buffer.pos(1, 60, 1).color(250, 250, 250, 100).endVertex();
		buffer.pos(1, 60, -1).color(250, 250, 250, 100).endVertex();
		
		tessellator.draw();

		
		buffer.setTranslation(0, 0, 0);
		GlStateManager.disableBlend();
		GlStateManager.enableAlpha();
		GlStateManager.enableTexture2D();
		GlStateManager.popMatrix();
		
		if (i == 1)
		{
			System.out.println("Hello from the bottom of renderTickEvent.");
			i = 0;
		}
	}
}

 

 

Edited by SerpentDagger

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted

I've gotten it to work now, after copying a couple lines of translation code from Cadiboo's example here, for a different topic. The rest was correct. I think I understand how the translation works now, but if someone could confirm or correct, that would be great.

It looks like BufferBuilder#setTranslation() sets the translation of the position origin in relation to the entity rendering the screen, rather than in relation to the world origin, and Cadiboo's code translates the position from the entity back to the world origin, so that you can draw something with world coordinates instead, by passing said world coords into the BufferBuilder#pos() method while building a vertex.

 

2019-09-13_13_18_03.thumb.png.91f968f04df1950788fd8a54118c09e1.png

 

I also found that it wasn't rendering from the bottom, because I hadn't used GlStateManager#disableCull() before the drawing.

 

Cull enabled from underneath:

2019-09-13_13_18_10.thumb.png.cb7cda2802705b2c6e6a480ad6acbcdb.png

 

Cull disabled from underneath:

2019-09-13_13_46_46.thumb.png.47a42d553a5e4d6f3f2ffeafca882b5c.png

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

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.