Jump to content

Recommended Posts

Posted

Hi :)

I try to put a chunk into a box. It's working well when I watch a face but other face doesn't work well. (Sorry for my bad english)

These picture should help you to understand my problem :

 

here it's work : width=800 height=449http://www.aht.li/2574678/2015-01-31_021445.png[/img]

And when I move to other face, I have :

width=800 height=449http://www.aht.li/2574679/2015-01-31_021517.png[/img]

width=800 height=449http://www.aht.li/2574680/2015-01-31_021505.png[/img]

width=800 height=449http://www.aht.li/2574681/2015-01-31_021511.png[/img]

 

Here is the code :

​	private void highligthChunk(ForgeFactionChunk c) {


	EntityPlayer player = Minecraft.getMinecraft().thePlayer;

	int xPos = c.xPosition<<4;
	int zPos = c.zPosition<<4;

	drawChunkFaceY(player, xPos, zPos);

	drawChunkFaceX(player, xPos, zPos);
	drawChunkFaceX(player, xPos+16, zPos);

	drawChunkFaceZ(player, xPos, zPos);
	drawChunkFaceZ(player, xPos, zPos+16);
}

private void drawChunkFaceX(EntityPlayer player, int xPos, int zPos) {

	if(player.posX < xPos) {
		GL11.glVertex3f(xPos,player.worldObj.getActualHeight(),zPos);
		GL11.glVertex3f(xPos,0,zPos);
		GL11.glVertex3f(xPos,0,zPos+16);
		GL11.glVertex3f(xPos,player.worldObj.getActualHeight(),zPos+16);
	}else {
		GL11.glVertex3f(xPos,player.worldObj.getActualHeight(),zPos+16);
		GL11.glVertex3f(xPos,0,zPos+16);
		GL11.glVertex3f(xPos,0,zPos);
		GL11.glVertex3f(xPos,player.worldObj.getActualHeight(),zPos);
	}
}

private void drawChunkFaceY(EntityPlayer player, int xPos, int zPos) {
	int y = player.worldObj.getActualHeight();
	if(player.posY < y) {
		GL11.glVertex3f(xPos+16,y,zPos+16);
		GL11.glVertex3f(xPos,y,zPos+16);
		GL11.glVertex3f(xPos,y,zPos);
		GL11.glVertex3f(xPos+16,y,zPos);
	}else {
		GL11.glVertex3f(xPos+16,y,zPos);
		GL11.glVertex3f(xPos,y,zPos);
		GL11.glVertex3f(xPos,y,zPos+16);
		GL11.glVertex3f(xPos+16,y,zPos+16);
	}
}

private void drawChunkFaceZ(EntityPlayer player, int xPos, int zPos) {
	if(player.posZ < zPos) {
		GL11.glVertex3f(xPos+16,player.worldObj.getActualHeight(),zPos);
		GL11.glVertex3f(xPos+16,0,zPos);
		GL11.glVertex3f(xPos,0,zPos);
		GL11.glVertex3f(xPos,player.worldObj.getActualHeight(),zPos);

	}else {
		GL11.glVertex3f(xPos,player.worldObj.getActualHeight(),zPos);
		GL11.glVertex3f(xPos,0,zPos);
		GL11.glVertex3f(xPos+16,0,zPos);
		GL11.glVertex3f(xPos+16,player.worldObj.getActualHeight(),zPos);
	}
}

 

Thanks for your help

Posted

It is happening because the rendering order of partially transparent objects is important.

 

If you draw the nearest face first, it completely hides the furthest face due to depth culling.

 

You need to draw the further face first, then the nearest face.

 

-TGG

Posted

Thank you for your help TheGreyGhost :)

I try to sort face by distance, but I don't sucess :/

Is there a way to do it easy ? In fact, because I use it in a very often called method, I'm scared to write something not enought optimized.

I read that OpenGL Z-Buffer is useless with transparency, I read information about GL_ALPHA_TEST but I don't understand how to use it :/

Posted

Hi

 

Unfortunately there is no easier way to do it, but I wouldn't worry about optimising it, if you're only drawing a few faces it will take no time at all even if your code is very inefficient.

 

Because the faces are parallel to the x, y, or z axes, sorting is actually very easy.

 

For example - consider the two faces on the y axis - the top face at y[top] and the bottom face at y[bottom]

Look at the player's y.

If y > y[top], draw the bottom face first

If y < y[bottom], draw the top face first.

Otherwise, it doesn't matter.

 

Similarly with the x and z faces.

 

Once you have figured out which face is furthest for each axis, draw them in this order

x furthest, y furthest, z furthest

then

x closest, y closest, z closest

 

As easy as that :)

 

You're right that the z buffer will not help you, and GL_ALPHA_TEST is no use to you either.  That's only for textures with pixels that are either fully opaque or fully transparent.

 

-TGG

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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