SFML community forums
Help => Graphics => Topic started by: dixondean25 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.
-
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.
-
All i want to do is clear a texture without using loadFromImage().
-
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 :-)
-
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?
-
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?
-
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.
-
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?