Jump to content

OpenGL and transparent square


Blackout

Recommended Posts

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

Link to comment
Share on other sites

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 :/

Link to comment
Share on other sites

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

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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