SDL_RenderCopy weird bug

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:
[Image: http://i57.tinypic.com/29nc58o.png ]

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------------------------
My project
http://sourceforge.net/projects/dangeroustux/

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.

samleo wrote:> 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:
[Image: http://i57.tinypic.com/29nc58o.png ]

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

Have you tried remove the following code ? :

Code:

SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, “linear”);

Have you tried remove the following code ? :

Code:

SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, “linear”);

On my end that does nothing mr_tawan wrote:

mr_tawan wrote:

Have you tried remove the following code ? :

Code:

SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, “linear”);

Yes, I tried. But the bug persist, just a little visible.

AlexRou wrote:

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.

And how I do that? Sorry, I’m new to SDL2.------------------------
My project

First create a texture

https://wiki.libsdl.org/SDL_CreateTexture?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)

Then set the render target to the texture

https://wiki.libsdl.org/SDL_SetRenderTarget?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)

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

Code:
#include <SDL2/SDL.h>
#include <GL/gl.h>

int main( int argc, char* args[] )
{
if( SDL_Init( SDL_INIT_EVERYTHING ) != 0 )
{
//error
}

SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 8 );
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );

SDL_Window* window = SDL_CreateWindow( “Test Window”,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800, 600,
SDL_WINDOW_OPENGL
);

SDL_GLContext GLContext = SDL_GL_CreateContext( window );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );

glViewport( 0, 0, 800, 600 );
/* change to the projection matrix and set our viewing volume. */
glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glOrtho( 0, 800, 600, 0, -1, 1 );

/* Make sure we’re chaning the model view and not the projection */
glMatrixMode( GL_MODELVIEW );

/* Reset The View */
glLoadIdentity();
glPushMatrix();

SDL_Event* event = new SDL_Event;
bool quit = false;

while( !quit )
{
while( !SDL_PollEvent( event ) )
{
if( event->type == SDL_QUIT )
quit = true;
}

  glMatrixMode( GL_MODELVIEW ); 
  glPopMatrix(); 
  glPushMatrix(); 

  glBegin( GL_TRIANGLE_STRIP ); 

  glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); 
  glVertex3f( -100, -100, 0.0f ); 
  glVertex3f( 100, -100, 0.0f ); 
  glVertex3f( -100, 100, 0.0f ); 
  glVertex3f( 100, 100, 0.0f ); 

  glEnd(); 

  SDL_GL_SwapWindow( window ); 
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 

}

SDL_Quit(); 

return 0;
}

samleo wrote:

mr_tawan wrote:

Have you tried remove the following code ? :

Code:

SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, “linear”);

Yes, I tried. But the bug persist, just a little visible.

AlexRou wrote:

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.

And how I do that? Sorry, I’m new to SDL2.

Code:

Code:

Code:

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 :> First create a texture

https://wiki.libsdl.org/SDL_CreateTexture?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)

Then set the render target to the texture

https://wiki.libsdl.org/SDL_SetRenderTarget?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)

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

Code:

#include
#include

int main( int argc, char* args[] )
{
if( SDL_Init( SDL_INIT_EVERYTHING ) != 0 )
{
//error
}

SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 2 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK,
SDL_GL_CONTEXT_PROFILE_CORE );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 8 );
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );

SDL_Window* window = SDL_CreateWindow( “Test Window”,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800, 600,
SDL_WINDOW_OPENGL
);

SDL_GLContext GLContext = SDL_GL_CreateContext( window );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );

glViewport( 0, 0, 800, 600 );
/* change to the projection matrix and set our viewing volume. */
glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glOrtho( 0, 800, 600, 0, -1, 1 );

/* Make sure we’re chaning the model view and not the projection */
glMatrixMode( GL_MODELVIEW );

/* Reset The View */
glLoadIdentity();
glPushMatrix();

SDL_Event* event = new SDL_Event;
bool quit = false;

while( !quit )
{
while( !SDL_PollEvent( event ) )
{
if( event->type == SDL_QUIT )
quit = true;
}

  glMatrixMode( GL_MODELVIEW );
  glPopMatrix();
  glPushMatrix();

  glBegin( GL_TRIANGLE_STRIP );

  glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
  glVertex3f( -100, -100, 0.0f );
  glVertex3f( 100, -100, 0.0f );
  glVertex3f( -100, 100, 0.0f );
  glVertex3f( 100, 100, 0.0f );

  glEnd();

  SDL_GL_SwapWindow( window );
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

}

SDL_Quit();

return 0;
}

samleo wrote:

mr_tawan wrote:

Have you tried remove the following code ? :

Code:

SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, “linear”);

Yes, I tried. But the bug persist, just a little visible.

AlexRou wrote:

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.

And how I do that? Sorry, I’m new to SDL2.

Code:

Code:

Code:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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.

[Image: https://googledrive.com/host/0B2Owi7msgdqDUU8xejNJMzhxY28/Screenshot%20from%202014-06-15%2014:36:53.png ]

Glxinfo :

Code:
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel® Ivybridge Mobile
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.2.1
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:

It only happens when the screen size changed

mr_tawan wrote:> 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.

[Image: https://googledrive.com/host/0B2Owi7msgdqDUU8xejNJMzhxY28/Screenshot%20from%202014-06-15%2014:36:53.png ]

Glxinfo :

Code:
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel® Ivybridge Mobile
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.2.1
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:

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, … :slight_smile:

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.

2014-06-15 6:50 GMT-03:00 Juan Manuel Borges Ca?o :

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, … :slight_smile:

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.>


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

AlexRou wrote:

First create a texture

https://wiki.libsdl.org/SDL_CreateTexture?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)

Then set the render target to the texture

https://wiki.libsdl.org/SDL_SetRenderTarget?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)

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

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.

2014-06-15 11:16 GMT-03:00 samleo <samuel.leonardo19 at gmail.com>:

AlexRou wrote:

First create a texture

https://wiki.libsdl.org/SDL_CreateTexture?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)

Then set the render target to the texture

https://wiki.libsdl.org/SDL_SetRenderTarget?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)

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

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.

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 mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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 <@Leonardo_Guilherme>
:>

2014-06-15 11:16 GMT-03:00 samleo <samuel.leonardo19 at gmail.com>:

AlexRou wrote:

First create a texture

https://wiki.libsdl.org/SDL_CreateTexture?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)

Then set the render target to the texture

https://wiki.libsdl.org/SDL_SetRenderTarget?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct)

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

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.

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 mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Leonardo wrote:

2014-06-15 11:16 GMT-03:00 samleo <@samleo (@samleo)>:

AlexRou wrote:

First create a texture

https://wiki.libsdl.org/SDL_CreateTexture?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct) (https://wiki.libsdl.org/SDL_CreateTexture?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct))

Then set the render target to the texture

https://wiki.libsdl.org/SDL_SetRenderTarget?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct) (https://wiki.libsdl.org/SDL_SetRenderTarget?highlight=(\bCategoryRender\b)|(CategoryEnum)|(CategoryStruct))

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

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.

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 (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 mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

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------------------------
My project

Leonardo wrote:

This is topic is not new apparently. See this thread https://forums.libsdl.org/viewtopic.php?p=39136&sid=02da27cc1daab72dbdd92d1d77afeebb (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/ (https://code.google.com/p/sdl-gpu/)

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.------------------------
My project

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.

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.

mr_tawan wrote:

Well, I think it’s not really a bug, but it is the way hw-accelerated works.

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.

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------------------------
My project