Is there any possiblity to compile console android app with SDL2? I already have libSDL2.so for android and toolchain that is working on android and compile for android (using CppDroid).
I was said that it will be OpenGL ES conflict (as SDL2 uses Open GL behind the scene on Android).
The next source code is said to work on old android, but even fail to launch on modern android:
#include
#include
#include
#include
//extern "C" EGLNativeWindowType android_createDisplaySurface(void);
EGLNativeWindowType android_createDisplaySurface(void);
EGLNativeWindowType displayWindow;
int width = 0;
int height = 0;
const EGLint config16bpp[] =
{
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_NONE
};
GLfloat colors[3][4] =
{
{1.0f, 0.0f, 0.0f, 1.0f},
{0.0f, 1.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f}
};
GLfloat vertices[3][3] =
{
{0.0f, 0.7f, 0.0f},
{-0.7f, -0.7f, 0.0f},
{0.7f, -0.7f, 0.0f}
};
void draw_tri()
{
glViewport(0,0,width,height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_FLOAT, 0, colors);
glVertexPointer(3, GL_FLOAT, 0, vertices);
// Draw the triangle (3 vertices)
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
int main(int argc, char** argv)
{
EGLint majorVersion, minorVersion;
EGLContext eglContext = NULL;
EGLSurface eglSurface;
EGLConfig eglConfig;
EGLDisplay eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
int numConfigs;
// Window surface that covers the entire screen, from libui.
displayWindow = android_createDisplaySurface();
eglInitialize(eglDisplay, &majorVersion, &minorVersion);
printf("GL version: %d.%d\n",majorVersion,minorVersion);
if (!eglChooseConfig(eglDisplay, config16bpp, &eglConfig, 1, &numConfigs)) {
printf("eglChooseConfig failed\n");
if (eglContext == 0) {
printf("Error code: %d\n", eglGetError());
}
}
eglContext = eglCreateContext(eglDisplay,
eglConfig,
EGL_NO_CONTEXT,
NULL);
printf("GL context: %p\n", eglContext);
if (eglContext == 0) {
printf("Error code: %x\n", eglGetError());
}
eglSurface = eglCreateWindowSurface(eglDisplay,
eglConfig,
displayWindow,
NULL);
printf("GL surface: %p\n", eglSurface);
if (eglSurface == 0) {
printf("Error code: %x\n", eglGetError());
}
eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
eglQuerySurface(eglDisplay, eglSurface, EGL_WIDTH, &width);
eglQuerySurface(eglDisplay, eglSurface, EGL_HEIGHT, &height);
printf("w=%d, h=%d\n", width, height);
while (1) {
draw_tri();
eglSwapBuffers(eglDisplay, eglSurface);
}
return 0;
}