Today, I've made a 3D object with OpenGL ES in android and thinking of displaying it into other layouts such as SurfaceView or FrameLayout in xml or in any possible way.
In the code below I'm setting the GL object into the onCreate's setContentView to display my object. If I were to display this GLSurfaceView somewhere else how can I do it ? It would be great if I can have some tips or example!
GLSurfaceView ourSurface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setting the gl surface view
ourSurface = new GLSurfaceView(this);
ourSurface.setRenderer(new GLCubeRender());
setContentView(ourSurface);
}
First you should create a class that extends GLSurfaceView with the constructor as you see in the following example
package com.ball.views;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
public class MYGLSurfaceView extends GLSurfaceView {
public MYGLSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
After this you could create a xml file with your own GLSurfaceView inside
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.ball.views.MYGLSurfaceView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/GLSurfaceView1" />
</LinearLayout>
Then change your code you posted before in order to set in the view the xml file you have created and to get the GLSurfaceView from the xml file
MYGLSurfaceView ourSurface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_xml_file);
//setting the gl surface view
ourSurface = (MYGLSurfaceView)this.findViewById(R.id.GLSurfaceView1);
ourSurface.setRenderer(new GLCubeRender());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With