here are Android versions of two small and (hopefully) handy classes for blitting text and images. more information can be found on original thread (http://www.jpct.net/forum2/index.php/topic,1074.0.html)
TexturePack (http://www.aptalkarga.com/download/android/TexturePack.java) packs several arbitrary sized images into a jPCT texture. it automatically layouts images and adjusts Texture size.
AGLFont (http://www.aptalkarga.com/download/android/AGLFont.java) creates GL renderable (blittable) fonts out of Android fonts.
Rectangle (http://www.aptalkarga.com/download/android/Rectangle.java) is used by AGLFont.
Bones Android demo app (http://www.aptalkarga.com/bones/bones_android_demo.zip) demonstrates how to use it
and an addition to GLFont (http://www.jpct.net/forum2/index.php/topic,3528.0.html) by nmare which allows multi-line and multi-color text blits
cheers ;D
r a f t
edit: updated the links and fixed getStringBounds(..) issue
edit2: added link to nmare's addition
An apk would be cool in addition...
Quote from: EgonOlsen on March 30, 2010, 08:18:12 PM
An apk would be cool in addition...
already there is an apk (http://www.aptalkarga.com/bones/Bones-Android-Ninja.apk) indeed. it's listed in Bones home page
I see...works fine (30fps without/8fps with animation) and looks great on my phone. I would be very interested to know how this runs on the Nexus One... dl.zerocool to the rescue?
i've already asked him for a test ;) hoping he wont mind quoting from pm:
Quote
Here is some basic results. Apparently everything runs pretty fine.
while not animating fps are arround 55 to 59
When the animation starts you drop down to 15fps to 20fps~ depending on which animation you choose, then after a second it goes back to 30fps even "spin" animation who look like a little bit slower that the other (sometimes it fall back from 30 to 26 fps)
What is strange is that all animation get stuck to 30fps after a second, like there's something synchronizing behind.
I didn't had time to look at your code, so at moment I'm just running the apk demo.
slow down while animating is expected. but i cant explain it gain some speed again. it behaves like it has JIT but it hasnt AFAIK. maybe Android detects continuous data flow and make some optimization ???
I think so. I've noticed that too on my applications just to a smaller amount. Dalvik might do some caching or similar. However, 30 fps is a pretty good result. If they enable this new JIT in addition, maybe 50-60 fps will be possible... ;D
capture of some speech bubbles on emulator.
texts are blitted with GLFont, bubble images are blitted with TexturePack:
(http://img641.imageshack.us/img641/4462/blittingandroid.png)
blitting really hurts performace at least on emulator, dont know why ???
Which version of AE is this? The latest?
latest i suppose (1.21). i downloaded yesterday
Yes, that should be the latest then. I was asking, because i already improved blitting performance. I assume that each character is a single, transparent and maybe scaled blit? Is there an apk to try this on actual hardware? The emulator isn't a fillrate wonder.
However, i can see one or two additional optimizations...i'll give them a try either tomorrow or next week.
indeed it was sunday i suppose, does it make a difference ?
right, each character is single, transparent but unscaled blit. each balloon image are two (border and inside) transparent and scaled blits.
here is an apk: http://www.aptalkarga.com/tmp/A1.apk
center key adds a random bubble. they disappear after some seconds
you should probably need to remove old S1 or A1 before installing this.
thanks :)
It starts with 8fps and slows down to almost 0 if i keep adding bubbles. Looks like as if you are not discarding the bubbles once they moved out of the screen. However, 8 fps isn't really fast either. I'll write myself a test case to see how much this can be improved...then again, i don't expect any miracles unless i'm doing something really stupid that i haven't noticed yet. But basically, blitting is like playing an animation, i.e. it's all about pumping new vertices to the GPU each frame. That part can be optimized a little bit by using indexed geometry (which might run 10-20% faster than now), but apart from that, i don't see much room for improvement. We'll see...
You might want to try to order your blits by texture if possible. The less texture changes there are, the better. However, i don't think that this will help very much, but maybe it's worth a try anyway.
yes, out of screen condition is not checked. it wasnt necessary for desktop version. i can do it. in real life there aren't many bubbles on the fly at the same time, but it wont hurt but help for sure..
i've tried blitting all text at last. which is kind of sorting. did slightly help: ~5-10% increase
i definitely need a boost here. 10-20% even 30-40% range wont help much
- i can try to use android text utilities. i'm not sure this is possible over GL surface and even if possible i seriously doubt it will perform any better.
- instead of character blitting, i can render each bubble's text to a texture and blit it. this is what i do in desktop karga except it's java2d not blitting. this will dramatically reduce number of blits in cost of texture creation
- what else ?
You might use a modified approach of your second bullet point, by filling some pre-generated textures with the bubble texts via an ITextureEffect. That will reduce at least some of the overhead of creating new textures.
maybe. the outer part is not fixed in size, it's scaled according to inner text part.
btw, seems as texure's arent needed to be added to TextureManager for blitting. they are uploaded at first use i suppose ? how can i dispose them ?
In desktop jPCT, you can do this via the TextureManager. In AE, you can't. I guess, i somehow missed that part in the porting...i'll add it.
great :) i wasn't even aware of TextureManager.unload.. method. you must have added it while i wasnt on the scene i guess..
i would expect uploading a new texture and modifying it with a texture effect perform almost the same, right ?
Not quite. Modifying will always be cheaper, because it removes some gl overhead that the creation of a new texture will cause. It might not be that much though.
Quote from: raft
instead of character blitting, i can render each bubble's text to a texture and blit it. this is what i do in desktop karga except it's java2d not blitting. this will dramatically reduce number of blits in cost of texture creation
yeap, this doubled the performance on emulator ;D
http://www.aptalkarga.com/tmp/B1.apk
Up to 26 fps now on the phone. I'll try to improve blitting speed somewhat anyway.
Nice to see you guys working on better solutions, as always, you can ask for tests (Since that's the only help I can provide atm.)
I'm working on the project so feel free to ask.
@dl.zerocool
feel free to try the app above and paste the results ;D
Quote from: raft on March 31, 2010, 12:48:33 PMi would expect uploading a new texture and modifying it with a texture effect perform almost the same, right ?
Quote from: EgonOlsen on March 31, 2010, 12:58:02 PM
Not quite. Modifying will always be cheaper, because it removes some gl overhead that the creation of a new texture will cause. It might not be that much though.
When I was working on my "video texture" project, I found that the overhead of adding new textures was significantly more than modifying existing textures (to the point that the first option was not really an option if you want smooth video playback).
-- I haven't tested if this is still true for JPCT-AE though.
Quote from: paulscode
When I was working on my "video texture" project, I found that the overhead of adding new textures was significantly more than modifying existing textures (to the point that the first option was not really an option if you want smooth video playback).
but i suppose you were doing this every frame ? in my case this is done once per bubble. indeed every time font size changes for each bubble but on Android font size wont change
Quote from: raft on March 31, 2010, 04:25:13 PM
@dl.zerocool
feel free to try the app above and paste the results ;D
First since I don't know what your application is doing, I only see few bubbles with text.
Next, when loading it start at 40fps and then go to 60fps and stay at 60fps.
Some time after the bubbles start disappearing gently to let the black screen alone, always at 60fps of course.
And stop animation from menu does nothing.
Quote from: dl.zerocool
First since I don't know what your application is doing, I only see few bubbles with text.
ehm ;D it's an image and text blitting test application, and hence the bubbles. you can hit center key to add more bubbles. and as you noticed they disappear after some time.
QuoteNext, when loading it start at 40fps and then go to 60fps and stay at 60fps.
same thing with animation, dalvik somehow warms up, good for us :D
QuoteSome time after the bubbles start disappearing gently to let the black screen alone, always at 60fps of course.
60fps with and without bubbles, i suppose there is vsync or something which limits fps.
and nevermind the menu, "copy paste is the mother of all evil" ;D
Quote from: raft on March 31, 2010, 06:16:34 PM
ehm ;D it's an image and text blitting test application, and hence the bubbles. you can hit center key to add more bubbles. and as you noticed they disappear after some time.
Sorry I don't understand what "blitting" means, I'm living in Switzerland and my mothers tongue is French, even I also speak Portuguese, English, German(school level) :) and learning Japanese.
Quote
and nevermind the menu, "copy paste is the mother of all evil" ;D
Ahah I do know this very well...
---
"Last week we had to "play" program few small trains with train station in real. (It was to prove our understanding about threads using the pthread lib).
And I spent 45minutes why my TrainA was not doing is stops and the TrainB suddenly stop itself when it was not needed.
Each train has is own thread and I did a copy paste at start to not having to rewrite the all thing... Well it was a bad idea since i copied TrainStop(B); everywhere... on the A thread."
---
Now about A1.
If I add bubbles the fps drop under 60 fps
with 14 bubbles ~43fps
with 18 bubbles ~38fps
and as soon as they start disappearing it goes back to 60fps.
anther thing is that when you leave the application (home for exemple) then go back in, there's no more bubbles, only text appear. (same fps as with bubbles)
moving arround with the pad don't make any changes on fps. Or so few that's not visible.
Quote from: dl.zerocool
Sorry I don't understand what "blitting" means..
blitting is something like pasting 2d image or text on top of rendered scene
QuoteAnd I spent 45minutes why my TrainA was not doing is stops and the TrainB suddenly stop itself when it was not needed...
hehe, yeap such things happens all the time..
QuoteNow about A1.
thanks for the tests. did you download A1.apk B1.apk ?
Quoteanther thing is that when you leave the application (home for exemple) then go back in, there's no more bubbles, only text appear. (same fps as with bubbles)
i suppose that happens because some textures are lost when GL surface is recreated. that should be handled in a
regular application
Quote from: raft on March 31, 2010, 06:59:25 PM
QuoteNow about A1.
thanks for the tests. did you download A1.apk B1.apk ?
Thanks for the explanation.
I downloaded B1.apk, but the software name is A1, sorry for the confusion.
Quote from: paulscodethe overhead of adding new textures was significantly more than modifying existing textures (to the point that the first option was not really an option if you want smooth video playback).
Quote from: raft on March 31, 2010, 05:12:10 PMbut i suppose you were doing this every frame ? in my case this is done once per bubble. indeed every time font size changes for each bubble but on Android font size wont change
Even still, the texture effect is a better option, because you will experience a 50-200 millisecond pause each time you add a texture, which players will notice as "hiccups" in the rendering, especially if several bubbles pop up around the same time.
i guess you are right as a rule of thumb but somehow texture creation is not noticable on this thing. not on emulator and not an actual device. possibly because the created text textures are very small in size. closest 2^n x 2^m to what you see on screen.
The class's look really handy.
I'm working on a AR Browser and need on-the-fly generated text bubbles, so this seems appropriate.
One thing; What license do you consider this under? Though we are developing a free, open source, browser ourself (http://arwave.org/), we want people to be able to re-use and adapt our code for their own projects, even if their commercial. So we need to know any code we use if allowed for that :P
you can do anything with it ;)
Thats fantastic, cheers :)
Nice classes, but I wonder. Did somebody use GLFont.getStringBounds(String s)? May be I downloaded older version of this class. But there is simple error. This method GLFont.getStringBounds(String s) doesn't work, it always returns width = 0. This is happening because of charWidths[] array isn't filled on setting Paint.
Just pointing on this simple copy/paste error ;)
I think i used this for Alien Runner and had the same problem. IIRC, raft fixed it back then. I just can't remember if i got that version from him or if he updated the download...
which version is it? android or desktop?
It is android version. I got it from first post in this topic.
i've updated the links. please re-download
Is there any example source for texture pack.
Quote from: jt123 on March 23, 2013, 01:50:16 PM
Is there any example source for texture pack.
you can have a look at bones demo to see sample usage
http://aptalkarga.com/bones/ (http://aptalkarga.com/bones/)
Thanks i forget to use pack(). Now it works.
hi all,
want to ask about blitting the text. is there anyway to blit text vertically? thanks
not directly. you need the modify the code.