Jump to content

[1.7.10] Make GUI draw behind chat


RadioactiveStud

Recommended Posts

I have a working GUI that draws to the screen just fine, but it renders in front of the chat instead of behind. What should I do?

Image:

 

5bc5d652387e556e6c3bb9f278a7ad32.png

 

Code:

GL11.glDisable(GL11.GL_BLEND);
GL11.glColor4f(1, 1, 1, 1);
ResourceLocation r = new ResourceLocation(Reference.PREFIX + "textures/gui/armorBar.png");
res = new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
int x = (res.getScaledWidth() / 2) - 11;
int y = res.getScaledHeight() - 49;
GL11.glPushMatrix();
Minecraft.getMinecraft().getTextureManager().bindTexture(r);
Util.drawTexturedModalRect(x, y, 0, 0, 9, 9);
GL11.glPopMatrix();
GL11.glDisable(GL11.GL_BLEND);

I can show other code if you wish.

Lead DivineRPG Developer

Link to comment
Share on other sites

  • 4 weeks later...

Okay so, kinda forgot about this, but what ever I tried, it didn't fix the problem.

 

 

public void renderOverlay(RenderGameOverlayEvent event){
	if(event.isCanceled() || event.type != ElementType.EXPERIENCE) return;
	if((EventArmorTick.size != 0) && !Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode) {
		//gui.drawArmor();
	}
   }

 

 

Tried ElementType.Armor and some others. Nothing worked.

Tried RenderGameOverlayEvent.Pre with and without event.isCanceled()

Am I doing something wrong?

Using recommended (1230) forge by the way.

Lead DivineRPG Developer

Link to comment
Share on other sites

Well it's the exact same as shown but with the changed event. Do I need to change something?

public void renderOverlay(RenderGameOverlayEvent.Post event){
if(event.isCanceled() || event.type != ElementType.EXPERIENCE) return;
if((EventArmorTick.size != 0) && !Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode) {
	gui.drawArmor();
}
}

Lead DivineRPG Developer

Link to comment
Share on other sites

Oh that's slightly outdated code.

     GL11.glPushMatrix();
	GL11.glEnable(GL11.GL_BLEND);
	GL11.glColor4f(1, 1, 1, 1);
	ResourceLocation r = new ResourceLocation(Reference.PREFIX + "textures/gui/armorBar.png");
	res = new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
	int x = (res.getScaledWidth() / 2) - 11;
	int y = res.getScaledHeight() - 49;
	switch(EventArmorTick.size) {
	case 1:
		Minecraft.getMinecraft().getTextureManager().bindTexture(r);
		Util.drawTexturedModalRect(x, y, 0, 0, 9, 9);
		break;
	}
	GL11.glDisable(GL11.GL_BLEND);
	GL11.glPopMatrix();

Here's drawTexturedModalRect. Pretty sure this is the same as the normal drawTexturedModalRect, I don't remember why I added it.

public static void drawTexturedModalRect(int par1, int par2, int par3, int par4, int par5, int par6) {
        float f = 0.00390625F;
        float f1 = 0.00390625F;
        Tessellator tessellator = Tessellator.instance;
        tessellator.startDrawingQuads();
        tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + par6), 1D, (double)((float)(par3 + 0) * f), (double)((float)(par4 + par6) * f1));
        tessellator.addVertexWithUV((double)(par1 + par5), (double)(par2 + par6), 1D, (double)((float)(par3 + par5) * f), (double)((float)(par4 + par6) * f1));
        tessellator.addVertexWithUV((double)(par1 + par5), (double)(par2 + 0), 1D, (double)((float)(par3 + par5) * f), (double)((float)(par4 + 0) * f1));
        tessellator.addVertexWithUV((double)(par1 + 0), (double)(par2 + 0), 1D, (double)((float)(par3 + 0) * f), (double)((float)(par4 + 0) * f1));
        tessellator.draw();
    }

Lead DivineRPG Developer

Link to comment
Share on other sites

If you know what

glPushMatrix()

and

glPopMatrix()

do,

glPushAttrib(ALL_ATTRIB_BITS

) and

glPopAttrib()

are similar, but they work with most blending options, lighting changes, etc.

 

Edit:

 

After taking another look at your code, I'm guessing you don't exactly know what

glPushMatrix()

and

glPopMatrix()

do, since you don't have any transformations in between those two lines.

glPopMatrix()

resets any OpenGL transforms (

glScale

,

glTranslate

,

glRotate

) that you do after the corresponding

glPushMatrix()

call. Since you don't have any transforms, you don't actually need to push/pop the matrix.

 

Also, it's better practice to make your

ResourceLocation

s static and final (and away from any other OpenGL code), since it's unlikely that they will be changing during your rendering. You don't want to make a new

ResourceLocation

every frame when you only need to make one at the beginning.

 

Here are two documented examples of modifying the overlay that might help you (the GUI overlay doesn't really change between 1.8 and 1.7):

https://github.com/Nephroid1/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/overlay_simple

https://github.com/Nephroid1/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/overlay_advanced

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.