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

Author Topic: getting pixels of a texture  (Read 9182 times)

0 Members and 2 Guests are viewing this topic.

Eru

  • Newbie
  • *
  • Posts: 3
    • View Profile
getting pixels of a texture
« on: April 15, 2021, 12:52:08 pm »
Hello i am learning sfml and i wonder how can i get pixels of my texture. in my project when i write
myTexture.getSize()
it gives me 512*512. But the problem is my texture is staring from (100,100)px. I mean the rest of empty with white colors. In my condition i cant crop the empty blanks from my image.png file. So, can i pull the starting pixels of my texture/image? Is it possible?


fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: getting pixels of a texture
« Reply #1 on: April 17, 2021, 10:31:05 am »
sf::Texture::loadFromFile() also allows you to supply an sf::IntRect which defines a smaller part of the texture you want to load

https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php#loading-a-texture

You can also use sf::Sprite::setTextureRect() to display only part of a texture

https://www.sfml-dev.org/tutorials/2.5/graphics-sprite.php#ok-can-i-have-my-sprite-now