Jump to content

[1.7.10] Weird Texture glitch


weckar

Recommended Posts

[Please see latest post for a new screenshot of the current condition.]

 

Sooo I've been working on my TESR, and am trying to just draw a dang block  :P

Apparently, harder than expected. So I made a method to do it for me. And it DOES draw the block with the proper texturing! Unfortunately, it also makes the block flicker black randomly across the surface as I move around it. I THINK I may have messed up the UV mapping, but I'm not sure...

example.png

protected void drawBlock(float x, float y, float z, float w, float h, float l, Block block, int meta){
	IIcon[] icons = new IIcon[6];
	for(int i = 0; i<6; i++){
		icons[i] = block.getIcon(i,meta);
	}
	GL11.glPushMatrix();
	GL11.glTranslatef(x, y, z);
	tess.startDrawingQuads();
	//top
	tess.setNormal(0.0F, 0.0F, 1.0F);
	tess.addVertexWithUV(w,h,l,icons[1].getMaxU(),icons[1].getMaxV());
	tess.addVertexWithUV(w,0,l,icons[1].getMaxU(),icons[1].getMinV());
	tess.addVertexWithUV(0,0,l,icons[1].getMinU(),icons[1].getMinV());
	tess.addVertexWithUV(0,h,l,icons[1].getMinU(),icons[1].getMaxV());
	//bottom
	tess.setNormal(0.0F, 0.0F,-1.0F);
	tess.addVertexWithUV(w,h,0,icons[0].getMaxU(),icons[0].getMaxV());
	tess.addVertexWithUV(w,0,0,icons[0].getMaxU(),icons[0].getMinV());
	tess.addVertexWithUV(0,0,0,icons[0].getMinU(),icons[0].getMinV());
	tess.addVertexWithUV(0,h,0,icons[0].getMinU(),icons[0].getMaxV());
	//south
	tess.setNormal(0.0F, 1.0F, 0.0F);
	tess.addVertexWithUV(w,h,l,icons[2].getMaxU(),icons[2].getMaxV());
	tess.addVertexWithUV(w,h,0,icons[2].getMaxU(),icons[2].getMinV());
	tess.addVertexWithUV(0,h,0,icons[2].getMinU(),icons[2].getMinV());
	tess.addVertexWithUV(0,h,l,icons[2].getMinU(),icons[2].getMaxV());
	//north
	tess.setNormal(0.0F, -1.0F, 0.0F);
	tess.addVertexWithUV(w,0,l,icons[3].getMaxU(),icons[3].getMaxV());
	tess.addVertexWithUV(w,0,0,icons[3].getMaxU(),icons[3].getMinV());
	tess.addVertexWithUV(0,0,0,icons[3].getMinU(),icons[3].getMinV());
	tess.addVertexWithUV(0,0,l,icons[3].getMinU(),icons[3].getMaxV());
	//east
	tess.setNormal(1.0F, 0.0F, 0.0F);
	tess.addVertexWithUV(w,h,l,icons[5].getMaxU(),icons[5].getMaxV());
	tess.addVertexWithUV(w,h,0,icons[5].getMaxU(),icons[5].getMinV());
	tess.addVertexWithUV(w,0,0,icons[5].getMinU(),icons[5].getMinV());
	tess.addVertexWithUV(w,0,l,icons[5].getMinU(),icons[5].getMaxV());
	//west
	tess.setNormal(-1.0F, 0.0F, 0.0F);
	tess.addVertexWithUV(0,h,l,icons[4].getMaxU(),icons[4].getMaxV());
	tess.addVertexWithUV(0,h,0,icons[4].getMaxU(),icons[4].getMinV());
	tess.addVertexWithUV(0,0,0,icons[4].getMinU(),icons[4].getMinV());
	tess.addVertexWithUV(0,0,l,icons[4].getMinU(),icons[4].getMaxV());
	tess.draw();
	GL11.glPopMatrix();
}

 

Maybe some pointers would be nice, as none of the TESR tutorials I found specifically deal with drawing cuboids...

 

[EDIT] So, apparently I forgot the turn off the actual block's rendering, but in the process I learned this method is messed up in many ways regardless. Maybe I should restart it from scratch? I'd still appreciate any and all advice.

If anyone has a comprehensive, visual guide to GUIs - don't hesitate to message me. They make my head spin.

Link to comment
Share on other sites

Unfortunately, it also makes the block flicker black randomly across the surface as I move around it.

 

That's called Z-Fighting.

https://en.wikipedia.org/wiki/Z-fighting

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

Yeah, got that bit covered. See the [EDIT]. Thanks anyway though, now I know a technical term for it! :)

 

[EDIT] So now I am getting the blocks to render properly (the order of some of the vertices was wrong before), but now the oddest thing happens: If I am not looking in a limited cone of directions (on all axis), none of the blocks render at all. They all disappear at once, not one at a time. It is therefore not to do with the Render Bounding Box..

 

[EDIT2] After a little more experimenting, it seems to only draw if I WOULD be able to see coordinates 0,0,0 in my crosshairs. Am I messing up translation or something? None of my other drawing commands are showing this behaviour so I think I may be using the Tesselator wrong...

 

If anyone has a comprehensive, visual guide to GUIs - don't hesitate to message me. They make my head spin.

Link to comment
Share on other sites

After a lot more testing and trying, I've come up with a few more facts of the case:

 

  • My assessment that it had to do with looking at the 0,0,0 point has been proved false. It depends on the world, it seems.
  • The problem is limited to this method, and even then only when it is called in render pass 0.
  • However, rendering in pass 1 instead seems to invert both the internal and external drawing order among the Tile Entities. The inside is drawn outside causing weird overlaps and a very Escherian feeling...

 

I feel like I'm getting closer, but there is still a few things that elude me here...

 

[EDIT] Felt it was time for another screenshot of the current situation. This shape is made up of 5 cuboids, just for testing purposes. It is currently being drawn in render pass 1.example.png

If anyone has a comprehensive, visual guide to GUIs - don't hesitate to message me. They make my head spin.

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.

Announcements



×
×
  • Create New...

Important Information

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