JS.
JS.

Reputation: 171

Android (JNI/NDK) OpenGL - FPS Display help

I have an android app that I need to display the current FPS for.

1 - App is rendered in OpenGL.

public void onDrawFrame(GL10 gl) {
    synchronized(lock) {
        NativeCalls.getFrame(); // Setup in JNI/NDK
        NativeCalls.drawFrame(); // using openGL
        }
    }
}

2 - You can see that the rendering call is done from Java to call functions from JNI.

3 - I need to show the current FPS over this OpenGL surface.

I think that sums up what I am trying to do, so let me explain a bit more. This is a live wallpaper, so speed is of the essence and I need a fast way to show the fps to users.

I know how to calculate the FPS, just not display it.

I am looking for ways of doing this simply, but the problem is that the OpenGL rendering and setup is done through JNI.

Is it possible to render this from the Java side and "overlay" the text over the OpenGL surface created from JNI?

I've looked into rendering this via the JNI side, but displaying fonts in OpenGL is a pain. (My code is C, NOT C++ - this cannot be changed due to other things that would need a major recode to become CPP compliant from the NDK side).

Any suggestions, examples, etc. would be great. I know this can be done using freetype2 via C, but the simple libs out there seem to be all for CPP (Tried some, conversion is not an option because of C->C++ (Structures, etc.)).

It's not much text to display, for example: "FPS: 20". Nothing more.

Upvotes: 1

Views: 2120

Answers (1)

svdree
svdree

Reputation: 13348

I'm doing the same thing; in onDrawFrame() I call a native function to do the rendering, then back in Java I use drawText() to render the fps to a texture, and render a quad with that texture in Java code. Works great.

Upvotes: 2

Related Questions