The basic premise is that I have 2 Android views ... The background view, which fills the screen ( ImageView
in this case) and LibGDX GLSurfaceView
which is in the foreground, is the application LibGDX
, I want to punch a hole in LibGDX GLSurfaceView
, so that I can see background ImageView
. those. the part LibGDX
behaves like an overlay. Unfortunately, I cannot get this to work at all. I deleted all the code to leave only the necessary items that hopefully demonstrate what I'm trying to do.
In the full application, this is an Android application where background View
is the video, and the foreground displayed LibGDX
is the set of video controls that should be superimposed on the video.
public class MiniClientGDXTestActivity extends AndroidApplication implements ApplicationListener {
@Bind(R.id.surface)
FrameLayout uiFrameHolder;
Stage stage;
Batch batch;
Camera camera;
Viewport viewport;
ShapeRenderer shapeRenderer;
private View miniClientView;
public MiniClientGDXTestActivity() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideSystemUI(this);
setContentView(R.layout.miniclientgltest_layout);
ButterKnife.bind(this);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.r = 8;
cfg.g = 8;
cfg.b = 8;
cfg.a = 8;
miniClientView = initializeForView(this, cfg);
if (graphics.getView() instanceof SurfaceView) {
SurfaceView glView = (SurfaceView) graphics.getView();
glView.setBackgroundColor(android.graphics.Color.TRANSPARENT);
glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
}
uiFrameHolder.addView(miniClientView);
}
@Override
public void create() {
camera = new OrthographicCamera();
viewport = new StretchViewport(1920, 1080, camera);
stage = new Stage(viewport);
batch = stage.getBatch();
shapeRenderer = new ShapeRenderer();
Gdx.graphics.setContinuousRendering(false);
Gdx.graphics.requestRendering();
}
@Override
public void resize(int width, int height) {
stage.getViewport().setWorldSize(1920, 1080);
stage.getViewport().update(width, height, true);
Gdx.graphics.requestRendering();
}
@Override
public void render() {
Gdx.gl20.glClearColor(0, 0, 0, 0);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
stage.draw();
drawRect(10, 10, 1000, 1000);
fillRect(50, 50, 800, 800);
clearRect(200, 200, 1600, 600);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
public void drawRect(final int x, final int y, final int width, final int height) {
shapeRenderer.setProjectionMatrix(camera.combined);
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.rect(x, y, width, height, Color.RED, Color.RED, Color.RED, Color.RED);
shapeRenderer.end();
}
public void fillRect(final int x, final int y, final int width, final int height) {
shapeRenderer.setProjectionMatrix(camera.combined);
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.rect(x, y, width, height, Color.BLUE, Color.BLUE, Color.BLUE, Color.BLUE);
shapeRenderer.end();
}
public void clearRect(final int x, final int y, final int width, final int height) {
shapeRenderer.setProjectionMatrix(camera.combined);
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setColor(Color.CLEAR);
shapeRenderer.rect(x, y, width, height);
shapeRenderer.end();
}
}
And here is the XML layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:keepScreenOn="true">
<FrameLayout
android:visibility="visible"
android:id="@+id/surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="match_parent" android:scaleType="fitXY" android:src="@drawable/background"/>
</FrameLayout>
</FrameLayout>