openGL ES - change the render mode from RENDERMODE_WHEN_DIRTY to RENDERMODE_CONTINUOUSLY on touch
Posted
by
Sid
on Game Development
See other posts from Game Development
or by Sid
Published on 2012-09-22T06:30:52Z
Indexed on
2012/09/22
9:50 UTC
Read the original article
Hit count: 1007
i want to change the rendermode from RENDERMODE_WHEN_DIRTY to RENDERMODE_CONTINUOUSLY when i touch the screen.
WHAT i Need : Initially the object should be stationary. after touching the screen, it should move automatically. The motion of my object is a projectile motion ans it is working fine.
what i get : Force close and a NULL pointer exception.
My code :
public class BallThrowGLSurfaceView extends GLSurfaceView{
MyRender _renderObj;
Context context;
GLSurfaceView glView;
public BallThrowGLSurfaceView(Context context) {
super(context);
// TODO Auto-generated constructor stub
_renderObj = new MyRender(context);
this.setRenderer(_renderObj);
this.setRenderMode(RENDERMODE_WHEN_DIRTY);
this.requestFocus();
this.setFocusableInTouchMode(true);
glView = new GLSurfaceView(context.getApplicationContext());
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event != null)
{
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
if (_renderObj != null)
{ Log.i("renderObj", _renderObj + "lll");
// Ensure we call switchMode() on the OpenGL thread.
// queueEvent() is a method of GLSurfaceView that will do this for us.
queueEvent(new Runnable()
{
public void run()
{
glView.setRenderMode(RENDERMODE_CONTINUOUSLY);
}
});
return true;
}
}
}
return super.onTouchEvent(event);
}
}
PS : i know that i am making some silly mistakes in this, but cannot figure out what it really is.
© Game Development or respective owner