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

Recent Posts

Pages: 1 2 3 [4] 5 6 ... 10
31
General / Re: How can I use stbi writing functions?
« Last post by kojack on April 29, 2024, 09:20:04 am »
Basically stbi needs a single instance of some things that can't safely be done in a header. Those defines let it create the objects that it needs.
If you used the stbi headers in for example 5 cpp files, you need to do the defines in just one cpp, the other cpps would do the includes without defines. If you do the defines in more than one cpp, you'll get the multiple definition error.
32
Graphics / Re: What is the best way to animate large frames?
« Last post by eXpl0it3r on April 29, 2024, 08:38:16 am »
At what point would it make sense to use a video format instead of trying to manually create an animation of images? ;)

On one hand make sure you're measuring the "performance" in release mode.
Then to make sure you're optimizing for the right bottleneck use profiling tools to find the hot paths.

Assuming it's the reading from disk part, there isn't much you can do, as you'll have to read the image data into memory at one point.
You could perform the reading in a separate thread, so you don't block your "UI" thread, but make sure to only do this for the disk reading part (i.e. sf::Image) and not to try to do any OpenGL calls in a separate thread.
33
If you need a texture that you use for drawing in SFML and you also use for TGUI then I actually recommend loading it twice (once as sf::Texture and once as tgui::Texture), because TGUI makes no guarantees about how its texture is stored internally and whether it will be compatible with sf::Texture.

That said, you can get access to the internal SFML texture with the methods that eXpl0it3r mentioned:
const sf::Texture* pTex = &std::static_pointer_cast<tgui::BackendTextureSFML>(texture.getData()->backendTexture)->getInternalTexture();
rect.setTexture(pTex);
35
I have tgui::Textures. Would you mind explaining to me, please, how I can use the bind function, because it's not clear from the documentation?
36
Graphics / What is the best way to animate large frames?
« Last post by Me-Myself-And-I on April 29, 2024, 01:45:07 am »
I have a class called "Life" which loads each frame into a vector of images and plays it when needed. I need something that can load 960x540 frames so I surely abandoned trying to use spritesheets. This method i'm using now works but is extremely inefficient. Just using the load function causes the entire program to stop till the process of loading finishes. 10 or so frames causes a 1/2 second pause and any decent length animation of 200 frames  causes a whopping 10 to 15 second lag. Of course I can't have this. Is this method impossible? I know there must be some way to load and play the frames of an animation that is 960x540. I just don't know how.


Here is my loading code.
                DIR *dr;
               
                struct dirent *en;
               
                dr=opendir(folder.c_str());
                for(int a=1;a<2000;a++)
                {

                        if(en=readdir(dr))
                        {
                                if(en->d_name==NULL)
                                {
                                        break;
                                }
                                if(a>2)
                                {
                                        Image newimage;
                                        newimage.loadFromFile(folder+en->d_name);
                                        image.push_back(newimage);
                                }
                        }
                        else
                                break;
                               
                               
                }
                closedir(dr);
 

I'm sure its not dirent that is causing the process pause because I manually loaded each frame to test if it was dirent or not and it still halted the processing the same.

I also tried loading only portions at a time as needed by loading the next few frames as needed. This still caused a 1/2 second lag that happened every few frames.



I know that loading from files is not good on performance, since several have told me that before. So I'm looking for either a new method,or a fix to this current method. So any ideas?

I also would like to know if it  would work to load into each image one loop at a time instead of all in one for() iterator.

 
37
General / Re: How can I use stbi writing functions?
« Last post by GetterSetter on April 28, 2024, 11:31:23 pm »
Yeah, I tried it before starting the topic, and I got the error about multiple definitions of these functions because, I assume, they are already implemented in libsfml-graphics.a.
Oh, I think, I've got your idea. Do you mean that in my cpp file I should only include headers without using defines?
38
General / Re: How can I use stbi writing functions?
« Last post by kojack on April 28, 2024, 11:04:39 pm »
In one (and only one) of your cpp files that includes the stbi headers, you need to do some defines before the includes:
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
 
The first one is needed for the reading functions. The second one for the writing functions.
39
What other kind of textures do you have anyways?

Creating a texture on the fly isn't a cheap operation.
If it's an OpenGL texture, you could also just bind it, instead of creating a copy.
40
General / How can I use stbi writing functions?
« Last post by GetterSetter on April 28, 2024, 08:20:55 pm »
Hello, if I try to include stbi headers, I receive an error from the linker about multiple definition of stbi_write_.... If I try to use
extern int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
//and so on
 
I receive the following error: undefined reference to stbi_... and it doesn't matter which link order I use. So, how can I use these functions? I need to do it because I have the set of pixels itself, so I think that creating a sf::Texture, updating it with this set, then copying it to an sf::Image and finally calling saveToFile() is a bit inefficient and stupid.
RMK: I'm using static sfml libraries
Pages: 1 2 3 [4] 5 6 ... 10