hello! I'm new to the forum and I'm doing some testings on ios and android ports in order to make a cross platform framework.
I'm building sfml in my own makefiles and building only window and system modules in libsfml.a on windows using mingw: these are my compilation flags:
DEFS= -DSFML_STATIC -DSFML_OPENGL_ES -D__STDC_FORMAT_MACROS -D__USE_BSD -D_BSD_SOURCE -DPOSIX_SOURCE -DGL_GLEXT_PROTOTYPES -Dfdatasync=fsync -DPIC -fPIC -fexceptions -frtti -std=gnu++11
LDFLAGS = -lGLESv1_CM -lGLESv2 -lstlport_static -lc -ldl -lgcc -landroid -lEGL
CFLAGS = -shared -LC:\android\ndk\sources/cxx-stl/stlport/libs/armeabi-v7a -LC:\android\ndk\platforms/android-17/arch-arm/usr/lib C:\android\ndk\platforms/android-17/arch-arm/usr/lib/crtbegin_static.o -nostdlib -Wl,--no-undefined -Wl,--whole-archive libsfml.a -Wl,--no-whole-archive
everything goes ok in window and linux but once I try android things gets hard: I managed to compile and make an apk but when I run a simple main creating a window and displaying a cube, I get a black screen in emulator. in particular eglCreatePbufferSourface returns egl_bad_alloc. I tried to fix it using some custom attributes list: no more errors but still I get black screen with eglSurfaceAttrib not implemented.
#include <stdio.h>
#include <exception>
#include "rs.hpp"
#ifdef RS_PLATFORM_ANDROID
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#elif RS_PLATFORM_IOS
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#else
#include "glew/GL/glew.h"
#endif
#include "sfml/SFML/Window.hpp"
#define _PLAYGROUND_NAME "playground"
#define _PLAYGROUND_VERSION "0.1.0"
using namespace std;
int main(int argc,char **p_argv)
{
try
{
sf::Window window(sf::VideoMode::getDesktopMode(),"OpenGL");
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
#ifdef RS_PLATFORM_ANDROID
glClearColor(1.0,1.0,1.0,1.0);
glClearDepthf(1.f);
#elif RS_PLATFORM_IOS
glClearColor(1.0,1.0,1.0,1.0);
glClearDepthf(1.f);
#else
glClearDepth(1.f);
#endif
glDisable(GL_LIGHTING);
glViewport(0,0,window.getSize().x,window.getSize().y);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLfloat ratio = static_cast<float>(window.getSize().x) / window.getSize().y;
#ifdef RS_PLATFORM_ANDROID
glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
#elif RS_PLATFORM_IOS
glFrustumf(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
#else
glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f);
#endif
GLfloat cube[] =
{
-20, -20, -20, 0, 0,
-20, 20, -20, 1, 0,
-20, -20, 20, 0, 1,
-20, -20, 20, 0, 1,
-20, 20, -20, 1, 0,
-20, 20, 20, 1, 1,
20, -20, -20, 0, 0,
20, 20, -20, 1, 0,
20, -20, 20, 0, 1,
20, -20, 20, 0, 1,
20, 20, -20, 1, 0,
20, 20, 20, 1, 1,
-20, -20, -20, 0, 0,
20, -20, -20, 1, 0,
-20, -20, 20, 0, 1,
-20, -20, 20, 0, 1,
20, -20, -20, 1, 0,
20, -20, 20, 1, 1,
-20, 20, -20, 0, 0,
20, 20, -20, 1, 0,
-20, 20, 20, 0, 1,
-20, 20, 20, 0, 1,
20, 20, -20, 1, 0,
20, 20, 20, 1, 1,
-20, -20, -20, 0, 0,
20, -20, -20, 1, 0,
-20, 20, -20, 0, 1,
-20, 20, -20, 0, 1,
20, -20, -20, 1, 0,
20, 20, -20, 1, 1,
-20, -20, 20, 0, 0,
20, -20, 20, 1, 0,
-20, 20, 20, 0, 1,
-20, 20, 20, 0, 1,
20, -20, 20, 1, 0,
20, 20, 20, 1, 1
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), cube);
glTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), cube + 3);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
sf::Clock clock;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -100.f);
glRotatef(clock.getElapsedTime().asSeconds() * 50.f, 1.f, 0.f, 0.f);
glRotatef(clock.getElapsedTime().asSeconds() * 30.f, 0.f, 1.f, 0.f);
glRotatef(clock.getElapsedTime().asSeconds() * 90.f, 0.f, 0.f, 1.f);
glDrawArrays(GL_TRIANGLES, 0, 36);
window.display();
}
}
catch(exception &exception)
{
}
return 0;
}