Вы можете создать макет с помощью surfaceView, например, activity_gl. xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
tools:context=".activities.OpenGLActivity">
<com.app.LimitedSurfaceView
android:id="@+id/oglView"
android:layout_width="300dp"
android:layout_height="300dp"/>
<!-- other elements -->
</androidx.constraintlayout.widget.ConstraintLayout>
И создать класс LimitedSurfaceView:
package com.app;
public class LimitedSurfaceView extends GLSurfaceView {
private SceneRenderer renderer;
public LimitedSurfaceView(Context context) {
super(context);
}
public LimitedSurfaceView(Context context, AttributeSet attributes) {
super(context, attributes);
}
public void init(Context context) {
setPreserveEGLContextOnPause(true);
setEGLContextClientVersion(2); // or setEGLContextClientVersion(3)
renderer = new SceneRenderer(context);
setRenderer(renderer);
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
...
}
}
Затем в классе OpenGLActivity инициализируйте limitedSurfaceView:
package com.app.activities
public class OpenGLActivity extends AppCompatActivity {
private LimitedSurfaceView limitedSurfaceView;
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.activity_gl);
limitedSurfaceView = findViewById(R.id.oglView);
limitedSurfaceView.init(this.getApplicationContext());
...
}
}
Результат: