5

I've been following the Android OpenGL tutorial using Android Studio 2.1.3 with Java Dev Kit 1.8.0 and SDK Version on API 24 (Android 7.0 Nougat) and I'm unable to set the OpenGL ES context # to 3.0 via setEGLContextClientVersion(3).

Doing so produces the following:

09-01 11:02:46.526 6822-6839/? E/AndroidRuntime: FATAL EXCEPTION: GLThread 149 Process: com.example.opengl, PID: 6822 java.lang.IllegalArgumentException: eglChooseConfig failed at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:852) at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1023) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1400) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)

Using setEGLContextClientVersion(2) works perfectly and the desired shape displays. I've tried adjusting my shaders in my Triangle & Square.java file to match 3.0 when trying setEGLContextClientVersion(3), but to no avail.

I've also tried to use setEGLConfigChooser(8, 8, 8, 8, 16, 4) as I've seen recommended to solve similar errors.

I've also tried restarting Android Studio and my emulators which are Android TV(1080p) API 24, Android TV(1080p) API 22, and Galaxy Nexus API 22.

Below is my MyGLSurfaceView.java code - again, if I adjust setEGLContextClientVersion(3) to (2), everything runs as expected.

package com.example.opengl;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.view.MotionEvent;

class MyGLSurfaceView extends GLSurfaceView {

private final MyGLRenderer mRenderer;

public MyGLSurfaceView(Context context) {
    super(context);

    //Create an OpenGL ES # context
    setEGLContextClientVersion(3);
    setEGLConfigChooser(8 , 8, 8, 8, 16, 4);

    mRenderer = new MyGLRenderer();
    setRenderer(mRenderer);
}

private final float TOUCH_SCALE_FACTOR = 180.0f / 320;
private float mPreviousX;
private float mPreviousY;

@Override
public boolean onTouchEvent(MotionEvent e){
    //MotionEvent reports input details from the touch screen
    // and other input controls. In this case, you are only
    // interested in events where the touch position changed.

    float x = e.getX();
    float y = e.getY();

    switch(e.getAction()) {
        case MotionEvent.ACTION_MOVE:

            float dx = x - mPreviousX;
            float dy = y - mPreviousY;

            //reverse direction of rotation above the mid-line
            if(y > getHeight()/2) {
                dx = dx * -1;
            }

            //reverse direction of rotation to left of the mid-lin
            if(x<getWidth()/2) {
                dy=dy * -1;
            }

            mRenderer.setAngle(mRenderer.getAngle()+((dx+dy)*TOUCH_SCALE_FACTOR)); // = 180.0f / 320
            requestRender();
    }

    mPreviousX = x;
    mPreviousY = y;
    return true;
    }
}

It's also worth noting that I have android:glEsVersion="0x00030000" in my Manifest and have import android.opengl.GLES30 for files that require GLES30/20 and everything runs smoothly provided that (2) is set.

Please let me know if I should add any additional code or information.

genpfault
  • 51,148
  • 11
  • 85
  • 139
lexalenka
  • 307
  • 4
  • 16

2 Answers2

1

Sometimes the phones, in which you are developing or running the app, does not have support for OpenGLES version 3. A way to check this, is by firstly using the OpenGles 2, and see if there is an error or not.Then if it works, it means that your phone does not support OpenGLES 3

Nick Asher
  • 726
  • 5
  • 19
  • I thought this was the case so I tried multiple emulators, all of which I believe should be 3 compatible, and they all exhibit the same behavior – lexalenka Sep 01 '16 at 21:14
  • Which emulators have you tried... and also please check this question http://stackoverflow.com/questions/24874066/does-the-android-emulator-support-opengl-es-3-0 – Nick Asher Sep 01 '16 at 21:34
  • 1
    I'm using Android TV(1080p) API 24, Android TV(1080p) API 22, and Galaxy Nexus API 22. I thought API 18+ supported OpenGLES3 as per the developers guide for graphics : https://developer.android.com/guide/topics/graphics/opengl.html. It seems from the attached link that the emulators might not be enough though :( . Thanks for point I can follow! – lexalenka Sep 01 '16 at 21:56
1

I ran into the same error message yesterday.

I found the following solution that worked for me:

  1. Start the emulator,
  2. Click on "Extended Controls" (the three dots) in the menu in the emulator window,
  3. Go to "Settings" in the "Extended Controls",
  4. Select "Renderer maximum (up to OpenGL ES 3.1)" in the "OpenGL ES API level (requires restart)" dropdown.

Note that this is not the same dropdown as the one that shows up when clicking on the edit pen when the emulator is not running. This is what stumped me yesterday.

Emil
  • 177
  • 1
  • 10