sdl2 copy and paste fallback renderer.

Well if you don't know, there are multiple renderers in sdl, and on some don't work on certain computers, so people use a fallback ex: "accelerated renderer -> software renderer". Sadly, I haven't came across an example that I could copy and paste.

-Pretty please can you not lecture me how to do this, and just give me code <3
Reading the documentation https://wiki.libsdl.org/SDL_CreateRenderer it would appear you could just do
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_ACCELERATED);

Pretty please can you not lecture me how to do this, and just give me code <3
This is a terrible attitude, I only posted code because your question was about how to use a very specific feature of SDL.
Last edited on
Reading the documentation https://wiki.libsdl.org/SDL_CreateRenderer it would appear you could just do
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_ACCELERATED);

Pretty please can you not lecture me how to do this, and just give me code <3
This is a terrible attitude, I only posted code because your question was about how to use a very specific feature of SDL.


Yea, but what about a complete one, using all the possible renderer's, with target texture and present sync?
Then just OR them all together using |
Ok, does it choose the best one automatically? Or does the one on a certain side is chosen first, if so, which renderers are better than the other?
I get sdl errors from your example, I guess changing the | to || fixed it...
|| is the logical or operator. It will treat both operands as bool values. Both SDL_RENDERER_SOFTWARE and SDL_RENDERER_ACCELERATED is different from zero so they will be treated as true.

 
true || true == true

The true value will be converted to the integer value 1 when it's passed to the function. The constant SDL_RENDERER_SOFTWARE is equal to 1 so that means passing SDL_RENDERER_SOFTWARE || SDL_RENDERER_ACCELERATED will have the same effect as passing just SDL_RENDERER_SOFTWARE.
Last edited on
So why won't
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_ACCELERATED);
work. It just goes strait for accelerated.
Note: my post is conjecture and I don't really know how SDL works. Take this with a grain of salt:

It doesn't make much sense to create a renderer that is both HW and SW. SDL likely favors the Accelerated option when specified and uses the Software option only if you do no specify the accelerated option.

If you want to fall back to SW if HW fails, try creating HW first... then if that fails... create a SW renderer:

1
2
3
4
5
6
7
8
9
10
11
SDL_Renderer* rend = SDL_CreateRenderer(win,-1,SDL_RENDERER_ACCELERATED);

if(!rend)
{
    rend = SDL_CreateRenderer(win,-1,SDL_RENDERER_SOFTWARE);
}

if(!rend)
{
    // could not create either HW or SW renderer -- notify user
}
It just goes strait for accelerated.
That's because your system supports accelerated. If it is not then it will fall back to software rendering. That's the point of having a fallback.
Note that the the function can impossibly know in which order you wrote SDL_RENDERER_SOFTWARE and SDL_RENDERER_ACCELERATED. The | operator simply produce a value where the bits are 1 if the corresponding bit is 1 in any of the two arguments.

SDL_RENDERER_SOFTWARE | SDL_RENDERER_ACCELERATED -> 00000001 | 00000010 -> 00000011
Last edited on
It just goes strait for accelerated.
That's because your system supports accelerated. If it is not then it will fall back to software rendering. That's the point of having a fallback.

Thats messed up man... I think that I have a driver problem... When I open my game, the window is blank and glitched, and no sdl errors pop up when it checks if the renderer is equal to null... But I play videogames! Shouldn't I have renderer problems with them too? I even re-downloaded the accelerated driver from intel for my chip set... Any ideas?

Yea, it works on other computers.
Last edited on
Can you post the code that's making it glitch? Also, in what way is it glitching?
Its so weird... But I think I have a temporary solution for it.

1
2
3
4
5
6
7
8
9
10
11
gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_ACCELERATED );
if( gRenderer == NULL )
{
  printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
  gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_SOFTWARE );
  if( gRenderer == NULL )
  {
    printf( "Renderer could not be created... again! SDL Error: %s\n", SDL_GetError() );
    return;
  }
}


Its weird, when I make it only have the accelerated flag, I get no error, but with both of them there I get it...

Does "Couldn't find matching render driver" ring any bell, or is it just the casual no accelerated driver message?

Can you post the code that's making it glitch? Also, in what way is it glitching?

Any sdl code that I compile gives the same error, you can take the lazyfoo tutorials for example.

This is what it looks like:
http://i.imgur.com/l8hLapE.png

Does anyone know a small precompiled sdl program I can download to see if its only for my compiles?
Any sdl code that I compile gives the same error
Even code that doesn't have SDL_CreateRenderer ? Can you post an example?
Oh, sorry, I meant to say that all the sdl code that I compile with the renderer, gets the same bug, not error. As I said, you can take the rendering tutorial on lazy foo as an example, any code with sdl rendering has the same bug...
Find the smallest example that produces this error. And post it. You can use pastebin if it's a bit long. But I'm not going to go through six tutorials to put together code that may or may not be the same code causing issues for you.
Topic archived. No new replies allowed.