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.