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

Author Topic: Clear or reset a texture?  (Read 4489 times)

0 Members and 2 Guests are viewing this topic.

dixondean25

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Clear or reset a texture?
« on: March 27, 2014, 08:42:24 pm »
I'm having issues with textures. I want to use a group of textures over and over again. This is what i'm doing.
1. Create all textures of certain size.
2. update textures from image takes up the whole texture space.
3. update textures from a different image that is smaller than the textures.
~~~~~this keeps the un-updated parts of the texture unaltered(because the new image is smaller), and the space the new image takes up update correctly.

So basically the update function doesn't clear the texture. Is there anyway to clear a texture? I tried the loadFromImage() function, but it stretches the image to fit the texture size sometimes. I don't know why it does that, but it looks very weird.

Peteck

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Clear or reset a texture?
« Reply #1 on: March 27, 2014, 09:32:51 pm »
My suggestion would be to use pointers to the textures instead.
This way you wont have these problems. You simple make the pointer, point to another texture.

Correct me if im wrong. But are you loading the image everytime you need a texture for a sprite? Thats a bad way of handling assets in general. Load all the textures/assets you need for the current scene into a array of some kind, maybe a map. When the scene is done, delete those textures/assets you dont need further to free up some memory and don't get alot of garbage.

dixondean25

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: Clear or reset a texture?
« Reply #2 on: March 27, 2014, 09:55:10 pm »
All i want to do is clear a texture without using loadFromImage().

Peteck

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Clear or reset a texture?
« Reply #3 on: March 27, 2014, 10:10:17 pm »
Oh, I may have misunderstood your question :-[
Hmm. So when you update a texture with a smaller image, the old content to get cleared? Maybe leave some wierd "garbage" pixels?

If thats the case. Well I've had a similar problem with WebGL/OpenGL a year ago. Can't remember what my solution ended up beeing, but if I remember right I just created another thread and added the image to that.

Maybe the other guys have a better solution for problem :-)
« Last Edit: March 27, 2014, 10:12:46 pm by Peteck »

dixondean25

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: Clear or reset a texture?
« Reply #4 on: March 27, 2014, 10:13:27 pm »
I found a workaround that works great, but don't know if it's the best way.
If I update the textures with a completely transparent image(that is the full size of the textures) before updating to the smaller ones it works perfect. Sounds super wrong and dirty but i'll do that for now until someone gives me another idea.

also, why does loadFromImage() stretch the image to fit the size of the texture?

Peteck

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Clear or reset a texture?
« Reply #5 on: March 27, 2014, 10:26:41 pm »
Hmm. I'm not able to make some test right now. So don't if it gonna work, leave any memory leaks or something. Be when you call loadFromImage(), try to call create(unsigned int, unsigned int) with the size of the image before loadFromImage() and see if you get any stretch then?

Tuffywub

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: Clear or reset a texture?
« Reply #6 on: March 27, 2014, 11:04:50 pm »
Why do you need to update the texture with a smaller image? Can't you just create a new texture with an appropriate size? Updating a texture all the time is rather slow, compared to just using a different one.

If you do need to update with a smaller image though, then the best way to do this would be to resize the smaller image (the image file, not in sfml) with transparent pixels on the outside.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Clear or reset a texture?
« Reply #7 on: March 27, 2014, 11:31:48 pm »
Your description is quite confusing. Can you tell us precisely what you want to achieve, and not how you think to achieve it? That is, what do you eventually want to draw?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: