Jump to content

[1.9.4] Rendering Overlay Turns Things Black


TLHPoE

Recommended Posts

Whenever I render my overlay, the background when opening the inventory or going to the menu is pitch black.

 

Render Code:

package tlhpoe.scalae.handler;

import org.lwjgl.opengl.*;

import net.minecraft.client.*;
import net.minecraft.client.gui.*;
import net.minecraft.client.renderer.*;
import net.minecraft.util.*;
import net.minecraftforge.client.event.*;
import net.minecraftforge.client.event.RenderGameOverlayEvent.*;
import net.minecraftforge.fml.common.eventhandler.*;
import net.minecraftforge.fml.common.gameevent.*;
import net.minecraftforge.fml.common.gameevent.TickEvent.*;
import net.minecraftforge.fml.relauncher.*;
import tlhpoe.scalae.*;
import tlhpoe.scalae.capabilities.*;

@SideOnly(Side.CLIENT)
public class ScalaeClientEvents extends Gui {
private static final ResourceLocation TEXTURE = new ResourceLocation(Scalae.MODID, "textures/gui/xp_bar.png");

private Minecraft mc;

public ScalaeClientEvents() {
	this.mc = Minecraft.getMinecraft();
}

@SubscribeEvent
public void drawXPBarPost(RenderGameOverlayEvent.Pre e) {
	if(e.getType() == ElementType.EXPERIENCE) {
		e.setCanceled(true);

		ScaledResolution sRes = new ScaledResolution(mc);

		int xPos = (sRes.getScaledWidth() - 182) / 2, yPos = sRes.getScaledHeight() - 32 + 3;

		mc.getTextureManager().bindTexture(TEXTURE);

		GlStateManager.pushAttrib();
		GlStateManager.color(1F, 1F, 1F);

		GlStateManager.enableAlpha();
		GlStateManager.enableBlend();

		drawTexturedModalRect(xPos, yPos, 0, 0, 182, 5);

		int width = (int) (182 * ((float) ClientProxy.PLAYER_XP / (float) ScalaeCapabilities.getXPRequired(ClientProxy.PLAYER_LEVEL)));

		drawTexturedModalRect(xPos, yPos, 0, 5, width, 5);

		String s = "" + ClientProxy.PLAYER_LEVEL;

		xPos = (sRes.getScaledWidth() - mc.fontRendererObj.getStringWidth(s)) / 2;
		yPos -= 6;

		mc.fontRendererObj.drawString(s, xPos + 1, yPos, 0);
		mc.fontRendererObj.drawString(s, xPos - 1, yPos, 0);
		mc.fontRendererObj.drawString(s, xPos, yPos + 1, 0);
		mc.fontRendererObj.drawString(s, xPos, yPos - 1, 0);
		mc.fontRendererObj.drawString(s, xPos, yPos, 0xFFF600);

		GlStateManager.popAttrib();
	}
}
}

 

1bf23d32e5504f83a47e1e404e5f7a80.png

 

I restarted the game and now the chat is black, but not the backgrounds.

21fda40ce3544e30b210f83e6a79bf3e.png

 

When the event isn't canceled, everything renders fine.

Kain

Link to comment
Share on other sites

You have to revert GL states to original (pre-event). Also - just because you are not directly changing states doesn't mean they are not different than they are supposed to (I am talking about cancelling event). Analyze place where particular Type of event is fired and make sure you have GL states correctly set. I wouldn't really trust push/pop Attribs.

 

Also: event.getScaledResolution() ;p (or something like that).

1.7.10 is no longer supported by forge, you are on your own.

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



×
×
  • Create New...

Important Information

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