My OpenGL ES shader fails to link with no error.

Read time: 4 minutes

At the beginning of the year I decided instead of trying to start/run/manage tonnes of side projects I was going to focus on one single project at a time. That project is a cross platform visual editing tool that allows you to write Lua on your phone/tablet/computer to interact with an OpenGL ES 3 surface.

As part of that; and being entirely out of my depth with this, the time came to write a shader (or two) to actually rasterise to the screen. This worked great on my laptop (hooray, that was easy) but my phone just wouldn't link my shaders at all and it gave no error, no status codes, nothing.

5 days later, I stumbled across which is incredible and alluded straight away to the fact that glCreateShader(GLEnum) will return 0 if there's no context in which to create a shader object from. hallelujah I had something to go on, I took my setup code from a place where I thought my context was fully set up and put it somewhere where I could guarantee my openGL context was set up and voila, it worked straight away.

Aside from glCreateShader returning 0, all other operations such as glCreateProgram are actually no-ops which means they won't/don't error and they don't return anything useful or trigger anything for glGetError to pick up. Another reminder that debugging usually means going further back than you think reasonable.

An excerpt from the C++ code that initializes my EGL surface (based on the Android NDK NativeActivity sample)

2  // The window is being shown, get it ready.
3  if (engine->app->window != NULL) {
4    engine_init_display(engine);
6    entryScript->setUserCodePath(;
7    entryScript->setAssetsPath(scriptStorage->rootPath);
8    entryScript->runUserScript();
9    entryScript->runSetupFunction();
11    engine_draw_frame(engine);
12  }
13  break;

OpenGL ES 3 multicolour triangle rendered from Lua

The above image is rendered from the below Lua script. It's still very explicit at the moment (more on this as the project develops)

1local shader = Shader:new()
2local triangleVertices = {
3  -0.5, -0.5, 0.0,
4  0.5, -0.5, 0.0,
5  0.0, 0.5, 0.0,
7local triangleColours = {
8  1.0, 0.0, 0.0,
9  0.0, 1.0, 0.0,
10  1.0, 0.0, 1.0,
12local uniforms = {
13  angle = 0.1,
16function setup()
17  -- Load the default shader.
18  shader:load("default")
20  -- Set the vertices for the vertex shader.
21  shader:setVertices(triangleVertices)
22  shader:setColours(triangleColours)
25function render()
26  -- Clear the screen to this colour.
28  GL.ClearColor(0.3, 0.0, 0.3, 1)
30  uniforms.angle = uniforms.angle + 0.01
31  shader:setUniforms(uniforms)
33  -- Run the shander.
34  shader:run()
36  -- Draw our triangles
37  GL.DrawTriangles(#triangleVertices)

The above script will give you a lovely, slowly spinning, multicoloured triangle on your laptop, phone or tablet.