I'm trying to make something like a very simple painting app using Libgdx. I've been searching on the intertubes for a few days now trying to solve this issue, which is probably due to my openGL noobness.
When I paint an object on the screen, as long as the render() method is running, the stuff that I've painted blinks very quickly (I assume it's every time the render() method is called). If I disable continuous rendering, the blinking stops until I draw something else (again, render() isn't being called).
Assume that I'm loading a new Texture into a Sprite appropriately - it does draw, afer all - and all I'm doing in my render() method is this:
batch.begin();
myShape.setPosition(Gdx.input.getX(), Gdx.input.getY());
batch.setColor(Color.BLUE);
myShape.draw(batch);
batch.end();
I'm not calling glClear because I don't (think I) want to clear the screen every render. I have blindly experimented with various glEnable and glDisable's for culling, blending, dithernig, etc., but nothing has helped the problem.
What in the world am I doing wrong, or just not understanding here? Did I not set something up right?
That's because of double buffering.
With double buffering enabled, you are not drawing over previous frame, but over pre-previous. That means, even and odd frames are drawn to two different buffers. Changing those buffers creates flickering.
I see three solutions:
You can disable double buffering. I'm not sure if that's possible in libgdx.
You can clear the screen and draw everything every frame. This will get slower as you draw.
You can save the image to texture and draw it back to screen at the beginning of every frame. This is the preferred solution, although it might require some work. This technique is called "render to texture".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With