Search code examples
androidopengl-esframe-rate

How do you display fps with opengl es (android)


I am new to java and opengl and still learning so forgive me for my ignorance. I have made an looming object apk file. Now i want to view the fps as the application is playing on my device. I have been following this tutorial http://www.youtube.com/watch?v=1MYgP8Oj5RY&list=UUKwypsRGgHj1mrlQXhLXsvg&index=67 and attempted to modify it for android but i can't get it to work.

Could anyone show me an example of how to add a simple fps indicator on the corner or on the title page and how to control the fps.

Thanks


Solution

  • if you use this class and call logFrame() it will tell you the fps in a log on your logcat:

    import android.util.Log;
    
    public class FPSCounter {
        long startTime = System.nanoTime();
        int frames = 0;
    
        public void logFrame() {
            frames++;
            if(System.nanoTime() - startTime >= 1000000000) {
                Log.d("FPSCounter", "fps: " + frames);
                frames = 0;
                startTime = System.nanoTime();
            }
        }
    }
    

    from what ive read you optimise your code to get a better framerate by minimising the calls to the gl states

    here is a link for drawText()