1

Please keep in mind that I am new to android development and I have no experience of using OpenGL before. I followed this lesson: http://developer.android.com/training/graphics/opengl/environment.html

and my current code is:

OpenGLESTestActivity.java:

package com.KML;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.opengl.*;

import com.KML.MyGLRenderer;

public class OpenGLESTestActivity extends Activity {
    /** Called when the activity is first created. */

    private GLSurfaceView mGLView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mGLView = new MyGLSurfaceView(this);
        setContentView(mGLView);
    }
}

class MyGLSurfaceView extends GLSurfaceView {


    public MyGLSurfaceView(Context context) {
        super(context);
        setRenderer(new MyGLRenderer());
        this.setEGLContextClientVersion(2);
        this.setRenderMode(RENDERMODE_WHEN_DIRTY);
    }
}

in MyGLRenderer.java:

package com.KML;

import android.opengl.GLES20;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView;


public class MyGLRenderer implements GLSurfaceView.Renderer {

    public void onSurfaceCreated(GL10 unused, EGLConfig config) {
        GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    }

    public void onDrawFrame(GL10 unused) {
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    }

    public void onSurfaceChanged(GL10 unused, int width, int height) {
        GLES20.glViewport(0, 0, width, height);
    }

}

This is giving me "Unfortunately, OpenGLESTest has stopped." on my android device.

Thanks

5
  • 1
    Post the exception my dear friend!
    – Wroclai
    Commented Aug 24, 2012 at 19:44
  • It may be, that your device doesn't support OpenGL ES 2.0, but please send a log for sure. Commented Aug 24, 2012 at 19:49
  • If you are using the emulator, you might not have Graphics Rendering or OpenGL activated (something like that). Older versions of the emulator did not support OpenGL stuff. Commented Aug 24, 2012 at 19:56
  • sorry, this may sound really noobish, but how do I get the error log? And I am testing it on my Transformer Prime. I read somewhere that the emulator doesn't support OpenGL, and the emulator is super slow anyway.. Commented Aug 24, 2012 at 20:54
  • What is your development environment? If you're using eclipse, it usually appears in a small window called "LogCat". After the crash you should see a block of red text about 20-50 lines long which says what caused the crash. If you don't use eclipse, I know you can get the logcat from adb, but I don't know the exact command. Try adb -help (or some such help command)
    – Tim
    Commented Aug 24, 2012 at 22:02

1 Answer 1

3

OpenGLES on Android - IllegalStateException: setRenderer has already been called for this instance

public MyGLSurfaceView(Context context) 
{
    super(context);
    setEGLContextClientVersion(2);
    setRenderer (new MyRenderer());
    setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}

It's the order you are setting up everything that is wrong.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.