SDL_RenderCopy weird bug |
samleo
|
This function have a weird bug. My code is totally normal, without any error, because the same code runs on SDL1.2 and don't shows any weird bug. This bug only occurs on SDL2 when I do the follow:
-resize the game window to any size -maximize the game window Here the image: Changing the render scale quality to nearest the bug seems reduce, but not ends. If you would like to see the bug download my game http://sourceforge.net/projects/dangeroustux/, compile and run it. Please compile with: to Linux: make DangerousTux.SDL2 to windows just run make -f Makefile.mingw from cmd or compile with the cmake |
|||||||||||
|
Re: SDL_RenderCopy weird bug |
AlexRou
|
Yeah it looks like a scaling bug, you can either use OpenGL directly and make your own renderer or you can try rendering to a fixed size texture then show that and see if it scales right.
|
|||||||||||||
|
mr_tawan
|
Have you tried remove the following code ? :
|
|||||||||||||
|
Re: SDL_RenderCopy weird bug |
samleo
|
Yes, I tried. But the bug persist, just a little visible.
And how I do that? Sorry, I'm new to SDL2. |
|||||||||||||||||
|
Re: SDL_RenderCopy weird bug |
AlexRou
|
First create a texture
https://wiki.libsdl.org/SDL_CreateTexture?highlight=%28%5CbCategoryRender%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruct%29 Then set the render target to the texture https://wiki.libsdl.org/SDL_SetRenderTarget?highlight=%28%5CbCategoryRender%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruct%29 Then you draw stuff as normal, set the target to NULL then draw the texture you created. NOTE: Untested If you want to make your own renderer you gota go learn OpenGL, here is some starting codes
|
|||||||||||||||||||||||||||
|
SDL_RenderCopy weird bug |
Leonardo
|
If your tilemap is not going to change a lot, you could create a surface, blit all your tiles and then create a texture from it:
  SDL_Surface * tileset; /* your tileset  as a surface */   SDL_Surface * target; /* the target surface to blit tiles */   SDL_Texture * result; /* the resulting texture */   target = SDL_CreateRGBSurface(0, tilemap_width_in_pixels, tilemap_height_in_pixels, 32, tileset->format->Rmask, tileset->format->Gmask, tileset->format->Bmask, tileset->format->Amask);    /*    * blit all your tiles from the tileset using SDL_BlitSurface    */   /* create a single texture from that surface */   result = SDL_CreateTextureFromSurface(renderer, target);   SDL_FreeSurface(target); You do that once for each map on initialization and use SDL_RenderCopy to render a single texture each frame, which is much faster. Don't do this if your map changes too much. 2014-06-14 10:52 GMT-03:00 AlexRou:
|
|||||||||||||
|
mr_tawan
|
Hi @samleo
I don't know if you have already sort this out or not. Today I've tried compiling your code and it looks pretty good on my end. Glxinfo :
|
|||||||||||||
|
AlexRou
|
It only happens when the screen size changed
|
|||||||||||||||
|
SDL_RenderCopy weird bug |
Juan Manuel Borges Caño
Guest
|
If any bug on SDL basic 2D drawing is just adviced to use your own GL renderer, hence don't expect we give a thing, I'd consider just start moving ... GL, EGL, AL and libinput anyway. as in what value adds... Console Framebuffer, SVGAlib, ... :-)
|
|||||||||||
|
SDL_RenderCopy weird bug |
Juan Manuel Borges Caño
Guest
|
Oh, and there is that thing about reload your assets on window resize, most fast advice being don't allow in live window resizing, cause gl context gets resetted, don't ask me why or what.
|
|||||||||||
|
SDL_RenderCopy weird bug |
Leonardo
|
2014-06-15 6:50 GMT-03:00 Juan Manuel Borges Caño:
I beg to differ, as any bug on SDL drawing should be fixed, not ignored. I *do* give a thing for problems that people are facing as can be the same problems I might have in the future. There's a large portion of good software written upon SDL. Maybe its renderer its not as good as your own, but thats no reason to leave it, it is reason to improve it. Â
|
|||||||||||||||
|
Re: SDL_RenderCopy weird bug |
samleo
|
Ok I tried the first solution and not work, the bug persist. The second I going not to try because I don't know programming on OpenGL. The tileset changes constantly, because it have animated tiles, and I don't can render to a Surface. I would like that bug was solved, so PLEASE someone fix this. |
|||||||||||||
|
SDL_RenderCopy weird bug |
Leonardo
|
2014-06-15 11:16 GMT-03:00 samleo:
Its not how things happen in open source software. You might want to learn the skills necessary to fix this yourself. This bugs does not affects me. You might also want to report this bug in https://bugzilla.libsdl.org, you'll have more chances of finding people interested in fixing bugs there. Could you provide a smaller example demonstrating and isolating the bug? That would make it easier to analyze and to produce a fix. Also, if you have only some tiles changing, you can draw static ones in the surface and animated ones on top of it. Rendering every tile every frame is already a very bad idea and very cpu and gpu intensive, added to the fact that you are scaling every single tile in each rendercopy. Why do you allow window resizing? I know only one or two games that allow window resizing on the fly, and only one that is tile-based and their solution was to show more or less tiles depending on the aspect ratio, not scale them. Â
|
|||||||||||||||
|
SDL_RenderCopy weird bug |
Leonardo
|
This is topic is not new apparently. See this thread https://forums.libsdl.org/viewtopic.php?p=39136&sid=02da27cc1daab72dbdd92d1d77afeebb for a larger discussion on the subject of tile seams.
Also you might want to try SDL_gpu which, according to that thread, can do what you want:Â https://code.google.com/p/sdl-gpu/ 2014-06-15 11:31 GMT-03:00 Leonardo Guilherme:
|
|||||||||||||||||
|
Re: SDL_RenderCopy weird bug |
samleo
|
Ok, I'll use the bugzilla. The first thing that I tried was fix the bug by myself, but it's very difficult to me because I don't know basic of the SDL2 code. Well, no resizing it's a good idea, at least it's the minimum to do. Thanks to all for reply |
|||||||||||||||||
|
Re: SDL_RenderCopy weird bug |
samleo
|
Ok, it seems good. On that thread it's like my problem but without solution yet. I guess that I'll use the SDL1.2 on entire game versions, just for windows was SDL2, or use SDL2 with no resizable window. |
|||||||||||||
|
mr_tawan
|
Well, I think it's not really a bug, but it is the way hw-accelerated works.
When using 3d hw to render things, the gpu sample the texel data from texture to render. If there's any scaling needed, especially when the target object is larger than the actual area of texture used, gpu needs to resample the texture data. The problem is the texture is resampled as a whole, so it takes the nearby texel into consideration. In contrast, most 2d sprite engine crop the image before doing resampling, thus the there is not nebouring pixel being used. I've looked at your sprite image, the sprite being issues are place adjectly without any gaps in-between. This caused the resampling algorithm takes the nearby sprite's texel value into its pipeline, caused a jarring pixel rendered. I'd recommend putting 1-pixel gap between every sprite you're using. Another way is to render into a texture with fixed size, then render that texture into the screen. That should take care of any resampling problem. |
|||||||||||
|
mr_tawan
|
I have been thinking about SDL_RenderSetLogicalSize() for a while. May be its proper behavior is to do the post-processing (render everything in logical size space, then scale it to match the real window size), rather than to scale each object when it's rendered on the screen. This should solve artifacts problem in the case that no scaling involed with each object (I mean, every object is rendered at it size in logical size space).
Scaling at the render time also cause the edge of the object contains artifact even if there a gaps between objects, except that the gap contain exact copy of the edge of the object. That would makes 2 gaps between object, or 1 pixel-border on every object in other words. Ps. I'm not really sure if I have expressed clearly enough or not. Admitted that English is not my first language, sorry about that. |
|||||||||||
|
samleo
|
Sorry to AlexRou, the code with the first solution works well. mr_tawan, does it's normal lose quality on resizing the window? The bug, for that I see, was something related to get the source from image, so this is too related to scaling? Sorry for all, I write just few lines because my English it's not so good I'm brazilian huehuehue |
|||||||||||||
|
SDL_RenderCopy weird bug |
Sam Lantinga
|
Yeah, this is a fundamental problem with the current implementation of SDL_RenderSetLogicalSize(), as it doesn't handle scaling very well (e.g. seams, lines the wrong width, etc.)
We're seriously considering reimplementing it in terms of a render to texture implementation, which takes more memory but solves all of these issues. On Sun, Jun 15, 2014 at 11:31 AM, mr_tawan wrote:
|
|||||||||||||
|
Re: SDL_RenderCopy weird bug |
mr_tawan
|
Actually I'm pretty interested in this topic. I went on checking out the code to see what can I do. Although it might not be so hard to implement the functionality (which involved with using a render target and performing screen-space coordinate transformation on mouse input) at the application level, it does look complicated to implement at the library and/or API level.
Just my 2 cents. :-)
|
|||||||||||||||
|
Re: SDL_RenderCopy weird bug |
tjpalmer
|
Hello! First post here.
I have a single 320x200 texture that I draw scaled with SDL_RenderCopy, and I still get pixel artifacts within the scaled image. Look between the middle rows of these bricks: Is this to be expected? And what's the best workaround? Currently, I'm imagining either (1) render a higher-pixel texture manually or (2) learn deep GL voodoo (including pixel shaders). I'm pretty sure the first would work, but it would get more CPU intensive. I know very little GL, so that's a steep learning curve, and I'd presumably still have lots of ropes to learn. Thanks much for any advice. I posted in this topic, because it seems related, although I'm not rendering multiple tiles here, just one 320x200 texture with tile-looking things inside it. |
|||||||||||
|