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



×
×
  • Create New...

Important Information

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