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

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

Drawing is step-by-step procedure, it's literally like placing layer over layer - 1st one executed will be on bottom, second on top of it.

 

Where and how are you calling this renderer?

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

  • Author

I figured that was the case. I just don't know what to change to fix that.

 

The function is being called with the RenderGameOverlayEvent which is being called in the ClientProxy in the preInit.

Lead DivineRPG Developer

  • 4 weeks later...
  • Author

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

  • Author

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

  • Author

Oh, if I replace gui.drawArmor() with a drawString method like you did, it draws behind the chat. So it's not the event that's the problem it's drawArmor().

(drawArmor() can be seen in the OP)

Lead DivineRPG Developer

  • Author

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

  • Author

I need the glColor because if I don't have it, the new GUI changes colors depending on other renders I added to the screen. I believe that I need to other gl stuff for the glColor to work.

Lead DivineRPG Developer

  • Author

That is very true xD. In my defence though, I wrote the function without the gl stuff but the color problem presented itself, and I asked someome helping me if they knew how to fix it. They did.

Lead DivineRPG Developer

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

  • Author

@diesieben07 Removed all the gl stuff, didn't work.

@Nephroid Will take a look.

(For the record, I did do the static final, but I didn't copy it to this forum)

 

Edit: Thanks for the examples. I understand a lot better now. I don't think it helps me with my problem though.

Lead DivineRPG Developer

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.