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

Author Topic: Image Deformation in SFML  (Read 11375 times)

0 Members and 1 Guest are viewing this topic.

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Image Deformation in SFML
« on: October 20, 2012, 02:38:13 am »
Say I want to take an image that is a straight line with colors effects and whatnot, does SFML allow me to deform that image into a shape? I want to make a laser that bends as it moves using only one image, so I was wondering if this was possible as I had never seen it before in SFML.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Image Deformation in SFML
« Reply #1 on: October 20, 2012, 09:04:47 am »
You can map a texture on any geometry. You can create any geometry with a vertex array. So, yes ;)
Laurent Gomila - SFML developer

Haikarainen

  • Guest
Re: Image Deformation in SFML
« Reply #2 on: October 20, 2012, 03:01:26 pm »
Say I want to take an image that is a straight line with colors effects and whatnot, does SFML allow me to deform that image into a shape? I want to make a laser that bends as it moves using only one image, so I was wondering if this was possible as I had never seen it before in SFML.

Doing this in realtime using sf::Image would probably be very slow. Do it using a rendertexture and shaders instead. Or better yet calculate the laser path and draw it using sf::Shape(and perhaps apply a shader to make it more.. lasery..)

For "true" image deformation (think skew, perspective etc in photoshop), bind your texture to a quad(sf::Shape or even better pure opengl since youll also get depth) or whatnot which you draw to a rendertexture. That way you can save the rendertexture to an image or do whatever you wish with it.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Image Deformation in SFML
« Reply #3 on: October 20, 2012, 06:35:25 pm »
Take a texture of straight laser beam and map it onto a triangle strip to get bending line? Or fan to get circle.
Back to C++ gamedev with SFML in May 2023

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Image Deformation in SFML
« Reply #4 on: October 20, 2012, 07:18:16 pm »
Can you please give me a code example of how to do it? I was also thinking on making it bend in curves. I'll post a youtube example of what I mean with this: http://www.youtube.com/watch?v=SunCHEC2Q0E

in minute 2:30 you can see the kind of effect I want to reproduce.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Image Deformation in SFML
« Reply #5 on: October 20, 2012, 07:38:34 pm »
Quote
Can you please give me a code example of how to do it?
Don't you want to try yourself first? ;)
Laurent Gomila - SFML developer

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Image Deformation in SFML
« Reply #6 on: October 20, 2012, 07:58:01 pm »
I would if I had the slightest idea of how to start. I've never used textures in anything other than simply setting a texture based on an image, so I have no idea how to start that's the reason I didn't give any code for starters.

For example this:
Quote
Take a texture of straight laser beam and map it onto a triangle strip to get bending line? Or fan to get circle.

Sounds simple enough, but I don't have the slightest clue of how to bring the explanation to practice, I'm still new to game programming.
« Last Edit: October 20, 2012, 08:35:14 pm by masskiller »
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Image Deformation in SFML
« Reply #7 on: October 20, 2012, 08:39:43 pm »
It's quite hard, yes. Try playing with this, it's interesting enough that I might try come up with a class to do that instead in the next week when I'm bored during C lecture.
int main(int argc,char * argv[])
{
        int i=0;
        sf::Vector2f coords[2];

        coords[1]=sf::Vector2f(0.f,64.f);
        coords[0]=sf::Vector2f(64.f,64.f);
       
        sf::Texture one;
        one.setSmooth(true);
        one.loadFromFile("laser.tga");
        sf::VertexArray arr(sf::TrianglesStrip);
        arr.append(sf::Vertex(sf::Vector2f(0.f,0.f),sf::Vector2f(0.f,0.f)));
        sf::RenderWindow app(sf::VideoMode(600,600),"aha");
        while(1)
        {
                sf::Event eve;
                while(app.pollEvent(eve))
                {
                        if(eve.type==sf::Event::MouseButtonPressed)
                        {
                                ++i;
                                arr.append(sf::Vertex(app.convertCoords(sf::Vector2i(eve.mouseButton.x,eve.mouseButton.y)),coords[i%2]));
                        }
                }
                app.clear();
                app.draw(arr,&one);
                app.display();
        }

       
}

Quote
For example this:
Quote

    Take a texture of straight laser beam and map it onto a triangle strip to get bending line? Or fan to get circle.


Sounds simple enough, but I don't have the slightest clue of how to bring the explanation to practice, I'm still new to game programming.
Me too. :)
But this is quite logical conclusion, since everything in video card is made of triangles, and sfml let's you set each triangle's position and texture mapping..
« Last Edit: October 20, 2012, 09:01:13 pm by FRex »
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Image Deformation in SFML
« Reply #8 on: October 20, 2012, 11:24:44 pm »
Quote
I would if I had the slightest idea of how to start
The online documentation (until tutorials are written), under "Texture" and "VertexArray" ;)
Laurent Gomila - SFML developer

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Image Deformation in SFML
« Reply #9 on: October 20, 2012, 11:43:26 pm »
After playing around with FRex's code I comprehend a bit on how to do it for shapes. I can't just yet figure how to do it with curves, but I'll probably do that later since I don't need it right away (in fact neither did the shaping of a laser in general, I just had a bad set of priorities), I'll probably need it later, but at least now I understand a bit how to handle VertexArrays which I had no clue at all. Thanks for the help so far.

Quote
The online documentation (until tutorials are written), under "Texture" and "VertexArray" ;)

Guess where I am now   ;D

btw, regarding tutorials, Is there an estimate date for them to be done or is "when it's done" the current answer?
 
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Image Deformation in SFML
« Reply #10 on: October 21, 2012, 12:11:45 am »
Not promissing anything but a class to do that* might happen withing next week since I have lots of time I sit around do nothing. ;D

* that = map a texture onto a cuve nicely so it looks like it's a bending line of something
Back to C++ gamedev with SFML in May 2023

Contadotempo

  • Full Member
  • ***
  • Posts: 167
  • Firelink Shrine
    • View Profile
Re: Image Deformation in SFML
« Reply #11 on: October 21, 2012, 01:23:24 am »
There's this class on the wiki:
http://www.sfml-dev.org/wiki/en/sources/stroke

Although I haven't tested it myself it might give you what you're looking for (check the demonstration video). It was written by Spiddy, who is also working on a SHMUP I believe.
« Last Edit: October 21, 2012, 01:25:36 am by Contadotempo »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Image Deformation in SFML
« Reply #12 on: October 21, 2012, 09:48:18 am »
Quote
btw, regarding tutorials, Is there an estimate date for them to be done or is "when it's done" the current answer?
Always the same answer... sorry :D
Laurent Gomila - SFML developer

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Image Deformation in SFML
« Reply #13 on: October 21, 2012, 11:42:02 pm »
There's this class on the wiki:
http://www.sfml-dev.org/wiki/en/sources/stroke

Although I haven't tested it myself it might give you what you're looking for (check the demonstration video). It was written by Spiddy, who is also working on a SHMUP I believe.

This class looks amazing, too bad I can't download anything due to it being hosted in megaupload. Though it's not exactly what (though it holds the functionality to do so) I want it's bound to give me ideas if I could look at the code.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Image Deformation in SFML
« Reply #14 on: October 22, 2012, 02:47:26 am »
The .cpp and .h of class are on the site, just the demo project isn't. ;)
Back to C++ gamedev with SFML in May 2023

 

anything