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



×
×
  • Create New...

Important Information

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