Frame rate drops when moving scene |
Multicoder
|
Hello altogether,
first of all, I am kind of new to game development, so please don't beat me for making beginners mistakes Also english is not my mother-tongue. If something I write is unclear to you, please feel free to ask and I'll try to explain what I mean I have a tiled background where I add some objects (trees). (Here is a Screenshot: http://imgur.com/RaxKOrX.) I can move the scene by pressing W, A, S or D. When everything is standing still, the "Game" runs at 120 frames per second both with and without objects visible. When I move the scene without any objects visible in it (only background), the frame rate drops to 60. When showing some objects (which are moved with the scene, too) the frame rate drops down to 40 and I guess it would drop even further when I add more objects. To show the objects, I use the two methods listed below.
It would be really nice, if you could help me stabilizing the frame rate and/or optimizing my code. Best regards, Daniel |
|||||||||||||
|
Frame rate drops when moving scene |
Multicoder
|
Thank you for your reply!
Well, actually I am using SDL 2.0 (I forgot to mention that, sorry), so according to the Wiki CategoryAPI (API By Name) there is no SDL_DisplayFormat(). I think I did not describe correctly what my code does (since it's only a part of the whole program). The two methods I posted blit the images to the main surface of the map (MSurface) and another method (which I didn't mention in the first post) creates a texture from MSurface and copies it to the main renderer. I did it this way because I could not find any SDL-function in the wiki to scale a texture - now I see, I simply didn't read well enough. After reading your answer I re-read the Wiki SDL_RenderCopy() and saw a little something I did miss last time: "The texture will be stretched to fill the given rectangle." Thank you very much for pointing me in the right direction! I will try to rewrite the methods to use textures instead of surfaces. After doing so I will post an update on how the frame rate is using textures. |
|||||||||||
|
Frame rate is good now, but now I have an "invalid text |
Multicoder
|
Wow! Using textures instead of surfaces did do the trick!
The frame rate is now stable between 115 and 120 But now I have another problem because of the textures (or because of my brain). This is the method where the error occurs:
When I first start the app, everything is okay, the objects (trees) are rendered and the console window tells me
But as soon as I move the scene a bit the trees disappear and the output changes to
It seems that the texture is invalid although it clearly is not NULL, but I can't figure out why. Do you have an idea what causes the error? |
|||||||||||||||||
|
Nathaniel J Fries
|
Although the error occurs at that function, it clearly cannot be within that function.
Either the renderer's data has been lost (is possible on some systems, with certain renderers; but I would hope SDL would be smart enough to report a more specific error in that case) or the texture is invalidated by your code in some other function. And yes, scaling in surfaces is slow because surfaces use software rendering (in SDL2, you should only be using surfaces to hold image data that needs to be processed or saved for later; rendering should all be done with textures). |
|||||||||||
|
Frame rate drops when moving scene |
Gabriele Greco
Guest
|
I think the problem is that you always destroy the last texture you have allocated, usually textures are never destroyed... |
|||||||||||||
|
Re: Frame rate drops when moving scene |
Multicoder
|
That was exactly the problem. I figured it out just a few minutes before reading your post Thank you anyways! By destroying BuildTexture I destroyed the main texture of the object (because it's a pointer pointing to the main texture). The scene is only rebuilt when anything has changed (e.g. when the scene is moved), so the texture didn't exist after the initial build and the error occured when the scene tried to rebuild. I removed SDL_DestroyTexture and it works fine now. |
|||||||||||||
|