1

I'm trying to make an app that load and display an image using NDK, JNI to call C++ code. However, i ran into some error, something wrong with my shader (I'm using GLES for OpenGL ES 3.0) and it couldn't be compiled and i have no idea how to fix it. Here is the logs:

02-14 15:53:37.523 6379-6379/? I/art: Not late-enabling -Xcheck:jni (already on)
02-14 15:53:37.523 6379-6379/? W/art: Unexpected CPU variant for X86 using defaults: x86
02-14 15:53:37.990 6379-6398/com.android.gl2jni I/OpenGLRenderer: Initialized EGL, version 1.4
02-14 15:53:37.990 6379-6398/com.android.gl2jni D/OpenGLRenderer: Swap behavior 1
02-14 15:53:38.119 6379-6398/com.android.gl2jni E/EGL_emulation: tid 6398: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
02-14 15:53:38.119 6379-6398/com.android.gl2jni W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9b67fa80, error=EGL_BAD_MATCH
02-14 15:53:38.166 6379-6397/com.android.gl2jni E/libc: Access denied finding property "ro.opengles.version"
02-14 15:53:38.172 6379-6397/com.android.gl2jni I/libgl2jni: GL Version = OpenGL ES 2.0 (4.3.0 - Build 10.18.14.4414)
02-14 15:53:38.173 6379-6397/com.android.gl2jni I/libgl2jni: GL Vendor = Google (Intel)
02-14 15:53:38.173 6379-6397/com.android.gl2jni I/libgl2jni: GL Renderer = Android Emulator OpenGL ES Translator (Intel(R) HD Graphics 4400)
02-14 15:53:38.173 6379-6397/com.android.gl2jni I/libgl2jni: GL Extensions = GL_EXT_debug_marker GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_depth24 GL_OES_depth32 GL_OES_element_index_uint GL_OES_texture_float GL_OES_texture_float_linear GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_packed_depth_stencil GL_OES_vertex_half_float GL_OES_texture_npot GL_OES_rgb8_rgba8 ANDROID_EMU_CHECKSUM_HELPER_v1 
02-14 15:53:38.173 6379-6397/com.android.gl2jni I/libgl2jni: setupGraphics(1080, 1776)
02-14 15:53:38.179 6379-6397/com.android.gl2jni E/libgl2jni: Could not compile shader 35633:
                                                             ERROR: unsupported shader version
02-14 15:53:38.179 6379-6397/com.android.gl2jni E/libgl2jni: Could not create program.
02-14 15:53:38.183 6379-6397/com.android.gl2jni I/libgl2jni: after glClearColor() glError (0x502)
02-14 15:53:38.184 6379-6397/com.android.gl2jni I/libgl2jni: after glClearColor() glError (0x501)

My vertex Shader in CPP file:

auto gVertexShader =
"#version 300 es\n"
"layout (location = 0) in vec3 position;\n"
"layout (location = 1) in vec3 color;\n"
"layout (location = 2) in vec2 texCoord;\n"

"out vec3 ourColor;\n"
"out vec2 TexCoord;\n"

"void main()\n"
"{\n"
    "gl_Position = vec4(position,1.0f); // Add the xOffset to the x position of the vertex position\n"
    "ourColor = color;\n"
    "TexCoord= vec2(texCoord.x,1.0f-texCoord.y);\n"
"}";

My fragment shader in CPP file:

auto gFragmentShader =

"#version 300 es\n"
"in vec3 ourColor;\n"
"in vec2 TexCoord;\n"

"out vec4 color;\n"

"uniform sampler2D ourTexture;\n"


"void main()\n"
"{\n"
    "color = texture2D(ourTexture , TexCoord);\n"
"}\n";
Toan Tran
  • 476
  • 6
  • 28

1 Answers1

0

version 330 isn't a valid GLSL version number for an OpenGLES 2.0 context.

GLSL versions are discussed here. For an OpenGLES 2.0 context you need to use #version 100, which is similar to version 120 from desktop, your shader code would need a number of changes before it could work. Alternatively you could create an OpenGLES 3.0 context and use "#version 330 es", but you would lose access to about 40% of Android devices (source)

Community
  • 1
  • 1
Columbo
  • 6,648
  • 4
  • 19
  • 30
  • Hi Columbo, thanks for your answer. After considering, I would like to create an OpenGLES 3.0 context and use #version 330 es. However, I'm a newbie in OpenGL ES so could you please guide me how to create an OpenGLES 3.0 context? I'm using this example : https://github.com/googlesamples/android-ndk/tree/master/hello-gl2. – Toan Tran Feb 14 '17 at 07:17
  • Look in GL2JNIView.java, createContext, you'd need to change the options in there. – Columbo Feb 14 '17 at 07:29
  • i set it to setEGLContextClientVersion(3); and edit my Manifest.xml file with But the app crash on launching, any idea why ? – Toan Tran Feb 14 '17 at 07:42
  • Does your device support OpenGLES 3? Lots of apps can help you check (e.g. AIDA64) – Columbo Feb 14 '17 at 07:53
  • By device, which one do you mean? My PC or my Android Emualtor? Btw, I'm trying to use GLSL for OpenGL ES 3.0 with declaration #version 300 es. However, i got this error in the log: ------------------------Could not compile shader 35633: ERROR: unsupported shader version. ---------------------------- Could you pls help me how to solve this ? – Toan Tran Feb 14 '17 at 09:43
  • 1
    The emulator doesn't support OpenGL ES 3.0; if you want to test ES 3.x you'll need a real device which supports it. – solidpixel Feb 14 '17 at 11:57