Answer the question
In order to leave comments, you need to log in
How to embed OpenGL ES into XML?
I did the animation using the View class, but the animation hung up for me, I was advised to use OpenGl ES. My animation is 1/4 of the screen and I inserted it via XML markup like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bbf"
android:layout_weight="1">
.
.
.
</ScrollView>
<ru.dima_n.elem.Anim
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/game_view"
android:layout_weight="2"
android:onClick="OnClickAnim"
android:background="#000"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="horizontal">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
android:layout_weight="1"
android:background="#000"/>
<ru.dima_n.opengl.Anim
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/game_view"
android:layout_weight="2"
android:background="#ff0360ff"
/>
</LinearLayout>
public class Anim extends View
{
GLSurfaceView glSurfaceView;
nRender renderer;
public Anim(Context context, AttributeSet attrs)
{
super(context, attrs);
try{ // пытаемся инициализировать OpenGL
glSurfaceView = new GLSurfaceView(context);
glSurfaceView.setEGLContextClientVersion(2);
renderer = new nRender();
glSurfaceView.setRenderer(renderer);
glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
Log.e("удачно", "3456");
}catch(RuntimeException e){
Log.e("error","error");
}
}
}
public class nRender implements GLSurfaceView.Renderer
{
GLSurfaceView glSurfaceView;
public nRender()
{
}
public void onDrawFrame(GL10 glUnused) {
Random rnd = new Random();
GLES20.glClearColor(((float)rnd.nextInt(2)/2.0f), ((float)rnd.nextInt(2)/2.0f), ((float)rnd.nextInt(2)/2.0f), 1.0f);
Log.e("test","color"); // этот лог не выводиться
GLES20.glClear( GLES20.GL_COLOR_BUFFER_BIT );
}
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
GLES20.glViewport(0, 0, width, height);
}
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
}
}
Answer the question
In order to leave comments, you need to log in
Well, initially it is not true that you are trying to initialize SurfaceView in the view constructor and thus receive an object, but do not receive it in your view hierarchy. To implement your problem, you can use GLSurfaceView or SurfaceView but above view should be, for example, inherited from GLSurfaceView. Learn more developer.android.com/reference/android/opengl/GLS...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question