1

Android application uses android.opengl.GLSurfaceView to rendering OpenGL ES:

public class GameActivity extends AppCompatActivity {
    private SurfaceView surfaceView;
    @Override
    protected void onCreate(Bundle state) {
        ...
        surfaceView = new SurfaceView(this);
        setContentView(surfaceView);
    }
}

public class SurfaceView extends GLSurfaceView {
    private final SceneRenderer renderer;
    public SurfaceView(Context context) {
        ...
        renderer = new SceneRenderer(context);
        setRenderer(renderer);
    }
}

How to display Android UI-elements (like text labels) over of OpenGL ES rendering?

alexrnov
  • 2,346
  • 3
  • 18
  • 34

1 Answers1

0

Need to use:

public class GameActivity extends AppCompatActivity {
    private SurfaceView surfaceView;
    @Override
    protected void onCreate(Bundle state) { 
        setContentView(R.layout.activity_gl);
        surfaceView = findViewById(R.id.oglView);
        surfaceView.init(this.getApplicationContext());
    } 
}

public class SurfaceView extends GLSurfaceView {
    private SceneRenderer renderer;
    public SurfaceView(Context context) {
        super(context);
    }

    public SurfaceView(Context context, AttributeSet attributes) {
        super(context, attributes);
    }

    public void init(Context context) {
        renderer = new SceneRenderer(context);
        setRenderer(renderer);
        ...
    }
}

And create layout activity_gl.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    tools:context=".activities.GameActivity">
    <com.app.SurfaceView
        android:id="@+id/oglView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <TextView ... />
</androidx.constraintlayout.widget.ConstraintLayout>

To update elements from the render thread, can use Handler/Looper.

alexrnov
  • 2,346
  • 3
  • 18
  • 34