Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

Calling openFramework methods from Android UI

$
0
0

I have being porting an iOS app made using OF to Android and had a strange problem. When calling OF methods from Android UI events such as click listeners, textures became black rectangles and some weird things happened. After two days searching through Internet I finally found the reason and solution for this.

On Android OF uses GLSurfaceView which creates a separate rendering thread and OpenGL context. You can make OpenGL calls from this thread without problem. But when you call make an OpenGL call from a UI event it is on the UI thread and it won't work. So you have to execute that call from the rendering thread using GLSurfaceView.queueEvent(Runnable).

For example you can get the current GLSurfaceView from OFAndroid and execute a native c++ method that make OpenGl calls like this.

GLSurfaceView glview = (GLSurfaceView) OFAndroid.getGLContentView();
glview.queueEvent(new Runnable() {
@Override
public void run() {
//native method
}
});

Hope this might help anyone having the same problem.


Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>