I wanted to save battery life time. My app only needs to be drawn sometimes.
So I added this code to my Renderer in the onDraw method:
boolean dirty = true;
public void onDrawFrame(GL10 arg0) {
if (!dirty) return;
dirty = false;
..... draw images ....
}
So my app only gets drawn when I want it. But what happens is that if I dont draw my app on every frame it flickers really fast. It looks like it will be drawn every 2. frame or so and in all the other frames only a black screen will be drawn.
I know that i could set the render mode to RENDERMODE_WHEN_DIRTY
. But I dont want to create another thread to check if its dirty or not.
My question is why does it flicker? i dont call any methods or GLES20 calls before i do my check: if (!dirty) return;
and i am sure that the boolean dirty
doesnt change and is always false except for the first frame.
EDIT:
I changed my code to this:
int dirty = 0;
public void onDrawFrame(GL10 arg0) {
if (dirty > 1) return;
dirty++;
..... draw images ....
}
This stops the flickering! Looks like you have to draw atleast 2 times so you dont have this wierd screen flickering. Anyways I will now try to use the more clean way and create a thread that calls requestRender()
when i want to draw something and set my render mode to RENDERMODE_WHEN_DIRTY
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…