![]() |
SDL on N900 / Maemo
i am new to Linux / N900 / SDL programming. but I am not new to mobile development (11 years) or programming (>25 years). i have experience in C and C++ plus a few other languages.
i am currently picking up an app that someone wrote here but has since abandoned a long time ago. this app uses SDL. the app is written in C to keep things simple. i call SDL_WM_ToggleFullScreen to get the app into full screen. everything works fine except - i can't use the CTRL-BACKSPACE key combo on the N900 to switch back out to the task viewer or desktop. the only way i can get out is to hit the power button at the top which brings down a menu and if i wait a few seconds it then goes back out to the desktop. i can then swap to the task manager and see my app's window. is there a way to pass the CTRL-BACKSPACE key combination back to the operating system instead of having it trapped by SDL? or is there another way to handle this? my thoughts now are to have a key in my app that allows the user to toggle between full screen and windowed mode. but ideally i would like my app to run in full screen all the time but still give the flexibility to the user to task out and say respond to an incoming SMS. |
Re: SDL on N900 / Maemo
Using D-Bus is the answer:
Code:
|
Re: SDL on N900 / Maemo
aaaaaaaaah thank u. thanks for the code snippet too.
let me try to figure out how to integrate this. i'm guessing i should run the code when i detect ctrl-backspace in SDL, yes? |
Re: SDL on N900 / Maemo
Include stdlib.h and you can use the code:
Code:
system("dbus-send /com/nokia/hildon_desktop com.nokia.hildon_desktop.exit_app_view"); You can either add a key combination or an on screen button much like the one originally in hildon windows. Ctrl+backspace works when I code in SDL & c++. Don't know why it doesn't for you. |
Re: SDL on N900 / Maemo
got it working nicely. thanks!!!!
i basically capture a keycode which i designate for activating the task manager. perfect. i don't know why ctrl-backspace doesn't work yet since i just started looking through the sources of that app. are you running in full screen mode? |
Re: SDL on N900 / Maemo
hmmmmmmmmm gotta spend a bit more time debugging the code though. if i manage to get toggle to the task manager ONCE, then ctrl-backspace works nicely thereafter without needing dbus.
but if i don't toggle to the task manager for the first time, ctrl-backspace doesn't work. |
Re: SDL on N900 / Maemo
Personally I think the user should have options to have either fullscreen or not - you can still make your preference the default without actually limiting user choice to make the app full-screen or not. Of course, some apps would be hard to properly scale to both fullscreen/'normal', so can't really be picky if that's the case.
|
Re: SDL on N900 / Maemo
Maybe its the way you go to fullscreen. Have you tried creating the screen surface already as a fullscreen surface with "SDL_SWSURFACE|SDL_FULLSCREEN"
|
Re: SDL on N900 / Maemo
nevermind. fixed it. all is fine and dandy. no need to use dbus anymore. yup, i had to use SDL_FULLSCREEN plus some other minor logic errors that the original author had in the code.
thanks folks. |
Re: SDL on N900 / Maemo
I love SDL :) I wrote some good things in C+SDL before (mainly a 2d/physics engine and other small cool stuff) and got them working on PSP, linux and now n900, without much tweaking at all, pretty cool
|
Re: SDL on N900 / Maemo
i like SDL too because of its simplicity and straight forwardness. feels like old-school API. :) there is less abstraction. it feels closer to the hardware. but that also means i have to do a bit more work on my own for some scenarios - which is fine by me.
|
Re: SDL on N900 / Maemo
folks - is there a way i can hildonize the SDL window? i'm trying to add some menu buttons and options to the app but can't find any examples for doing this.
|
Re: SDL on N900 / Maemo
also, i read in the wiki that a non-full screened SDL window will always be aligned to the top left corner of the screen. other than offsetting all my pixel drawing code, is there any other way to still have coordinate (0,0) offset slightly to the lower right?
|
Re: SDL on N900 / Maemo
Don't quite know what you need to do but you could have a look at using zenity. I've tweaked a few scripts but not built one from scratch. It looks similar to win32 dialog-script before visual studio turns them into GUI dialogs for you. The buttons can then call scripts or in your case possibly programme-functions.
Are there any GUI classes in SDL that could be used to make your menus etc? If so, just be careful with font-size and word-length - at least you know which device it's aimed at - not like pc software! |
Re: SDL on N900 / Maemo
the second part can be found here http://wiki.maemo.org/Game_development
if you look under the section about "SDL specific notes", look at the second bullet point. that's the issue i'm facing now. in non full screen mode, the window is aligned to the top left corner of the screen and my window is smaller than the entire screen size. so i'm getting a black border on the lower right section of the screen. ugly. as for menus, i'll take a peek at Zenity. i just want to implement some menus in my SDL application that allows the user to configure some settings. thanks. |
Re: SDL on N900 / Maemo
Quote:
|
Re: SDL on N900 / Maemo
hmmmmmm......neither seems like an elegant solution to me. :( both are painful. i'll still take a look. i would also keep trying to hack the SDL window to see if i can extend it. perhaps a search for SDL and GTK+ might give some clues......thanks.
|
Re: SDL on N900 / Maemo
i guess it won't work. i think the best way is to use any of the available UI libraries for SDL.
|
Re: SDL on N900 / Maemo
Can you elaborate on what you want to do?
- If you want to show the "window has menu" icon on the titlebar, that is mostly easy to do. But what are you going to do when the user clicks on it? Render an in-game menu? -- that would be easy. Open a new popup window? hard -- SDL 1.2 does not support multiple windows. - You don't like top-right, ok. So do you want the image centered? Scaled? Either way, I suggest you avoid windowed mode like the plague (so also, you should not do the menu thing). There's a large performance hit so anything other than simple 2D apps get slow. I also suggest you do not create a surface that is smaller than the screen, because that is not portable -- maemo adds black borders, but webos rescales. |
Re: SDL on N900 / Maemo
the app is a simple 2d app. so far it doesn't consume more than 50% CPU (averages about 20-30% when it is running full speed). so speed is still ok.
i don't want to set an icon on the title bar. that's not important to me :) all i want is a bunch of user interface elements that i can use to change settings in my app. for example, i would like to change the path where my app saves data. how would i create a UI for this in SDL? |
Re: SDL on N900 / Maemo
yes, i would like to have my image centered. it does not need to be scaled. the image is already scaled via internal routines in the app.
i have solved this for now by modifying the call to SDL_BlitSurface and specifying the target rectangle to be slightly offset to the lower right. |
Re: SDL on N900 / Maemo
Quote:
- If you're targeting Maemo/Meego only, now it's the time time to think if you should make that UI in Qt. A few 2D games have been developed in QML already. - Professional games usually have their own widget "toolkit" for SDL/plain framebuffer and they change it for every game so that the widgets are themed in the game's style. This is what most complex/3D iPhone games, WebOS games, etc. do. - You can use one of those SDL-based widget toolkits around (many of them but I have no experience with any). - You can code a Gtk+ or Qt launcher application, where you can configure the SDL game before launching it. This is what the built-in N900 games and DrNokSnes do (so you can try the result!). |
Re: SDL on N900 / Maemo
problem is with the app i'm working on, some of the settings need to be changed on the fly. ok, i'll come clean. this is for an apple ][ emulator. i need to be able to swap disks on the fly since there are only 2 drives and some games can span 4 disks.
so the DrNokSnes example won't work for me (would have loved it though. an excuse to learn python). if i build the UI in Qt (which i would also love!!), my issue is trying to figure out how to tie the entire Qt portions of the code into SDL and the emulator. the emulator is originally written to use directX on windows (AppleWin). i picked up the work after Arnim dropped it off many moons ago (i think 1 year ago) when he did a port to N800. he picked it up from a linux based port of the emulator (that was based off the windows version) that was already running using SDL. based on ArnimS' version, the emulator could only boot up and load a disk on the N900. it emulated the content fine though but no keyboard input, sound was whacked, tasking out didn't work, etc. a lot of things were broken. i've been progressively fixing these issue and it is now in a very very useable state on the n900. the next major hurdle i'm facing is to build some simple UI around the emulator that allows the user to change settings on the fly. that's where i'm currently stuck at, and i'm leaning now towards the UI libraries that are listed on the SDL home page. |
Re: SDL on N900 / Maemo
Quote:
(It is not python btw). |
Re: SDL on N900 / Maemo
hmmmmm that's an interesting idea (saving state)...will give this a thought.
|
Re: SDL on N900 / Maemo
SDL and GUI is a nightmare IMO for everything else than a game (at least on a desktop). I would not use it again for a software project! You could check out Agar GUI, that's what we sticked to in the end (with all the problems of a non-standard GUI). The dev is responsive, it is fast, portable and themeable. Basically it can substitute SDL (but also works on top of it).
|
Re: SDL on N900 / Maemo
yeah, i had a look at it and was thinking of using Agar as a last resort. i am still inclined to work with the DrNokSnes approach.
i tested saving and restoring state on the emulator last night and it works fine. all i need now is a way to communicate between a separate app, say in Qt for all the menu options etc, and the emulator itself so that each knows when to stop and continue when the other is done. i'm guessing the Qt app will be the entry point to the emulator. it then fires up the emulator once all configuration is done. however, i have yet to figure out how to get the emulator to return control back to the Qt app when the user wants to change some configuration. i was thinking of sending a kill signal to the emulator (the emulator already has an option to save state when it exits gracefully) from the Qt app and leaving the Qt app running all the while. but i do need to be able to differentiate between a user exiting the emulator and a user wanting to make a change in the config. not impossible as i have a rough idea of how to do this already with exit codes. |
Re: SDL on N900 / Maemo
anyone has experience around the audio APIs in SDL? specifically, i'm referring to these http://wiki.libsdl.org/moin.cgi/CategoryAudio. the emulator doesn't use sdl_mixer.
i seem to be getting crackling sounds everytime an audio clip is played by the emulator. it plays fine but at the end there is a slight crack in the audio output. as a result, some games have music that lags (i'm guessing because the game plays music as separate distinct "pulses" vs a continuous stream). any ideas? |
Re: SDL on N900 / Maemo
no one? increasing the buffer size obviously solves this but introduces lag (no surprises, FIFO buffer).
|
Re: SDL on N900 / Maemo
it seems like SDL is buggy on the N900. i have audio buffers that have zero-ed values being submitted to SDL via the audio callback function and i still hear crackling sounds. NOOOOOOOOOOOOOOOOOOOOOO!!! :(
http://lists.mandriva.com/bugs/2010-04/msg02238.php http://maemo.org/packages/view/libsdl1.2/ http://bugzilla.libsdl.org/show_bug.cgi?id=698 sigh.....we have 1.2.13 on the n900. the bug was fixed in 1.2.14 of SDL. damnit! |
Re: SDL on N900 / Maemo
I do not see what you're talking about. Half if not all the games in Maemo use SDL for audio, and they experience no crackling. Also, Maemo does not use such a recent version of PA.
Please provide a testcase, as small as possible. |
Re: SDL on N900 / Maemo
that's good to know. yes, i was planning to write a simple app to test this out.
it's weird that the emulator does that. it also suffers from chronic buffer underruns.... anyway, will report back once i have that test app running. |
Re: SDL on N900 / Maemo
i've managed to solve the crackling sound. it's the way the emulator code was written.
i never realized this problem until now because i've been doing testing with the phone connected via USB: when i unplug the phone from the USB, the sound becomes super choppy and it struggles to keep up. it's like the emulator is slowing down?? when it's plugged into the charger, sound is almost smooth (98%). if i unplug the charger and run the emulator, i can replicate the *almost smooth* sound playback by pressing on a key. i don't need to be focused in the emulator's window to replicate this. i can press and hold a key in the desktop and the sound playback will be smooth. hmmmmmmm |
Re: SDL on N900 / Maemo
problem fixed. code issue.
|
All times are GMT. The time now is 10:29. |
vBulletin® Version 3.8.8