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

Author Topic: how to make clipping of images/text?  (Read 4612 times)

0 Members and 1 Guest are viewing this topic.

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
how to make clipping of images/text?
« on: August 18, 2011, 12:00:27 pm »
I want to create a control with image buttons as many web pages have nowadays - a chain of sliding images. But how can I clip them on sides - so do not appear outside of the control area?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
how to make clipping of images/text?
« Reply #1 on: August 19, 2011, 01:04:49 pm »
Draw only the sub-rectangles you need, and only where you want them to be located... Or do I miss something?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
how to make clipping of images/text?
« Reply #2 on: August 19, 2011, 02:27:48 pm »
OpenGL Scissor regions should be the answer, if i didnt miss anything either ;D

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
how to make clipping of images/text?
« Reply #3 on: August 20, 2011, 11:58:51 am »
can your point me to something more concrete in terms of sfml? i realize that i need to draw only part of the rectangle  :)

i was thinking about using a view - any thoughts - pros/cons?

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
how to make clipping of images/text?
« Reply #4 on: August 21, 2011, 08:07:14 am »
You'd have to be more specific about the effect you're trying to achieve.

What is your sliding image control, do you mean like the central advertising space on steampowered.com?. Sort of like a window with a long horizontal sheet of images scrolling behind it?

If so then you're going in the right direction with a view, that's how I'd try to do it.

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
how to make clipping of images/text?
« Reply #5 on: August 21, 2011, 07:59:29 pm »
yes, like there. but several images are shown at once not one.

Ricky

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
    • Tejada
    • Email
how to make clipping of images/text?
« Reply #6 on: August 23, 2011, 08:37:44 pm »
Quote from: "dydya-stepa"
yes, like there. but several images are shown at once not one.

Code: [Select]

#include <SFML/Graphics.hpp>

int main(void)
{
sf::RenderWindow game(sf::VideoMode(256, 224, 32), "Game");
sf::Event event;

sf::Texture texture;
texture.LoadFromFile("myimage.png");

sf::Sprite sprite;
sprite.SetTexture(texture, false);
sprite.SetSubRect(sf::IntRect(0, 0, 16, 16));

while(game.IsOpened())
{
while(game.PollEvent(event)
{
if(event.Type==sf::Event::Closed)
game.Close();
}

game.Clear();
game.Draw(sprite);
game.Display();
}

return 0;
}


sf::Sprite::SetSubRect(sf::IntRect(Left, Top, Width, Height))
Remember this, this is the key
you can later make functions to automatically do the subrect adjustments for you and viola you have yourself animation

also I just wrote the code above from scratch if it even compiles let me know and if it helps, glad I could be useful to someone xD

edit: forgot to set the sprites texture :(
Wilt thou yet say before him that slayeth thee, I am God? but thou shalt be a man, and no God, in the hand of him that slayeth thee.

 

anything