Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8] Weird Lighting Bug with RenderGameOverlayEvent


Recommended Posts

Hello,

I hook into RenderGameOverlayEvent, and check for ElementType.ALL to ensure everything only renders once. The event is lowest priority, so it should render last. Within the event I render several things to the GUI, including text, items, textured quads, and some transparent textured quads. The transparency seems to break the rendering engine somehow, because whenever I render anything with a transparent colour, the following happens to the hotbar and every other transparent part of the HUD:

5joAWOi.png

Everything gets weirdly bright, and I can't work out what's causing it. It seems to correspond with the day/night cycle, since at night this stops happening. Do I have to disable the day/night lighting system somewhere?

 

I've tried various combinations of the following set of lines:

 

GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

 

Along with trying to bind textures, enabling and disabling GL_LIGHTING or GL_TEXTURE_2D. All the usual fixes don't seem to work here.

 

Does anyone know what's going on? What's interesting is that depending on the ElementType, sometimes this doesn't happen. However, every type I've tried so far has screwed up another part of the vanilla HUD somehow.

 

None of my rendering methods contain any code outside of vanilla functions (drawTexturedModalRect, drawString, bindTexture...) and the OpenGL functions above - I have also used glPushMatrix and glPopMatrix when necessary.

 

Thank you for reading.

Link to post
Share on other sites

Hi

 

Looks like your rendering methods are messing with one of the rendering settings.  There are quite a few of them.

 

You could try using   

GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);

.. your render stuff here...

GL11.glPopAttrib();

 

or

GL11.glPushAttrib(GL11.GL_ENABLE_BIT);

.. your render stuff here...

GL11.glPopAttrib();

 

 

glPushMatrix only stores the transformation matrix, glPushAttrib can be used to save rendering settings too

 

Failing that, I'd suggest you narrow it down as much as possible and then look to see exactly which vanilla code is changing rendering settings.  I don't think it's likely to be texture binding.  The day/night suggests you have turned world lighting on somehow.  The glPushAttrib should fix that.

 

-TGG

Link to post
Share on other sites

No luck. I was already using glPushAttrib and glPushMatrix. I tried removing them, and interestingly, removing glPushAttrib and glPopAttrib (GL_ALL_ATTRIB_BITS) actually fixed the problem... Partially. When I did that, the problem appeared whenever I was looking at the skybox and not the terrain, then went away again afterwards. However, since I do change some GL states during my rendering, I can't keep it like this (and it only makes more errors, anyway...).

 

So, I started removing parts to see if the error would fix. In the end, I managed to narrow the entire problem down to Minecraft's vanilla function, Gui.drawRect.

I managed to narrow down my entire rendering code to the following, and the same problem persisted:

@SubscribeEvent(priority = EventPriority.LOWEST) // We want this to render last out of everything
public void onRenderTick(RenderGameOverlayEvent.Post e) {
if(mc == null) mc = Minecraft.getMinecraft();
if(fr == null) fr = mc.fontRendererObj;
if(ri == null) ri = mc.getRenderItem();

if(e.type == RenderGameOverlayEvent.ElementType.ALL) {
	if(mc != null && mc.ingameGUI != null && fr != null && mc.thePlayer != null) {
		glPushAttrib(GL_ALL_ATTRIB_BITS); {
			glPushMatrix(); {
				GL11.glEnable(GL11.GL_BLEND);
				GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
				GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

				mc.ingameGUI.drawRect(5, 5, 105, 105, 0xaaffffff);
			}
			glPopMatrix();
		}
		glPopAttrib();
	}
}
}

Removing that one call to drawRect solves the problem, but then of course I'm not rendering anything. Drawing strings, interestingly, does not cause the problem.

 

Looking into the code from drawRect, the only rendering code is the following:

float f3 = (float)(color >> 24 & 255) / 255.0F;
float f = (float)(color >> 16 & 255) / 255.0F;
float f1 = (float)(color >> 8 & 255) / 255.0F;
float f2 = (float)(color & 255) / 255.0F;
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.color(f, f1, f2, f3);
worldrenderer.startDrawingQuads();
worldrenderer.addVertex((double)left, (double)bottom, 0.0D);
worldrenderer.addVertex((double)right, (double)bottom, 0.0D);
worldrenderer.addVertex((double)right, (double)top, 0.0D);
worldrenderer.addVertex((double)left, (double)top, 0.0D);
tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();

Nothing here appears out of the ordinary, right? It enables, then disables blending, same with texture2D but reversed. Fiddling with blending or texture2D does absolutely nothing in my rendering code, regardless of whether I use MC's "GLStateManager" or just pure GL11 functions. Only thing I can think of now is the "tryBlendFuncSeparate" function, which I doubt would cause an issue... I'm completely stuck for ideas.

 

EDIT: drawTexturedModalRect also doesn't cause the problem (the last bound texture before my method was the font texture, if it's useful).

Link to post
Share on other sites

Well that's frustrating.  I'm out of ideas unfortunately.  The GLStateManager pushAttrib and popAttrib functions are buggy (they don't dirty the cache properly) but if you're not using that, then I don't know.

 

I've previously used this troubleshooting class to help track a similar problem

https://github.com/TheGreyGhost/MinecraftByExample/blob/master/src/main/java/minecraftbyexample/usefultools/OpenGLdebugging.java

i.e. call dumpAllIsEnabled() before & after, then look for the difference

 

In your case I doubt it will help though.

 

You could try copying drawRect into your own class, and slowly whittling down further until you get to the statement which causes the issue.  Apart from that I'm stuck, sorry!

 

-TGG

 

Link to post
Share on other sites

SOLUTION!

 

"You could try copying drawRect into your own class, and slowly whittling down further until you get to the statement which causes the issue.  Apart from that I'm stuck, sorry!"

Before I saw this post, this is what I started doing. I copied over drawRect into my own RenderUtil class and, as you said, whittled it down. Somehow, that came up with a solution.

 

Now, what I find most baffling is what was causing the problem. It was with this line:

GlStateManager.enableBlend();

Even though all I could find in this method was a lot of abstraction from GL11.glEnable(GL11.GL_BLEND), removing that line and replacing it with glEnable directly somehow fixed the problem. (I also removed the disabling blending part, because I imagine other parts of the GUI need blending enabled, e.g. chat).

 

Weird how MC's own rendering manager can cause such a glitch, when it has such a simple task to do. I couldn't even find another line of active code that would have changed anything, just lots and lots of wrapper. Anyway, it's a solution, I don't know why it's a solution, but it is. Thank you for your help, TheGreyGhost.

 

EDIT: Not really a solution... Sigh.

I was so happy having fixed this thing, I thought everything was great, then I typed something into the chat.

The back of the chat box (which is translucent) now has the same issue. I have nothing but my own version of drawRect in my render method now, with all the methods from GlStateManager replaced with raw GL (I don't trust that thing anymore...). I've tried just leaving GL_BLEND replaced, to no avail. When the time is evening, I look towards the sunset and the chat box becomes orange tinted, and I look away and it goes blue again. This pretty much confirms the skybox is definitely interfering with rendering somehow. But I'm not doing a single thing to let that happen.

 

Oh, and it's still affecting the hotbar, after I've typed a message into chat.

Link to post
Share on other sites

Writing a new post here, because I think I actually do have a solution.

 

I updated Minecraft Forge... Turns out I must've been using one of the early development versions rather than any of the newer ones which work properly.

Why I hadn't tried that earlier, I can't fathom.

Link to post
Share on other sites

I'm back.

After a release of the mod, and me being sure everything was working perfectly again, I found out I was wrong. Here we are again, same issue, absolutely no reason I can think of why. Seems like putting any code at all into a RenderGameOverlayEvent causes the problem. Ugh...

Link to post
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.

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.