11
« on: January 21, 2009, 11:43:51 pm »
As I've hinted in another thread I've been working on getting SFML on the iPhone but I need some feedback on design decisions due to the nature of the device.
So far the following has been ported over complete but largely untested
SFML-System
SFML-Audio (minus libsnd)
SFML-Network
I'm currently working on SFML-Window and it is partially working. You can create a window, draw with OpenGLES and swap the buffers, here is the sample code that works.
/*
* test.cpp
* SFML-iPhone
*
* Created by Sean Chapel on 1/20/09.
*
*/
#include <SFML/Window.hpp>
#include <SFML/Window/UIKit/UserMain.h>
int main(int argc, char** argv)
{
sf::Window App(sf::VideoMode(320,480,32), "title");
sf::Clock Clock;
const GLfloat squareVertices[] =
{
-0.5f, -0.5f,
0.5f, -0.5f,
-0.5f, 0.5f,
0.5f, 0.5f,
};
const GLubyte squareColors[] =
{
255, 255, 0, 255,
0, 255, 255, 255,
0, 0, 0, 0,
255, 0, 255, 255,
};
while (App.IsOpened())
{
App.SetActive(true);
sf::Event Event;
while (App.GetEvent(Event))
{
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glRotatef(3.0f, 0.0f, 0.0f, 1.0f);
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glVertexPointer(2, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
App.Display();
}
return 0;
}
The only real difference is that I needed to include "SFML/Window/UIKit/UserMain.h". The reason for this is that inorder to run a UIWindow application it requires that the UIWindow handles the main loop, thus taking over control. I really hate that it does this so I used a hack like what SDL does and it redefines main to UserMain and when the UIWindow starts it calls UserMain, it works but it's not ideal.
So the next thing I want to get done is input. Touching the screen acts like a mouse, you have a press/release/drag and it has x,y coordinates however you can have multiple touches at once and SFML doesn't look like it support multiple mice. A solution would to use a joystick however it seems a bit odd.
The other thing the iPhone has is the accelerometer, which can act like a joysticks analog stick movement but it has no buttons.
Given the touch input and the accelerometer, where do you think these two things fit the best? I would like to avoid creating new devices for portability reasons (not everyone has a mac to develop with and developing iPhone games on linux and window seems appealing to my company).
Right now my idea is to make joystick 1 the accelerometer and joysticks 2-? the multi-touch inputs. I'm not sure how many touches you can do at once tho, I initially thought it was only two but I've heard some people talk about handling more.
The last thing is that the iPhone doesn't have a keyboard in the normal sense. It has the onscreen one and it does work properly over OpenGLES however it doesn't mesh well with games. I don't plan to support the built-in keyboard, it's easy enough to make your own and there is a lot of other work to be done however if enough people want it I will consider it.
I will be releasing this code and hopefully it can be included in SFML someday but until I get the SFML-Window lib ported over properly I don't see a reason to release the code.
Any thoughts and suggestions would be great.