Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

I think you have to enable alpha in opengl(GL11.glEnable(GL11.GL_BLEND)), also you have the width and height parameters in the event.resolution.

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.

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...
  • Author

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

GL11.glEnable(GL11.GL_BLEND);

GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

render

GL11.glDisable(GL11.GL_BLEND);

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.