Jump to content

[1.8] Weird Lighting Bug with RenderGameOverlayEvent


TheNuclearDuck

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • hola thanks for answering  i set some system outs to test and see whats going on      @Override     protected void saveAdditional( CompoundTag nbt ){                  nbt.put("itemhandler", itemhandler.serializeNBT() );         nbt.putInt("progress", this.progress );         System.out.println("saveAdditional(nbt)");                 System.out.println(NbtUtils.prettyPrint(nbt)); //<-- this is whats getting saved         super.saveAdditional( nbt );     }     @Override     public void load( CompoundTag nbt ){         itemhandler.deserializeNBT( nbt.getCompound("itemhandler") );         this.progress = nbt.getInt("progress" );         System.out.println(NbtUtils.prettyPrint(nbt)); //<-- this is whats minecraft is giving back to the entity          System.out.println("load(nbt)");         super.load( nbt );     }   This dead adventurer body  has two parts a block and a block Item  both has their own item-handlers and their own menus all of that seems fine  Testing remarks : *when i change some element inside the gui  it triggers the saveAdditional(nbt) system out and shows a pretty print of the data being saved  *when the world map loads it triggers the load(nbt) system out and shows a pretty print of the data minecraft is giving to this Block Entity For the testing i gonna set mi BlockEntityBodyBlock, save something in it, close minecraft, fireup the game again and check if the items remain      ################ first try set the block entity (dead adventurer body like shaped) and left only a weath seed  in the slot 10 the console says its all right    close minecraft, launch it again i see the system out whit the data returned to the entity and its look good theres is only a weed seed  ################ Second try, now i gonna change the seed for two arrows  the console says its all right the two arrows are being saved    ######### Now close and run again bam Error  minecraft returns the original data whit only a wheat seed the two arrows has been loss   ########## try again now i gonna put 3 wheat seeds Console system out says it gets it and is saving the data   ############## but after close fire again  wheat seed,  data losed once more time  and it just throw the original   ####################################################################################### sorry for the long post and the crappy video  this is the reason why i say its saving the Block Entity data only when it feels like  coze its saves data when it feels like  ¿ its something wrong whit mi BlockEntity.saveAdditional()  if  i keep trying eventually it updates and the data chages      i alredy try to  level.removeBlockEntity(pos); level.setBlockEntity(pos, bebb);     BlockEntityBodyBlock.class   BlockEntityInit.class     body_blockitem.class                  
    • Yesterday I buy a minecraft server to play with my friends you know... One of my friends send me the list of mods to add and then i start to dowload them, when i add them to the server it start crashing but i don't know about this things because it's my first time buying a minecraft server This is the error: https://paste.ee/p/sJf7B
    • Discovering that a trusted colleague had accessed my Bitcoin account and transferred $30,000 worth of bitcoins was a devastating blow. It shattered the trust I had placed in them and left me feeling vulnerable and betrayed. However, in the face of adversity, I turned to MUYERN TRUST HACKER for assistance in reclaiming control over my finances and holding the perpetrators accountable for their actions. One of the standout features of MUYERN TRUST HACKER was its ability to provide real-time alerts and notifications, keeping me informed every step of the way. With the support of MUYERN TRUST HACKER, I was able to gather irrefutable evidence of the perpetrator's actions and hold them accountable for their crimes. Armed with the information provided by the platform, I pursued legal recourse and ensured that justice was served. The perpetrator faced severe consequences for their actions, including legal penalties and financial restitution. Beyond its role in facilitating the recovery process, MUYERN TRUST HACKER provided me with a sense of empowerment and resilience in the face of adversity. While the experience was undoubtedly challenging, it ultimately served as a testament to the importance of vigilance and the power of technology in safeguarding our digital assets. Thanks to MUYERN TRUST HACKER, I emerged stronger and more resilient, ready to face whatever challenges the future may hold. Mail; muyerntrusted[At] mail-me .c o m
    • Discovering that a trusted colleague had accessed my Bitcoin account and transferred $30,000 worth of bitcoins was a devastating blow. It shattered the trust I had placed in them and left me feeling vulnerable and betrayed. However, in the face of adversity, I turned to MUYERN TRUST HACKER web [ ht tps:// muyerntrusthack.solutions/ ] for assistance in reclaiming control over my finances and holding the perpetrators accountable for their actions. One of the standout features of MUYERN TRUST HACKER was its ability to provide real-time alerts and notifications, keeping me informed every step of the way. With the support of MUYERN TRUST HACKER, I was able to gather irrefutable evidence of the perpetrator's actions and hold them accountable for their crimes. Armed with the information provided by the platform, I pursued legal recourse and ensured that justice was served. The perpetrator faced severe consequences for their actions, including legal penalties and financial restitution. Beyond its role in facilitating the recovery process, MUYERN TRUST HACKER provided me with a sense of empowerment and resilience in the face of adversity. While the experience was undoubtedly challenging, it ultimately served as a testament to the importance of vigilance and the power of technology in safeguarding our digital assets. Thanks to MUYERN TRUST HACKER, I emerged stronger and more resilient, ready to face whatever challenges the future may hold. Mail; muyerntrusted[At] mail-me .c o m  
    • Do you have still this problem? (I have it too so I want to know if you did something with it)  
  • Topics

×
×
  • Create New...

Important Information

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