I am trying to make my custom GUI inside OpenGL aplication. I would like to use TextRenderer class to render texts for me. But when I use it I notice a strange behavior. The aplication runs smoothly for about minute or two then starts to lag and is practicaly unusable. I figured out that this only happenes when I put TextRenderer in place. So it must be something how I use TextRenderer. I have looked at my code, at itss code, and didn't find anything obvious.
My architecture goes like this:
class BaseUIElement
{
protected TextRenderer textRenderer;
//something something
public BaseUIElement ()
{
//something something
this.textRenderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 16) );
}
public final void Render( GL2 gl)
{
//setting ortho projection, binding textures for menu and stuff
this.drawContent();
//restoring OGL states to before
}
protected void drawContent()
{
//box itself drawing magics
textRenderer.beginRendering(...);
this.textRenderer.setColor(...);
for (String line : textLines)
{
this.textRenderer.draw( ... );
}
this.textRenderer.endRendering();
}
public void destroy()
{
//free my stuff
this.textRenderer.dispose();
}
}
I also used properties of text renderer to determin text align box size and stuff but I dot thinl thats relevant. One thing you will most likely point out is, that I shouldn't have constructed UIElemetn in each call of OpenGL display loop. But If that was the problem, I would expect the App to run slow from the very begining. And I do call destroy() after I am done with each UI object so the TextRenderer should free the resources each time. I didn't took a look at memory usage and there is nothing strange about it. The heap size stays basicly the same whole time. Any cluses what I should have a look at or what may be the problem? I would do more, but I am not sure how to debug this behavior. I would be glad for any advice. :)