OpenGL ES not working on Android

I’m writing a cross-platform game with SDL2 and OpenGL/OpenGL ES. My first test works OK in Linux with “full fat” OpenGL, but won’t work properly on Android. The symptoms are different depending on which device I run it on. The test just renders a flat square with a grassy texture and spins it slowly against a black background. On my Samsung Galaxy S3 phone it sort of works, but the colours are all wrong. The background is red and the grass is pink. On my Kindle Fire HD it seems to be able to create the buffers and load the texture OK, but fails just prior to rendering, glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, …) failing with GL_INVALID_OPERATION. On my Galaxy Tab 8.9 it fails before that, glGenTextures failing with the same code. Actually, it’s possible that earlier gl calls are failing and I just missed out checking the error status on them, but it’s definitely significantly different behaviour across the 3 devices.

This is how I initialise the context (non-Android bits snipped):

Code:

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
mWindow = SDL_CreateWindow(mStartData.appname,
        SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0, 0,
        SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN);
mGlContext = SDL_GL_CreateContext(mWindow);

Checking glGetString(GL_VERSION) just after that point gives expected results, “OpenGL ES 2.0 …”, but then things start to go wrong.

I am using threads (with C++11’s API rather than SDL’s) but I’ve been careful to make sure all OpenGL calls stay on the original thread and verified that by checking the thread id. I also tried adding SDL_GL_MakeCurrent(mWindow, mGlContext); just after the above code, but that doesn’t make any difference.

2014-06-20 16:22 GMT-03:00 realh :

I’m writing a cross-platform game with SDL2 and OpenGL/OpenGL ES. My
first test works OK in Linux with “full fat” OpenGL, but won’t work
properly on Android. The symptoms are different depending on which device I
run it on. The test just renders a flat square with a grassy texture and
spins it slowly against a black background. On my Samsung Galaxy S3 phone
it sort of works, but the colours are all wrong.

This appears to be a known issue:
https://bugzilla.libsdl.org/show_bug.cgi?id=2291#c47

Right now the fix is to use SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); on
those devices.

The background is red and the grass is pink. On my Kindle Fire HD it seems
to be able to create the buffers and load the texture OK, but fails just
prior to rendering, glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, …) failing with
GL_INVALID_OPERATION. On my Galaxy Tab 8.9 it fails before that,
glGenTextures failing with the same code. Actually, it’s possible that
earlier gl calls are failing and I just missed out checking the error
status on them, but it’s definitely significantly different behaviour
across the 3 devices.

Welcome to Android! :wink:

You can try your OpenGL ES app on Linux Desktop too (with nVidia drivers,
or with Mesa installed), that might make things easier to figure out.

Gabriel.

That issue seems to be specific to S3 phones, I’ve got even bigger problems with other Android devices. Comments on that bug seem to suggest SDL has problems with EGL. So I just tried the code on my Raspberry Pi and that had problems too: glGetString(GL_VERSION) returns a null string, but the next thing to go wrong is that it fails to find one of my shader variables.

I’ve been working on this project for some time, and an earlier version used SDL1 for Linux, with my own code for creating an OpenGL context (supporting GLX, WGL and EGL as necessary) instead of using SDL_WINDOW_OPENGL etc, and for Android I was using Android’s native API directly instead of SDL. I had it all working properly, but I thought it would make things easier to use SDL2 for everything :(.

You can try your OpenGL ES app on Linux Desktop too (with nVidia drivers, or with Mesa installed), that might make things easier to figure out.

I’ve tried that too (basically using the SDL_GL_CONTEXT attributes as shown above instead of SDL_GL_CONTEXT_PROFILE_CORE) and noticed another discrepancy. After requesting OpenGL ES with SDL2 glGetVersion returns “3.0 Mesa 10.1.3” and “GLSL 1.30” whereas with my old code, using GLX directly, I get “OpenGL ES 3.0 Mesa 10.1.3” and “OpenGL ES GLSL ES 3.0”. It runs OK though, despite the supposed differences in the shader languages.

That issue seems to be specific to S3 phones, I’ve got even bigger
problems with other Android devices. Comments on that bug seem to suggest
SDL has problems with EGL. So I just tried the code on my Raspberry Pi and
that had problems too: glGetString(GL_VERSION) returns a null string, but
the next thing to go wrong is that it fails to find one of my shader
variables.

Does this mean that SDL2 can’t be used for writing OpenGL / OpenGL ES apps
on Android? I was planning to use SDL2 on Android for exactly that purpose?
Bummer :frowning:

ardiOn Mon, Jun 23, 2014 at 7:42 PM, realh wrote:

2014-06-24 11:40 GMT-03:00 Ardillas del Monte :

That issue seems to be specific to S3 phones, I’ve got even bigger
problems with other Android devices. Comments on that bug seem to suggest
SDL has problems with EGL. So I just tried the code on my Raspberry Pi and
that had problems too: glGetString(GL_VERSION) returns a null string, but
the next thing to go wrong is that it fails to find one of my shader
variables.

Does this mean that SDL2 can’t be used for writing OpenGL / OpenGL ES apps
on Android? I was planning to use SDL2 on Android for exactly that purpose?
Bummer :frowning:

ardi

This is not true. There’s a lot of SDL2/Android apps, they all use GL ES,
including desktop ported games like Portal and Half Life 2.> On Mon, Jun 23, 2014 at 7:42 PM, realh wrote:


Gabriel.

2014-06-24 11:40 GMT-03:00 Ardillas del Monte <@Ardillas_del_Monte
<javascript:_e(%7B%7D,‘cvml’,’@Ardillas_del_Monte’);>>:

That issue seems to be specific to S3 phones, I’ve got even bigger
problems with other Android devices. Comments on that bug seem to suggest
SDL has problems with EGL. So I just tried the code on my Raspberry Pi and
that had problems too: glGetString(GL_VERSION) returns a null string, but
the next thing to go wrong is that it fails to find one of my shader
variables.

Does this mean that SDL2 can’t be used for writing OpenGL / OpenGL ES
apps on Android? I was planning to use SDL2 on Android for exactly that
purpose? Bummer :frowning:

ardi

This is not true. There’s a lot of SDL2/Android apps, they all use GL ES,
including desktop ported games like Portal and Half Life 2.

If I’m reading the thread correctly, it’s not possible to allocate a Z
Buffer on S3 devices. This sounds like a show stopper for me, because I’m
using GL for 3D graphics, and 3D really requires a depth buffer. And
considering that this is affecting Samsung devices, that would be a problem
for me.

ardiOn Tuesday, June 24, 2014, Gabriel Jacobo wrote:

On Mon, Jun 23, 2014 at 7:42 PM, realh <h at realh.co.uk <javascript:_e(%7B%7D,‘cvml’,‘h at realh.co.uk’);>> wrote: