Why does this tutorial not have SDL_CreateRenderer anywhere, is this correct?

Here is the tutorial in question: Lazy Foo' Productions - Color Keying

A renderer is created at one point and is set to NULL, this renderer is later passed as an arguement to the SDL_CreateSurfaceFromTexture function. At this point isn’t the created renderer still of NULL value?

 newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface );

When I try this in my own code it does not work, I need to first create the renderer using SDL_CreateRenderer.

This is what I did, I put this line of code before the previous one and it works. However it only works when a single texture is loaded, when I try loading multiple textures with this method as the tutorial does it no longer works, which I guess has something to do with the renderer being ‘created’ again.

 mainRenderer = SDL_CreateRenderer(mainWindow, -1, 0);

Apolagies as my problem might not be very clear from reading this, I would be happy to elaborate.

It assumes you use the same init() function as in earlier tutorials.

Use the link “Download the media and source code for this demo here” at the bottom of the page to see the complete code put together.

You shouldn’t have to create multiple renderers. Just create one renderer at the beginning and then keep reusing it for all textures you load and other things that requires a renderer.

1 Like

Thanks for the help, my Init() function was missing the part where it created the renderer, got it working now.