Jump to content

Recommended Posts

Posted

Hello!

When I draw a texture using RenderGameOverlayEvent, then with her drawn back white background, although it is transparent.

My code is:

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void cancelVanillaGUI(RenderGameOverlayEvent.Pre event){
	/* Cancel render vanilla hearts, food, air and armor */
	if(event.type == ElementType.HEALTH || event.type == ElementType.FOOD || event.type == ElementType.AIR || event.type == ElementType.ARMOR || event.type == ElementType.EXPERIENCE){
		event.setCanceled(true);

		Minecraft mc = Minecraft.getMinecraft();

		if(mc.theWorld == null || mc.thePlayer == null){
			return;
		}

		EntityClientPlayerMP player = mc.thePlayer;

		RPGPlayerInfo info = RPGPlayerInfo.forPlayer(player);

		if(player.capabilities.isCreativeMode){
			return;
		}

		ScaledResolution resolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);

		int height = resolution.getScaledHeight();
		int width = resolution.getScaledWidth();

		GL11.glPushMatrix();
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.9F);
		//GL11.glDisable(GL11.GL_LIGHTING);

		mc.getTextureManager().bindTexture(new ResourceLocation(InMinecraftRpg.MOD_ID.toLowerCase(), "textures/gui/icons.png"));

		/* Draw border */
		mc.ingameGUI.drawTexturedModalRect(2, 2, 0, 0, 162, 60);

		int healthBarWidth = MathHelper.ceiling_float_int(((player.getHealth() / player.getMaxHealth()) * 108));

		/* Draw health bar */
		mc.ingameGUI.drawTexturedModalRect(52, 16, 0, 60, healthBarWidth, 10);

		int armorBarWidth = MathHelper.ceiling_float_int(((getArmorValue(player) / 100.0F) * 108));

		/* Draw armor bar */
		mc.ingameGUI.drawTexturedModalRect(52, 29, 0, 70, armorBarWidth, 10);

		if(mc.objectMouseOver != null){
			if(mc.objectMouseOver.typeOfHit == MovingObjectType.ENTITY && mc.objectMouseOver.entityHit instanceof EntityLivingBase){

				EntityLivingBase viewEntity = (EntityLivingBase)mc.objectMouseOver.entityHit;

				int viewEntityHealthBarWidth = MathHelper.ceiling_float_int((viewEntity.getHealth() / viewEntity.getMaxHealth()) * 86);

				/* Draw view entity health bar */
				mc.ingameGUI.drawTexturedModalRect(66, 53, 0, 80, viewEntityHealthBarWidth, 6);

				/* Draw view entity name */
				mc.ingameGUI.drawCenteredString(mc.fontRenderer, viewEntity.getCommandSenderName(), 112, 64, Color.CYAN.getRGB());

				if(viewEntity instanceof EntityPlayer){

					int healthArmor = MathHelper.floor_float(viewEntity.getMaxHealth() + getArmorValue((EntityPlayer)viewEntity));

					/* Draw view player health + armor */
					mc.ingameGUI.drawCenteredString(mc.fontRenderer, String.valueOf(healthArmor), 112, 55, Color.CYAN.getRGB());
				}
			}
		}

		mc.getTextureManager().bindTexture(Gui.icons);

		int max = info.experienceToNextLvl - RPGPlayerInfo.getXpToNextLvl(info.experienceLevel - 1);

		int current = info.experienceToNextLvl - info.experience;

		int concurrent = max - current;

		int experienceBarWidth = MathHelper.ceiling_float_int(((float)concurrent / (float)max) * 182);

		//GL11.glTranslated(-182, 0, 0);

		/* Draw experience border */
		mc.ingameGUI.drawTexturedModalRect(width / 2 - 91, height - 29, 0, 64, 182, 5);

		/* Draw experience bar */
		mc.ingameGUI.drawTexturedModalRect(width / 2 - 91, height - 29, 0, 69, experienceBarWidth, 5);

		/* Draw experience lvl value */
		drawStringWithShadow(String.valueOf(info.experienceLevel), 82, 40, 8453920);

		/* Draw health value */
		drawStringWithShadow(String.valueOf((int)player.getHealth()) + "/" + (int)player.getMaxHealth(), 218, 18, Color.WHITE.getRGB());

		/* Draw armor value */
		drawStringWithShadow(String.valueOf((int)getArmorValue(player)) + "/100", 218, 31, Color.WHITE.getRGB());

		/* Draw experience value */
		drawStringWithShadow(String.valueOf(info.experience) + "/" + String.valueOf(info.experienceToNextLvl), width, height - 45, 8453920);

		//GL11.glEnable(GL11.GL_LIGHTING);
		GL11.glPopMatrix();
	}
}

 

Here drawn picture:

 

mc.getTextureManager().bindTexture(new ResourceLocation(InMinecraftRpg.MOD_ID.toLowerCase(), "textures/gui/icons.png"));
/* Draw border */
mc.ingameGUI.drawTexturedModalRect(2, 2, 0, 0, 162, 60);

 

Screenshot:

 

2cac9d721e991accc49ae2a6780cee7b.png

Posted

Em, i don't have it in my code(sniper that has zooming and crosshairs, used RenderGameOverlay), try without it, if you see errors(something is rendering wrongly) put it to the end. Also use glpushmatrix before the blendfunc, and popmatrix at the end.

Posted

Hi

 

The flag you are looking for is probably ALPHA_TEST, assuming you've set the background alpha properly.

 

      GL11.glPushMatrix();
      GL11.glPushAttrib(GL11.GL_ENABLE_BIT);

        GL11.glEnable(GL11.GL_ALPHA_TEST);
        GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);

.. do your rendering here

      GL11.glPopAttrib();
      GL11.glPopMatrix();

 

pushMatrix & popMatrix stops your glTranslate and glRotate from affecting anything drawn after you're done

pushAttrib and popAttrib prevents your changed rendering settings (eg ALPHA_TEST) from affecting vanilla renders after your render

 

-TGG

  • 2 weeks later...
Posted

Hi

 

The flag you are looking for is probably ALPHA_TEST, assuming you've set the background alpha properly.

 

      GL11.glPushMatrix();
      GL11.glPushAttrib(GL11.GL_ENABLE_BIT);

        GL11.glEnable(GL11.GL_ALPHA_TEST);
        GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);

.. do your rendering here

      GL11.glPopAttrib();
      GL11.glPopMatrix();

 

pushMatrix & popMatrix stops your glTranslate and glRotate from affecting anything drawn after you're done

pushAttrib and popAttrib prevents your changed rendering settings (eg ALPHA_TEST) from affecting vanilla renders after your render

 

-TGG

 

Not Transparency is working :(

GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.3F); //0.3F - alpha not work :(

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.