Jump to content

[1.12.2] [SOLVED] Tesselator is drawing black when player looks certain angles


CosmicDan

Recommended Posts

Hi,

 

I'm trying to draw arbitrary things in the world. I based my initial work on "MoreOverlays" code (MIT licensed) which renders chunk boundaries and I do have some experience with drawing in OpenGL, but I have no idea why this happens - depending on the angle I'm looking at, it draws as either "partially black speckles" or completely black, instead of the color I set. Furthermore, the hex value given to GlStateManager.color is not always correct (e.g. 0xFFFFFF = pink).

 

Screenshots of problem:

 

1.png.632b5cac5413256b24bd7b2d9e04f18b.png

 

2.png.9fbc0bd86671e0a38099611b1ea94d4b.png

 

3.png.a68ebc3e1bfaab62f26f413fd9f91829.png

 

Current code:

 

@SubscribeEvent
	// tried both RenderWorldLastEvent and DrawBlockHighlightEvent; no difference
	//public void onRenderWorldLast(RenderWorldLastEvent event) {
	public static void drawMonumentPlacementOverlay(DrawBlockHighlightEvent event) {
  		// I know these don't belong here, it's just put here so I can HotSwap my code changes easily in debug mode
		final int lineWidth = 3;
		final int edgeRadius = 1;
		final int edgeColor = 0xFF0000;
		final int middleColor = 0x00FF00;
		final int gridColor = 0xFF0000;

		//log.info("Eh?");
		final EntityPlayer player = Minecraft.getMinecraft().player;
		if (player.getHeldItemMainhand().getItem().equals(Item.getItemFromBlock(ModBlocks.MONUMENT))) {
			Minecraft.getMinecraft().renderEngine.bindTexture(BLANK_TEX);
			GlStateManager.pushMatrix();
			GL11.glLineWidth(lineWidth);
			GlStateManager.translate(-render.viewerPosX, -render.viewerPosY, -render.viewerPosZ);

			int h = player.world.getHeight();
			int h0 = (int) player.posY;
			int h1 = Math.min(h, Math.max(h0 - 16, 0));
			int h2 = Math.min(h, Math.max(h0 + 16, 0));

			int x0 = player.chunkCoordX * 16;
			int x1 = x0 + 16;
			int x2 = x0 + 8;
			int z0 = player.chunkCoordZ * 16;
			int z1 = z0 + 16;
			int z2 = z0 + 8;

			int radius = edgeRadius * 16;

			GlStateManager.color( ((float)((edgeColor>>16) & 0xFF))/255F, ((float)((edgeColor>>8) & 0xFF))/255F, ((float)(edgeColor & 0xFF))/255F);
			for(int xo=-16-radius; xo<=radius; xo+=16){
				for(int yo=-16-radius; yo<=radius; yo+=16){
					renderEdge(x0-xo, z0-yo, h);
				}
            }

			GlStateManager.popMatrix();
		}
	}

	public static void renderEdge(double x, double z, double h) {
		Tessellator tess = Tessellator.getInstance();
		BufferBuilder renderer = tess.getBuffer();

		renderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION);

		renderer.pos(x, 0, z).endVertex();
		renderer.pos(x, h, z).endVertex();

		tess.draw();
	}

	

 

I've seen posts of people seeking answers for similar problems, but they're all for old Minecraft where functions no longer exist or don't solve them.

 

Greatly appreciate any help!

Edited by CosmicDan
Words

Windows software, Android hacking, and other curios

Link to comment
Share on other sites

3 hours ago, CosmicDan said:

Solved it. The "blank" texture needed to be a solid white, not 100% transparent.

More accurately, the texture needs to have white in its color channels. But most image programs discard text information when the opacity is 0, as it compresses better.

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.