Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

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


Recommended Posts

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.



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;
	public void renderTickEvent(RenderTickEvent event)
		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();

		buffer.setTranslation(0, 0, 0);
		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.

Link to comment
Share on other sites

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.




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:



Cull disabled from underneath:


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

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

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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.


  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.