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

[1.9] [Unsolved] Rendering help


tiffit
 Share

Recommended Posts

I am having trouble with rending a box. There is a weird "quad" that is rendering at (0, 0, 0). It seems to only happen when I render more than 1 quad.

 

Here is the rendering code:

public static final void renderSelectionBox(
		Tessellator tessellator, VertexBuffer ren,
		float minX, float minY, float minZ,
		float maxX, float maxY, float maxZ, float a
		) {
	float U = Math.round(maxX - minX);
	float V = Math.round(maxY - minY);
	float W = Math.round(maxZ - minZ);
	float VOLUME = U*V*W;

	float SPEED = 10000;
	float UVW_DIVIDE = 1;

	if(VOLUME > (128*128*128)) {
		UVW_DIVIDE = 128f;
		SPEED = 10000;
	} else if(VOLUME > (16*16*16)) {
		UVW_DIVIDE = 16f;
		SPEED = 7500;
	} else {
		UVW_DIVIDE = 1;
		SPEED = 3000;
	}

	// divide
	U /= UVW_DIVIDE;
	V /= UVW_DIVIDE;
	W /= UVW_DIVIDE;

	float u0 = 0;
	float u1 = U;
	float v0 = 0;
	float v1 = V;
	float w0 = 0;
	float w1 = W;

	{
		final long speedL = (long) SPEED;
		final float speedF = SPEED;

		float f4 = Minecraft.getSystemTime() % speedL / speedF;
		float ADD = f4;

		u0 += ADD;
		u1 += ADD;
		v0 += ADD;
		v1 += ADD;
		w0 += ADD;
		w1 += ADD;
	}

	float r = 1;
	float g = 0.5f;
	float b = 0;

	if(a == -1) {
		a = 1;
		r = 0;
		g = 0;
		b = 0;
	}

	if(a == -2) {
		a = 1;
		r = 0;
		g = 1;
		b = 0;
	}

	if(a == -3) {
		a = 1;
		r = 1;
		g = 0.25f;
		b = 0.25f;
	}
	VertexBufferHelper vertexbuffer = new VertexBufferHelper(ren);
	// top
	vertexbuffer.startDrawingQuads();
	vertexbuffer.color(r, g, b, a);
	vertexbuffer.normal(0, 1, 0);
	vertexbuffer.addVertexWithUV(minX, maxY, maxZ, u0, w0);
	vertexbuffer.addVertexWithUV(maxX, maxY, maxZ, u1, w0);
	vertexbuffer.addVertexWithUV(maxX, maxY, minZ, u1, w1);
	vertexbuffer.addVertexWithUV(minX, maxY, minZ, u0, w1);
	// bottom
	vertexbuffer.normal(0, -1, 0);
	vertexbuffer.addVertexWithUV(minX, minY, minZ, u0, w0);
	vertexbuffer.addVertexWithUV(maxX, minY, minZ, u1, w0);
	vertexbuffer.addVertexWithUV(maxX, minY, maxZ, u1, w1);
	vertexbuffer.addVertexWithUV(minX, minY, maxZ, u0, w1);
	// negative z | north
	vertexbuffer.normal(0, 0, -1);
	vertexbuffer.addVertexWithUV(minX, maxY, minZ, u0, v0);
	vertexbuffer.addVertexWithUV(maxX, maxY, minZ, u1, v0);
	vertexbuffer.addVertexWithUV(maxX, minY, minZ, u1, v1);
	vertexbuffer.addVertexWithUV(minX, minY, minZ, u0, v1);
	// positive z | south
	vertexbuffer.normal(0, 0, 1);
	vertexbuffer.addVertexWithUV(maxX, maxY, maxZ, u0, v0);
	vertexbuffer.addVertexWithUV(minX, maxY, maxZ, u1, v0);
	vertexbuffer.addVertexWithUV(minX, minY, maxZ, u1, v1);
	vertexbuffer.addVertexWithUV(maxX, minY, maxZ, u0, v1);
	 //positive x | east
	vertexbuffer.normal(1, 0, 0);
	vertexbuffer.addVertexWithUV(maxX, maxY, minZ, w0, v0);
	vertexbuffer.addVertexWithUV(maxX, maxY, maxZ, w1, v0);
	vertexbuffer.addVertexWithUV(maxX, minY, maxZ, w1, v1);
	vertexbuffer.addVertexWithUV(maxX, minY, minZ, w0, v1);
	 //negative x | west
	vertexbuffer.normal(-1, 0, 0);
	vertexbuffer.addVertexWithUV(minX, maxY, maxZ, w0, v0);
	vertexbuffer.addVertexWithUV(minX, maxY, minZ, w1, v0);
	vertexbuffer.addVertexWithUV(minX, minY, minZ, w1, v1);
	vertexbuffer.addVertexWithUV(minX, minY, maxZ, w0, v1);
	tessellator.draw();
}

private static class VertexBufferHelper {
	private VertexBuffer rend;
	public VertexBufferHelper(VertexBuffer rend) {
		this.rend = rend;
	}

	public void startDrawingQuads() {
		rend.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
	}

	public VertexBuffer pos(double x, double y, double z) {
		return rend.pos(x, y, z);
	}

	public void setTranslation(int x, int y, int z) {
		rend.setTranslation(x, y, z);
	}

	public void addVertexWithUV(double x, double y, double z, float u, float v) {
		rend.pos(x, y, z).tex(u, v).endVertex();

	}

	public void normal(float x, float y, float z) {
		rend.normal(x, y, z);
	}

	public void color(float r, float g, float b, float a) {
		rend.color(r, g, b, a);
	}
}

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
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • public class ManaOverlay extends Gui implements IIngameOverlay { private final Minecraft mc; private Font font = null; public int left_height = 39; public int right_height = 49; private RenderGameOverlayEvent eventParent; public static final ResourceLocation GUI_MANA_LOCATION = new ResourceLocation("textures/gui/icons.png"); private static final ManaOverlay INSTANCE = new ManaOverlay(Minecraft.getInstance()); public ManaOverlay(Minecraft p_93005_) { super(p_93005_); this.mc = Minecraft.getInstance(); this.font = mc.font; OverlayRegistry.registerOverlayTop("Mana ", (gui, mStack, partialTicks, screenWidth, screenHeight) -> { boolean isMounted = gui.minecraft.player.getVehicle() instanceof LivingEntity; if (!isMounted && !gui.minecraft.options.hideGui && gui.shouldDrawSurvivalElements()) { setupOverlayRenderState(true, false); renderMana(screenWidth, screenHeight, mStack); } }); } public void setupOverlayRenderState(boolean blend, boolean depthText) { setupOverlayRenderState(blend, depthText, GUI_MANA_LOCATION); } public void setupOverlayRenderState(boolean blend, boolean depthTest, @Nullable ResourceLocation texture) { if (blend) { RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); } else { RenderSystem.disableBlend(); } if (depthTest) { RenderSystem.enableDepthTest(); } else { RenderSystem.disableDepthTest(); } if (texture != null) { RenderSystem.enableTexture(); bind(texture); } else { RenderSystem.disableTexture(); } RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShader(GameRenderer::getPositionTexShader); } public static void init() { MinecraftForge.EVENT_BUS.register(INSTANCE); } public void renderMana(int width, int height, PoseStack mStack) { minecraft.getProfiler().push("mana"); Player player = (Player)this.minecraft.getCameraEntity(); RenderSystem.enableBlend(); int left = width / 2 + 91; int top = height - right_height ; boolean unused = false;// Unused flag in vanilla, seems to be part of a 'fade out' mechanic FoodData stats = minecraft.player.getFoodData(); int level = stats.getFoodLevel(); for (int i = 0; i < 10; ++i) { int idx = i * 2 + 1; int x = left - i * 8 - 9; int y = top; int icon = 16; byte background = 0; if (minecraft.player.hasEffect(MobEffects.HUNGER)) { icon += 36; background = 13; } if (unused) background = 1; //Probably should be a += 1 but vanilla never uses this if (player.getFoodData().getSaturationLevel() <= 0.0F && tickCount % (level * 3 + 1) == 0) { y = top + (random.nextInt(3) - 1); } blit(mStack, x, y, 16 + background * 9, 27, 9, 9); if (idx < level) blit(mStack, x, y, icon + 36, 27, 9, 9); else if (idx == level) blit(mStack, x, y, icon + 45, 27, 9, 9); } RenderSystem.disableBlend(); minecraft.getProfiler().pop(); } @Override public void render(ForgeIngameGui gui, PoseStack pStack, float partialTicks, int width, int height) { this.screenWidth = this.minecraft.getWindow().getGuiScaledWidth(); this.screenHeight = this.minecraft.getWindow().getGuiScaledHeight(); eventParent = new RenderGameOverlayEvent(pStack, partialTicks, this.minecraft.getWindow()); if (pre(ALL, pStack)) return; font = minecraft.font; this.random.setSeed(tickCount * 312871L); OverlayRegistry.orderedEntries().forEach(entry -> { try { if (!entry.isEnabled()) return; IIngameOverlay overlay = entry.getOverlay(); if (pre(overlay, pStack)) return; //overlay.render(this, pStack, partialTicks, screenWidth, screenHeight); post(overlay, pStack); } catch(Exception e) { } }); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); post(ALL, pStack); } private boolean pre(RenderGameOverlayEvent.ElementType type, PoseStack mStack) { return MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.Pre(mStack, eventParent, type)); } private void post(RenderGameOverlayEvent.ElementType type, PoseStack mStack) { MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.Post(mStack, eventParent, type)); } private boolean pre(IIngameOverlay overlay, PoseStack mStack) { return MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.PreLayer(mStack, eventParent, overlay)); } private void post(IIngameOverlay overlay, PoseStack mStack) { MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.PostLayer(mStack, eventParent, overlay)); } private void bind(ResourceLocation res) { RenderSystem.setShaderTexture(0, res); } } Thanks to you, I was able to display it. However, the bar that uses the full stomach ground keeps shaking. I wonder why that is?  
    • It's the "Width on the screen" and "Height on the screen", so in this case the screen width and height.
    • I was able to post the 4 others, so they are on there now.
    • Could be "write", check vanilla for examples, or provide details of which version you're currently on.
    • I am trying to update a mod, and there does not seem to be any save() function in BlockEntity. What do I use instead?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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