[GLSurfaceView]Should I update game logics in onDrawFrame()?

Put your problem here if it does not fit any of the other categories.

[GLSurfaceView]Should I update game logics in onDrawFrame()?

Postby lgmcben » Fri Oct 09, 2009 6:45 am

Hi. Please excuse me for being new. I'll try my best to explain.

I read the Android Developer blog about GLSurfaceView here:

http://android-developers.blogspot.com/ ... penGL%20ES

It said one of the advantage we get from using GLSurfaceView is "Creating and managing a separate rendering thread to enable smooth animation."


Question:

Currently I'm doing this in my game.
public void onDrawFrame(GL10 gl) {

//update game mechanics/physics
updateGame(gl);


//draw game
gl.glDisable(GL10.GL_DITHER);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
.........
}

Is this what it's supposed to be? (I handled 'elapsed time' in my updateGame() )


Or should I create another thread to do the update? Like this:

@Override
public void run() {
while (mRun) {

//update game mechanics/physics
updateGame(gl);

}
}

public void onDrawFrame(GL10 gl) {
//draw game
gl.glDisable(GL10.GL_DITHER);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
.........
}

Which one will produce best result for a game?

Thank you in advance.
lgmcben
Junior Developer
Junior Developer
 
Posts: 24
Joined: Mon Nov 17, 2008 5:06 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 14 guests