Posted January 3, 201510 yr Hi, all. I'm starting a mod and figured I'd start relatively simple with a custom GUI that simply displays how to get started with the mod. All seems to be working well, except that the GuiButton is drawing oddly. It works, so it isn't disabled. I suspect I'm setting something wrong / should be resetting something in OpenGL, but right now I admit I'm cargo cult programming the OpenGL stuff - learning it properly is still on the todo list. http://troglodytegames.com/images/ForgeGUIWeirdButtons.png shows how they look. Full GUI class is at : http://pastebin.com/VM5m4F5n I suspect it is in the drawscreen : /** * Draws the screen and all the components in it. */ public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(backgroundTexture); this.drawTexturedModalRect( (this.width - 256) / 2, 0, 0, 0, 256, 256); drawShapelessCrafting((this.width - 100) / 2, 180, LegendOfArtisansMod.legendarybookShapeless); for (int k = 0; k < this.buttonList.size(); ++k) { ((GuiButton)this.buttonList.get(k)).drawButton(this.mc, p_73863_1_, p_73863_2_); } for (int k = 0; k < this.labelList.size(); ++k) { ((GuiLabel)this.labelList.get(k)).func_146159_a(this.mc, p_73863_1_, p_73863_2_); } }
January 3, 201510 yr In general, a good way to debug OpenGL is to comment out everything that you think causes the problem, and see if the problem still exists. (If it does, then keep commenting until the problem goes away.) Then uncomment each line one by one until the problem reappears again. This will identify the specific piece of code that causes your problem, which will help you and others identify the problem too. If you use Eclipse, you can actually run your mod in debug mode, and the changes will take effect without restarting the mod. A good OpenGL trick is to use the push and pop functions to save and reset the "states" of OpenGL. If you call glPushAttrib(GL_ALL_ATTRIB_BITS) before your other OpenGL calls, it "saves" the current rendering "state" of OpenGL (i.e. color, lighting, etc). After your rendering calls, call glPopAttrib() to revert to the last pushed state, effectively resetting everything that you've done. In this case, after you figure out the segment of code causing the problem, surround it with a push and pop. That usually solves problems with weird rendering issues. GitHub|Recipe API Proposal
January 3, 201510 yr Author A good OpenGL trick is to use the push and pop functions to save and reset the "states" of OpenGL. If you call glPushAttrib(GL_ALL_ATTRIB_BITS) before your other OpenGL calls, it "saves" the current rendering "state" of OpenGL (i.e. color, lighting, etc). After your rendering calls, call glPopAttrib() to revert to the last pushed state, effectively resetting everything that you've done. The push and pop solved it beautifully. Thank you!
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.