2
\$\begingroup\$

In my old game based on canvas and bitmaps I used surfaceHolder and Thread to call onDraw:

public class GameThread extends Thread {
private SurfaceHolder _surfaceHolder;
private ScreenObjectsView _panel;
private boolean _run = false;

public static int mOnDrawPeriodGap = 20;


public GameThread(SurfaceHolder surfaceHolder, ScreenObjectsView panel) {
    _surfaceHolder = surfaceHolder;
    _panel = panel;
}

public void setRunning(boolean run) {
    _run = run;
}

public SurfaceHolder getSurfaceHolder() {
    return _surfaceHolder;
}

@Override
public void run() {
    Canvas c;
    while (_run) {

        if(!_surfaceHolder.getSurface().isValid()){
            continue;
        }

        c = null;
        //Log.e("test","thread running");
        try {
            c = _surfaceHolder.lockCanvas(null);
            synchronized (_surfaceHolder) {
                _panel.updatePhysics();
                _panel.onDraw(c);

                /** onDraw() method  run too fast, lets slower it*/
                try {
                    Thread.sleep(mOnDrawPeriodGap);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        } finally {
            // do this in a finally so that if an exception is thrown
            // during the above, we don't leave the Surface in an
            // inconsistent state
            if (c != null) {
                _surfaceHolder.unlockCanvasAndPost(c);
            }
        }
    }
}

}

Today I try to adapt my game to openGL 2D. I'm new in openGL world.

Do I need to do the same for new framework?

As I know It (openGL) seems already starts a second thread for rendering, calling into the Renderer methods.

Thank you,

\$\endgroup\$

0

Browse other questions tagged .