Thought i would give a quick demo of my progress.
The goal is to have all the gui_apps in the examples projects folder in sfmls cmake folder run. Preferably with as little or no changes if possible.
Below is a quick example of sfml system and sfml window parts. It simply makes the entire screen a color.
The green color is controlled by a timer and reset every second and can be reset when your finger touches the screen. The red color is controlled by your fingers last x position and blue by your fingers last y position.
all the same as normal sfml except using gles. There is one part at the top which is driving me nuts. If i have that function where I wanted in sfml window then when it is statically linked the compiler optimizes it out ><. If you have any ideas. I would appreciate it.
/*
stupid peice of code here. The android activity handling stuff would be completely unnoticed.
Though because it is adding a static library and if the ANativeActivity_onCreate entry point is in it. it seems to get Optimised out. >< joy.
*/
#include <android/native_activity.h>
extern void ANativeActivity_onCreate2(ANativeActivity* activity, void* savedState, size_t savedStateSize);
void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_t savedStateSize)
{
ANativeActivity_onCreate2(activity, savedState, savedStateSize);
}
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include <GLES/gl.h>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create the main window
sf::Window window(sf::VideoMode(640, 480, 32), "SFML Window", sf::Style::Default, sf::ContextSettings(32));
// Create a clock for measuring the time elapsed
sf::Clock clock;
sf::Vector2u size=window.getSize();
// Start the game loop
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::MouseButtonPressed)
clock.restart();
// Resize event : adjust viewport
if (event.type == sf::Event::Resized)
glViewport(0, 0, event.size.width, event.size.height);
}
float x = sf::Mouse::getPosition(window).x;
float y = sf::Mouse::getPosition(window).y;
x /=size.x;
y /=size.y;
float val=clock.getElapsedTime().asSeconds();
if(val>1)
val=clock.restart().asSeconds();
glClearColor(x, val, y , 1);
glClear(GL_COLOR_BUFFER_BIT);
// Finally, display the rendered frame on screen
window.display();
}
return EXIT_SUCCESS;
}
below is a video. unfortunately it is not very clear on when i am clicking which is mean to represent my finger on the screen.
http://www.youtube.com/watch?v=hwbmQmvVli4 (http://www.youtube.com/watch?v=hwbmQmvVli4)
I also use extra stuff not shown. Like threads, mutex's and locks. It was required to get the main thread working.
Also any experienced OpenGL ES 2 users around? I suppose this is really not the place where they would be. Having worked on mobiles which are not really related to SFML. Restructuring the graphics library will be hardest. plus compiling it's libs for android. Hopefully I can offload that work onto you guys :P
Regarding your issue with the optimized native activity: You don't have to use it or create it on your own - at least I've never done so so far. The NDK provides premade code you can link.
The AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.unique.package.name"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="12" />
<application
android:label="@string/app_name"
android:hasCode="false" >
<activity
android:name="android.app.NativeActivity"
android:label="@string/app_name" >
<meta-data android:name="android.app.lib_name"
android:value="mylibraryname" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The main entry point in main.cpp looks like this:
#include <android_native_app_glue.h>
int main(int argc, char **argv) {
// stuff happening...
return 0;
}
In your Android.mk make sure to link the following static library:
LOCAL_STATIC_LIBRARIES := android_native_app_glue
I plan to work on it soon after SFML 2.0 is released.
You should share your work so that I can use it when doing the official port :)
Let me know if/when you start doing so and could need some help. Would love helping you getting it written, tested, etc. and to get some prototype games stuff finally ported to Android (and finished).