Canvas

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!

Canvas

Postby ajs15822 » Tue May 13, 2008 4:05 am

Hey Ogre3D, it's been a while. :D I thought I'd share a little something I've been working on.

What: A super-fast, lightweight, 2D-rendering engine for Ogre3D. To be used for powering simple HUDs or basic interface libraries.

Why: Existing solutions seemed a bit inefficient and I felt like tackling the issue. My implementation is able to batch all rendering into one operation, regardless of document complexity, without using any real-time texture caching.

How: The secret sauce is Atlas, a programmatic texture atlas that can pack font glyphs of multiple fonts and texture assets into a single texture. Assets are pre-loaded into an Atlas, eliminating the need for material-switching in a Canvas (allowing me to get the batch count down to one).


Screenshot: (click for bigger)
Image


Here's a screenshot of the packed Atlas texture that was generated at run-time (in about 0.03s) for the demo. It contains 4 font faces and 5 font sizes (for a total of 500 glyphs) and a single texture (the logo). Please note that most of the unused space is due to POT limitations on texture-sizes. (click for bigger)
Image


The demo itself is also a work of love; everything is data-driven, it can parse "<font></font>" tags (so that you can specify inline font styles), and I also wrote a simple multi-font text-layout implementation (see TextFlowElement).

Download the demo here.


The source is LGPL, non-platform-specific (feel free to port). All you need to build is MSVC8 and the OgreSDK (the only other dependency, FreeType, is included).

Download the source here.


I'm welcome to questions, comments, and critique. :wink:

For this message the author ajs15822 has received kudos
User avatar
ajs15822
OGRE Expert User
OGRE Expert User
 
Posts: 570
Kudos: 2
Joined: 02 Jan 2006
Location: Texas

Postby NoodlesOnMyBack » Tue May 13, 2008 4:35 am

Looks really nice! And is exactly what i was looking for, as soon as i test it i'll post a better comment.
Downloading...Woohoo!
User avatar
NoodlesOnMyBack
Goblin
 
Posts: 200
Kudos: 0
Joined: 05 Feb 2008
Location: Buenos Aires, Argentina

Postby Kojack » Tue May 13, 2008 6:19 am

hehe, that atlas texture looks almost artistic. :)

Sounds cool.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
 
Posts: 6456
Kudos: 410
Joined: 25 Jan 2004
Location: Brisbane, Australia

Postby Jerky » Tue May 13, 2008 6:33 am

Very nicely done. Looks fantastic, and the performance is amazing.
Erik Briggs (Jerky)
My Blog
Project Wish
Image
User avatar
Jerky
Orc Shaman
 
Posts: 791
Kudos: 0
Joined: 02 Mar 2005
Location: Springville, Utah

Postby lf3thn4d » Tue May 13, 2008 6:33 am

Pretty neat. Looking at the atlas, it looks like bsp packing to me. Not very efficient imho, but good enough :)
User avatar
lf3thn4d
Orc
 
Posts: 478
Kudos: 12
Joined: 10 Apr 2006

Postby AshMcConnell » Tue May 13, 2008 12:25 pm

Fantastic, this will help me quite a bit for making a HUD. Thanks!

Is it suitable for quickly changing stuff (e.g. Laptime / Speed / RPM etc?)

Thanks again!
Ash

PS. Just tested the demo and it ran at ~5000fps (yes FIVE thousand!)
User avatar
AshMcConnell
Orc
 
Posts: 450
Kudos: 6
Joined: 14 Dec 2007
Location: Northern Ireland

Postby betajaen » Tue May 13, 2008 12:42 pm

Oh my.

I have to use this in something.
User avatar
betajaen
OGRE Moderator
OGRE Moderator
 
Posts: 3446
Kudos: 57
Joined: 18 Jul 2005
Location: Wales, UK

Postby pratty70 » Tue May 13, 2008 1:44 pm

Oh my.

I have to use this in something.


ditto!

Just got to add to this - totally awesome - what superb performance!! Nice job.
Last edited by pratty70 on Tue May 13, 2008 2:02 pm, edited 1 time in total.
pratty70
Gnome
 
Posts: 394
Kudos: 0
Joined: 13 May 2004
Location: Wales - UK

Postby ValentinGalea » Tue May 13, 2008 1:58 pm

I for one, welcome our new overlord Atlas!
ValentinGalea
Halfling
 
Posts: 45
Kudos: 0
Joined: 23 Apr 2007

Postby Praetor » Tue May 13, 2008 3:40 pm

Very awesome.
User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
 
Posts: 3335
Kudos: 3
Joined: 21 Jun 2005
Location: Rochester, New York, US

Postby ajs15822 » Tue May 13, 2008 5:18 pm

Kojack wrote:hehe, that atlas texture looks almost artistic. :)


Heh, you're right-- it looks like an experiment in typography. :P

lf3thn4d wrote:Pretty neat. Looking at the atlas, it looks like bsp packing to me. Not very efficient imho, but good enough


Yup, the packing algo is binary space partitioning-- I needed something that could balance results with performance. If you have any suggestions for better algorithms to try, please share! :)

AshMcConnell wrote:Is it suitable for quickly changing stuff


Absolutely, it was designed for frequent geometry updates.

Similar to Ogre's BillboardSet, Canvas keeps a pool of quads around and resizes the index/vertex buffers only when it needs to. Confining the rendering to indexed quads allows us to decrease the number of vertices required (speeding up vertex buffer updates) and also to optimize index buffer updates (it is only updated during buffer resize).

AshMcConnell wrote:PS. Just tested the demo and it ran at ~5000fps (yes FIVE thousand!)


Hawt :P

ValentinGalea wrote:I for one, welcome our new overlord Atlas!


Rofl.
User avatar
ajs15822
OGRE Expert User
OGRE Expert User
 
Posts: 570
Kudos: 2
Joined: 02 Jan 2006
Location: Texas

Postby Kentamanos » Tue May 13, 2008 5:35 pm

Nicely done :).
User avatar
Kentamanos
Gargoyle
 
Posts: 1038
Kudos: 0
Joined: 07 Aug 2004
Location: Dallas, TX

Postby Frenetic » Tue May 13, 2008 6:17 pm

I downloaded it and gave it a quick look, and I must say, holy shit, this looks excellent! Elegant, well documented... This might save me a lot of time...

Thank you, thank you! :D
User avatar
Frenetic
Bugbear
 
Posts: 806
Kudos: 0
Joined: 03 Feb 2006

Postby sinbad » Tue May 13, 2008 6:43 pm

Very nice work indeed. Thanks for sharing!
User avatar
sinbad
OGRE Founder (Retired)
OGRE Founder (Retired)
 
Posts: 25870
Kudos: 63
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands

Postby Frenetic » Tue May 13, 2008 7:08 pm

Say, what happens when the Atlas gets too big? Looking at the source, it seems the Atlas expands infinitely, whereas I think most current cards only support 2048x2048 textures, the newer fancier ones do 4096, and older or on-board ones can only do 1024. Also, some on-board cards don't like large non-square (eg. 512x1024) textures... so a feature for general texture-size constraints, maybe an error-check or something, would be nice. And maybe the ability to "reserve()" a certain size ala std::vector.

I suppose I can use several Canvas+Atlases if I expect to be using a crap-ton of textures? I'll probably replace my own GUI-drawing code with this (improving my own code would be re-inventing the wheel now) and I have lots of fonts and text, lots of background images, lots of icons, etc. so going beyond the max texture size my card supports is almost certain.

Oh, and the fonts in my app are (supposed to be) user-customizable. Dynamically regenerating the fonts shouldn't be too hard, right? (This feature does not need real-time performance, of course)

Lastly, it bugs me that you don't use the mWhatever member-variable convention... everything else is so far above my highest standards, that this tiny issue stands out... ;)
User avatar
Frenetic
Bugbear
 
Posts: 806
Kudos: 0
Joined: 03 Feb 2006

Postby detox » Tue May 13, 2008 8:12 pm

thank you for sharing the source. I will definitely be using this.
User avatar
detox
Greenskin
 
Posts: 103
Kudos: 0
Joined: 07 Sep 2006
Location: Ohio, USA

Postby metaldev » Tue May 13, 2008 8:51 pm

wow if i switch from navi now i can use my own fonts ^_^


so happy :o ajs, my hero.
User avatar
metaldev
Orc Shaman
 
Posts: 761
Kudos: 12
Joined: 17 Mar 2005
Location: Boston

Postby pratty70 » Tue May 13, 2008 10:20 pm

I think this is so good - and so very useful it warrants a second reply!! Many many many thanks for this, I know it's gonna prove so useful for us!

Still keep having to run the demo to realise just how impressive this is!
pratty70
Gnome
 
Posts: 394
Kudos: 0
Joined: 13 May 2004
Location: Wales - UK

Postby neocryptek » Wed May 14, 2008 2:20 am

betajaen wrote:Oh my.

I have to use this in something.

Ditto...

Thanks a lot for sharing!
User avatar
neocryptek
Orc
 
Posts: 473
Kudos: 0
Joined: 01 Mar 2003
Location: Idaho, USA

Linux port

Postby Fuinelen » Wed May 14, 2008 5:07 am

First of all, thanks a lot for sharing :)

I'm trying to port it to linux right now (using code::blocks) and I got so far as to only receive this lonely error :

Code: Select all
Canvas - May 12th 2008/Canvas/Source/Atlas.cpp||In member function ‘void Atlas::pack(ComputationVector&)’:|
Canvas - May 12th 2008/Canvas/Source/Atlas.cpp|385|error: no matching function for call to ‘sort(__gnu_cxx::__normal_iterator<ComputationRect**, std::vector<ComputationRect*, std::allocator<ComputationRect*> > >, __gnu_cxx::__normal_iterator<ComputationRect**, std::vector<ComputationRect*, std::allocator<ComputationRect*> > >, Atlas::pack(ComputationVector&)::compare)’|


any ideas what I missed?
User avatar
Fuinelen
Halfling
 
Posts: 86
Kudos: 0
Joined: 31 Mar 2005
Location: Martinique

Postby scriptkid » Wed May 14, 2008 11:49 am

Hey there,

looks nice :) I browsed through the code and liked your apprauch of using states for painting formatted text.

As you mention, you wrote it to power simple HUD elements. Does that mean that users should combine your system with a more full-blown system in order to create an options screen or an inventory, for example? Or are you going to add more widget types?

Good luck anyway :)
Check out my released 3D snake game using Ogre!
User avatar
scriptkid
Bronze Sponsor
Bronze Sponsor
 
Posts: 133
Kudos: 0
Joined: 25 Jun 2004
Location: The Hague, Netherlands

Postby Lord LoriK » Wed May 14, 2008 12:44 pm

Wow, ajs15822! Very good job. Well done, as always.

Suggestions:
* I think quite a lot of the "demo" source should go into the main library. The Document, Element, ImageElement, Parser and TextFlowElement feel like "core" classes, IMO.

* Add text justification to TextFlowElement.

* Add serialization support. Creating an editor with that would be a piece of cake.

* Multitexture support. Even if this increases the batch count, is the only way to provide nearly limitless flexibility.

* AnimatedImageElement. 'Nuff said.

* Primitive drawing: point, line, circle, square, polyline. Maybe a fill function, too.

I had to reinstall my system a few days ago, but if I manage to set my development environment soon enough, I'll gladly help with these.
Lord LoriK
Goblin
 
Posts: 254
Kudos: 0
Joined: 13 Feb 2007


Postby gamedboy » Wed May 14, 2008 3:54 pm

This is very cool, Great Job!
gamedboy
Gremlin
 
Posts: 168
Kudos: 3
Joined: 19 Sep 2007
Location: singapore

Postby nikki » Wed May 14, 2008 4:55 pm

Wonderful stuff there! But don't you think some of the things in the demo should actually be part of the library itself? Or is your library supposed to be confined to just image loading only?
User avatar
nikki
Old One
 
Posts: 2730
Kudos: 12
Joined: 17 Sep 2005
Location: Princeton, New Jersey, USA

Next

Return to Showcase

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 1 guest