BetaCairo: Cairo Wrapper, 0.1 Released!

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
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58

BetaCairo: Cairo Wrapper, 0.1 Released!

Post by betajaen »

Image

Hello again! Let me show you the 3rd* of the "Beta" free libraries; "BetaCairo".

Unlike BetaGUI, BetaCairo has one dependency, the Cairo library. Now let me explain it to the uneducated. Cairo is a 2D graphics drawing library which supports bitmap and vector drawing onto an image, as well as basic image manipulation, it also includes support for SVG and many other things, and apparently it's used in Firefox 3.0 for the new canvas tag. So it's pretty nifty.

So I've just made a simple wrapper so it can directly draw onto an Ogre Texture, which can then be on an entity or in the case of of the screenshot onto an overlay ala BetaGUI. The texture then can be updated as many times as you like i.e. an analogue clock or a push button.

How the above image was created is another amazing thing:

Code: Select all

mTexture = new BetaCairo::Texture("wee", 256, 256);

mTexture->fill(Ogre::ColourValue(1.0,0.65,0.65,0.1));
mTexture->drawLine(ColourValue::Red, 10,10, 100,100);
mTexture->setLineThickness(2);
mTexture->drawLine(ColourValue::Green, 100,10, 100,100);
mTexture->setLineThickness(3);
mTexture->drawLine(ColourValue::Blue, 10,46,100,100);

		
mTexture->drawRectangle(ColourValue(0.5,0.2,0.6,0.4), 190,20,50,30);
mTexture->drawBox(ColourValue::Black, 8,150, 100,60);
mTexture->setFont("Gill sans", 16);
mTexture->drawText("Hello Ogre3d.org!", ColourValue::White,10, 180);

mTexture->redraw();
Then used in a material:

Code: Select all

MaterialPtr material = MaterialManager::getSingleton().create( "WeeMaterial", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
material->getTechnique(0)->getPass(0)->createTextureUnitState("wee");
material->getTechnique(0)->getPass(0)->setSceneBlending(SBT_TRANSPARENT_ALPHA);
Then used in this case in a BetaGUI window:

Code: Select all

mGUI->createWindow(Vector4(128,128,256,256),"WeeMaterial", BetaGUI::NONE);


And thats just the tip of the iceberg of what Cairo can do, and hopefully in many versions to come BetaCairo can do as well.

I'll shall be releasing version 001 of the source tommorow under the same license as BetaGUI, and in the same manner.

But I'm already wondering what some crazy Ogre programmer can mix BetaGUI and BetaCairo with; Vector Overlay GUIs. Oh my ;)

Enjoy!

*BetaSound will be released once I get the kinks out of it.
Last edited by betajaen on Sun Dec 24, 2006 12:02 pm, edited 4 times in total.
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 100

Post by Wolfmanfx »

Looks really great :) & usefull...
i know cario from gtk+ :)
User avatar
joshcryer
Gnome
Posts: 351
Joined: Wed Oct 13, 2004 8:22 am

Post by joshcryer »

Wow! Excellent job! :)

I think this was done before? But I like what you've done here. Thanks for the contribution. :D
Image
User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3

Post by johnhpus »

I don't have any experience with Cairo, but just by looking at the example code you posted for drawing lines into a material I can already see this is going to be good.
User avatar
Game_Ender
Ogre Magi
Posts: 1269
Joined: Wed May 25, 2005 2:31 am
Location: Rockville, MD, USA

Post by Game_Ender »

Do you use the accelerated features of Cairo? One of its upshots is the ability to use the opengl (glitz) backend and draw directly to an opengl context (texture?). Allowing much faster rendering. There GTK2 Cairo Engine to provide prettier Linux themes.

PS. Can you use a slightly better number scheme for this than you have NxOgre. You know, something like Major.Minor.Patch. Where the first Alpha/beta release all go in 0.x.0 range. Just a request. I am very interested in looking at this under the hood.
User avatar
joshcryer
Gnome
Posts: 351
Joined: Wed Oct 13, 2004 8:22 am

Re: BetaCairo - Cairo Wrapper for drawing on to Textures!

Post by joshcryer »

betajaen wrote:But I'm already wondering what some crazy Ogre programmer can mix BetaGUI and BetaCairo with; Vector Overlay GUIs. Oh my ;)
You will be my hero if you can get this working. Seriously. InkSpace + Cairo + BetaGUI/Cairo would be so amazingly awesome. It would solve one of my biggest problems (not keen on CEGUI, and have been hacking my own for a long time now, always being put off by the task, but this would make it so much easier).

:D
Image
User avatar
Wretched_Wyx
Orc
Posts: 498
Joined: Thu Mar 16, 2006 5:27 pm

Post by Wretched_Wyx »

Holy smokes I've been in the cave too long again. BetaGUI + BetaCairo... I think I'll definitely play with this a bit. If it turns out to be easy to make vector based GUIs with this combo... Well I guess it will give me something to do that can actually pull me away from what I've been doing lately :wink:.

I've been wondering why it doesn't say "MVP" under your name... You've been rolling out some nice stuff lately, and of course the almighty NxOgre alone should be enough to earn that status. Though I guess you don't need it, we know who you are and the great additions to Ogre you've made :).

Okay enough brown nosing. Do you have any cool features for later versions of BetaCairo that you can share? Also can't wait to get my hands on BetaSound, sounds really cool.
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58

Post by betajaen »

Game_Ender wrote:Do you use the accelerated features of Cairo? One of its upshots is the ability to use the opengl (glitz) backend and draw directly to an opengl context (texture?). Allowing much faster rendering. There GTK2 Cairo Engine to provide prettier Linux themes.
I have tried, directly writing to a texture via Cairo but it comes out weird. I have the pixel formats correct, but with there is a required stride value which I cannot find anywhere related to the Ogre texture. So it comes out quite funny. So I'm just using a for loop now to copy the pixel data over, but I'm going to try again. ;)
Game_Ender wrote:PS. Can you use a slightly better number scheme for this than you have NxOgre. You know, something like Major.Minor.Patch. Where the first Alpha/beta release all go in 0.x.0 range. Just a request. I am very interested in looking at this under the hood.
NxOgre uses the same system. We just don't use patch numbers. ;)
Wretched_Wyx wrote:I've been wondering why it doesn't say "MVP" under your name......
It would be nice, but I hear their private members bar can be quite noisy sometimes. :D
Wretched_Wyx wrote:Okay enough brown nosing. Do you have any cool features for later versions of BetaCairo that you can share?
Yes! I want to get SVG working, and loading of images directly in. This alone would cover many many different possibilities of use, and even for newbies things like tachometers would be a few lines at most.


As for the BetaGUI/BetaCairo combo. SVG would be certainly the easiest way to implement it, but probably one of the slowest. But some definite fiddling is needed.

However I think I've decided (or someone has decided for me) on my project for the holiday break people! :D
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66

Post by sinbad »

Beta-tastic. :)
User avatar
SunSailor
Gnoll
Posts: 699
Joined: Sun Jan 02, 2005 5:45 pm
Location: Velbert, Germany
x 2

Post by SunSailor »

Following the rules of this forum and the Ogre-project, I'd like to propose betajaen for MVP :-).
User avatar
DaCracker
Gremlin
Posts: 192
Joined: Thu Jan 27, 2005 9:57 am
Location: Sweden

Post by DaCracker »

SunSailor wrote:Following the rules of this forum and the Ogre-project, I'd like to propose betajaen for MVP :-).
Me too :)
----------------------------------------------------
DaCracker's Common Lib:
http://sourceforge.net/projects/dacrackerslib/
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

I remember :wumpus: talking about Cairo and Ogre a lot, but never got around to it.
Kudus to you, betajaen! :)

I am, however, not going to use Beta libraries, ever! :twisted:

Just kidding... :P
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58

Post by betajaen »

jacmoe wrote:I am, however, not going to use Beta libraries, ever! :twisted:
Fine. I won't use your software either.
jacmoe wrote:Just kidding... :P
I'm not. :P
User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3

Post by johnhpus »

Hah, well maybe your anti-endorsements of one another's software are purely in jest (and maybe referring to a joke I missed in another thread) but you guys might reconsider your posts. It's confusing unless you actually don't trust the code.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

Beta, that's after Alpha, isn't it? :P
Beta and Alpha are generally what comes before an actual stable release.
Betajaen calls his libraries Beta_whatever, like BetaGUI, BetaCairo.
Pun intended - get it? :)

Anyway: I think this is generally awesome! Vector graphics and Ogre == Yummi! :D
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3

Post by Falagard »

I can't endorse Betajaen for MVH, he's clearly the devil:

Username: betajaen
Joined: 18 Jul 2005
Posts: 666
Location: Wales, UK

Maybe after he posts one more time though ;-)
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58

Post by betajaen »

I always get confused with him, I always say "Mate, you've got the wrong address!".
User avatar
paddy
Greenskin
Posts: 136
Joined: Sun Aug 01, 2004 7:07 pm

Post by paddy »

This is very good news. I had to write a very primative (ie unpolished) line/bezier drawing tool set and since decided to gut it for a quality external 2D lib, but haven't gotten around to integrating one with ogre yet.

Now I won't have to! :D
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58

Post by betajaen »

Update!

Image

There won't be a release today like I wanted, but I have some news.

BetaCario is currently in a library (BetaCario.dll) format, but if I can get the right license allow it to be directly imported into your project like BetaGUI or use it like the library. To meet the best of both worlds.

Second, there will be three sample/tutorials that are copied to your Ogre samples directory after compiling:
  • BetaCario101: "Dynamic Textures" Image above. A working clock is projected onto the cube, the hands actually move around depending on the time of day, the grid on the floor is generated by BetaCairo too.
  • BetaCario102: "BetaGUI". Using BetaCairo with BetaGUI.
  • BetaCario103: "BetaGUI and BetaCairo to the extreme". Put BetaGUI windows onto meshes and using them, just like the Doom 3 computer consoles ;)
Probably for the first time in Ogre history ever. These samples/tutorials are requires no external resources what so ever. All the meshes and images are generated for you, the boot up time is staggering. ;)
User avatar
Game_Ender
Ogre Magi
Posts: 1269
Joined: Wed May 25, 2005 2:31 am
Location: Rockville, MD, USA

Post by Game_Ender »

More technical questions. What cairo backend are you using for this? A custom Ogre backend?
User avatar
Wretched_Wyx
Orc
Posts: 498
Joined: Thu Mar 16, 2006 5:27 pm

Post by Wretched_Wyx »

That is so freakin' sweet... I can kinda tell from that shot that the generated textures are very clean, ie less jaggies than using your standard textures, and and I'm not referring to AA. Yet I still have to ask- how sharp are the textures BetaCairo is generating?

Also, does BetaCairo have built-in functionality to save the textures it generates out to file (ie png/svg)? I'm sure it wouldn't be (assumption) too hard to add that in ourselves if we needed to, just curious if it's possible out-of-the-box.

Betajaen wrote:BetaCario103: "BetaGUI and BetaCairo to the extreme". Put BetaGUI windows onto meshes and using them, just like the Doom 3 computer consoles
That just put me in an infinite loop of pants wetting.

Falagard wrote:I can't endorse Betajaen for MVP, he's clearly the devil
*Oh you have no idea... Just last week he ordered a hit on my guinea pig because I wouldn't give him any cake. I managed to get him some cake before he followed through with it... but instead he had 3 of my fingers chopped off. Makes things much harder on the coding end, I'll tell ya. I won't tell you about the time I woke up with a horse head in my bed, because I jokingly said I didn't condone the use of NxOgre.

* For the very gullible, this is a total fallacy. Though I wouldn't put it past him...
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
x 3

Post by Praetor »

Ogre already depends on libraries that load (and save?) images of all sorts of formats. I imagine if Cairo can speak some intermediate language, even it doesn't have saving functionality, it can make FreeImage do it.

And I'm sure the sharpness will still depend on the resolution of the texture you are writing it to. But in that screenshot it indeed looks very sharp.
User avatar
Wretched_Wyx
Orc
Posts: 498
Joined: Thu Mar 16, 2006 5:27 pm

Post by Wretched_Wyx »

Good point about making FreeImage save the texture out to an image. As far as the the sharpness goes... I've always known SVG to be a vector image format. And I've always known vector images to be super sharp, and in particular SVG scales very nicely. So if you made a texture at a 512x512 resolution, and then scaled it (say, with BetaCairo?) up to 1024x1024, you wouldn't have a loss of quality or any jaggies or blurring, etc.

At least I'm pretty sure that's how it works. I don't have *that* much experience with vector formats, but enough to get excited about the crazy things you could do with this.
User avatar
Game_Ender
Ogre Magi
Posts: 1269
Joined: Wed May 25, 2005 2:31 am
Location: Rockville, MD, USA

Post by Game_Ender »

Vector formats don't scale "very nicely" they scale perfectly to an infinite size. The only limitation is the size buffer you render them to. Cairo can save any cairo_surfrace_t to a png with cairo_surface_write_to_png you just need to make sure support for that was compiled in when you build cairo.

Has anyone found a good cairo + glitz tutorial?
Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
x 1

Post by Vectrex »

Well I'm not sure how OgreSWF does it, but it can draw directly to the screen, bypassing the render to texture bit. It's really fast and infinite resolution. Maybe interrogate stoneCold?