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!
User avatar
ajs15822
OGRE Expert User
OGRE Expert User
Posts: 570
Joined: Mon Jan 02, 2006 2:05 am
Location: Texas
Contact:

Canvas

Post by 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:
0 x

User avatar
NoodlesOnMyBack
Goblin
Posts: 200
Joined: Tue Feb 05, 2008 4:14 am
Location: Buenos Aires, Argentina
Contact:

Post by 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!
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7134
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Post by Kojack » Tue May 13, 2008 6:19 am

hehe, that atlas texture looks almost artistic. :)

Sounds cool.
0 x

User avatar
Jerky
Orc Shaman
Posts: 791
Joined: Wed Mar 02, 2005 4:13 am
Location: Springville, Utah
Contact:

Post by Jerky » Tue May 13, 2008 6:33 am

Very nicely done. Looks fantastic, and the performance is amazing.
0 x
Erik Briggs (Jerky)
My Blog
Project Wish
Image

User avatar
lf3thn4d
Orc
Posts: 478
Joined: Mon Apr 10, 2006 9:12 pm

Post by 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 :)
0 x

User avatar
AshMcConnell
Silver Sponsor
Silver Sponsor
Posts: 591
Joined: Fri Dec 14, 2007 11:44 am
Location: Northern Ireland
Contact:

Post by 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!)
0 x

User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
Contact:

Post by betajaen » Tue May 13, 2008 12:42 pm

Oh my.

I have to use this in something.
0 x

pratty70
Gnome
Posts: 341
Joined: Thu May 13, 2004 4:52 pm
Location: Wales - UK

Post by 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.
0 x

ValentinGalea
Halfling
Posts: 45
Joined: Mon Apr 23, 2007 1:01 pm
Contact:

Post by ValentinGalea » Tue May 13, 2008 1:58 pm

I for one, welcome our new overlord Atlas!
0 x

User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
Contact:

Post by Praetor » Tue May 13, 2008 3:40 pm

Very awesome.
0 x

User avatar
ajs15822
OGRE Expert User
OGRE Expert User
Posts: 570
Joined: Mon Jan 02, 2006 2:05 am
Location: Texas
Contact:

Post by 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.
0 x

User avatar
Kentamanos
Minaton
Posts: 980
Joined: Sat Aug 07, 2004 12:08 am
Location: Dallas, TX

Post by Kentamanos » Tue May 13, 2008 5:35 pm

Nicely done :).
0 x

User avatar
Frenetic
Bugbear
Posts: 806
Joined: Fri Feb 03, 2006 7:08 am

Post by 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
0 x

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19261
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
Contact:

Post by sinbad » Tue May 13, 2008 6:43 pm

Very nice work indeed. Thanks for sharing!
0 x

User avatar
Frenetic
Bugbear
Posts: 806
Joined: Fri Feb 03, 2006 7:08 am

Post by 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... ;)
0 x

User avatar
detox
Greenskin
Posts: 103
Joined: Thu Sep 07, 2006 1:13 am
Location: Ohio, USA
Contact:

Post by detox » Tue May 13, 2008 8:12 pm

thank you for sharing the source. I will definitely be using this.
0 x

User avatar
metaldev
Orc Shaman
Posts: 761
Joined: Thu Mar 17, 2005 11:56 pm
Location: Boston
Contact:

Post by 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.
0 x

pratty70
Gnome
Posts: 341
Joined: Thu May 13, 2004 4:52 pm
Location: Wales - UK

Post by 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!
0 x

User avatar
neocryptek
Gnome
Posts: 335
Joined: Sat Mar 01, 2003 11:21 pm
Location: Idaho, USA
Contact:

Post by 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!
0 x

User avatar
Fuinelen
Halfling
Posts: 86
Joined: Thu Mar 31, 2005 7:42 am
Location: Martinique
Contact:

Linux port

Post by 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?
0 x

User avatar
scriptkid
Bronze Sponsor
Bronze Sponsor
Posts: 88
Joined: Fri Jun 25, 2004 8:16 pm
Location: The Hague, Netherlands
Contact:

Post by 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 :)
0 x
Check out my released 3D snake game using Ogre!

Lord LoriK
Goblin
Posts: 254
Joined: Tue Feb 13, 2007 5:33 am

Post by 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.
0 x


gamedboy
Gremlin
Posts: 168
Joined: Wed Sep 19, 2007 1:19 pm
Location: singapore

Post by gamedboy » Wed May 14, 2008 3:54 pm

This is very cool, Great Job!
0 x

User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: Princeton, New Jersey, USA
Contact:

Post by 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?
0 x

Post Reply