Welcome, Guest. Please login or register. Did you miss your activation email?

Poll

Is this a waste of time/space/memory?

Yes, but could be worth it
1 (20%)
Yes
1 (20%)
No
3 (60%)
No, but it looks pretty useless anyway
0 (0%)

Total Members Voted: 5

Voting closed: May 23, 2010, 11:19:27 pm

Author Topic: CairoShapes with SFML  (Read 6066 times)

0 Members and 1 Guest are viewing this topic.

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
CairoShapes with SFML
« on: May 23, 2010, 11:19:27 pm »
I've written a really basic class for drawing stuff with Cairo and then using it as a normal sprite in SFML and I call the project CairoShape. I think it would be possible to actually use it in a practical application but my main intention is to create placeholder graphics when I'm playing with SFML.

The Shape class in SFML has its positive sides but I don't feel like I have the freedom sometimes.

If you find it in anyway useful please improve on it.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
CairoShapes with SFML
« Reply #1 on: May 24, 2010, 01:17:14 am »
Could you tell us a little bit more about CairoShape? What is it conceived for? What are the differences between it and sf::Shape? Which features does it provide?

It would be nice to learn more about your project, at the moment I have no idea. And a description in words is much better than one in code... ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
CairoShapes with SFML
« Reply #2 on: May 24, 2010, 01:42:11 am »
I guess he's using the Cairo 2D graphics library to draw shapes into an image buffer, thus providing it to SFML.

I like the idea, as it moves a bit forward in the vectorized graphics direction. However, an "SVG load plug-in" would be still great. Simple reason: SVG is rather popular and a lot of editing tools exist.

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
CairoShapes with SFML
« Reply #3 on: May 24, 2010, 07:11:41 am »
Quote from: "Nexus"
Could you tell us a little bit more about CairoShape? What is it conceived for? What are the differences between it and sf::Shape? Which features does it provide?

It would be nice to learn more about your project, at the moment I have no idea. And a description in words is much better than one in code... ;)


It works similar to a sprite but instead of supplying it with an image you give it a function like this one:
Code: [Select]
void CairoShape::DefaultDrawFunc(cairo_t *cr, float Width, float Height)
{
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 1.0);
cairo_rectangle(cr, 0, 0, 1.0, 0.33);
cairo_fill(cr);
cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 1.0);
cairo_rectangle(cr, 0, 0.33, 1.0, 0.66);
cairo_fill(cr);
cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 1.0);
cairo_rectangle(cr, 0, 0.66, 1.0, 1.0);
cairo_fill(cr);
// This cairo_set_source_rgba call is just to have a different color on each redraw of the image.
cairo_set_source_rgba(cr, (rand()%255)/255.0,(rand()%255)/255.0,(rand()%255)/255.0,0.75);
cairo_rectangle(cr, 0.1, 0.1, 0.8, 0.8);
cairo_set_line_width(cr, 0.05);
cairo_stroke(cr);
}
 

Then the CairoShape class will handle redrawing on resize mainly. It would probably be most convinient when you wish to draw gradients, lots of alpha or svg. As far as features go it doesn't have much, all my work so far has gone into handeling resizing properly, but I plan on making a sf::Shape-like interface and most likely a svg-loader of some sort, but that is just sub-classing.

The reason I've made this class at all is because I felt I needed it when I started working on a physics-simulator project and I knew that I wouldn't want to create alot of resources in GIMP or similar.

So far it has got some bugs, mainly dealing with scale when doing things that aren't square.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
CairoShapes with SFML
« Reply #4 on: May 25, 2010, 01:43:08 am »
So it enables loading SVG? What are the exact dependencies?

However, sounds good so far.

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
CairoShapes with SFML
« Reply #5 on: May 26, 2010, 11:49:32 am »
Quote from: "Tank"
So it enables loading SVG? What are the exact dependencies?

However, sounds good so far.


I haven't really looked into it yet but i suspect that it would require some extra libraries to load svgs but cairo is a step on the way. The dependencies so far is just cairo, later maybe librsvg or something similar.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
CairoShapes with SFML
« Reply #6 on: May 27, 2010, 05:48:46 pm »
I see, thanks. Would be nice if you keep this thread up-to-date. :)

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
CairoShapes with SFML
« Reply #7 on: May 27, 2010, 07:32:07 pm »
Quote from: "Tank"
I see, thanks. Would be nice if you keep this thread up-to-date. :)


Yeah, I will try, I'm currently rewritting it so that the cairo drawing is done with a image class instead :)

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
CairoShapes with SFML
« Reply #8 on: May 27, 2010, 09:46:06 pm »
A brand new version, it should be clearer how to use and it is less code. The main difference is that there is now automatic resizing now. http://sfml-dev.org/wiki/en/sources/cairoshape

 

anything