Flipping textures through RenderCopyEx's flip parameter in software mode gets them scrambled

Hello humans. First things first, I’m using SDL2.0.8.

I’ll be brief: I’m trying to find a way to draw a smaller surface onto the window’s surface (for pixel art games), but without having to ditch the SDL_Render routine set.

Here is a snippet to show what I’m trying to do:

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 128
#define SCALE 4

int main(int argc, char **argv) {
/* Skipping mundale loading stuff */

SDL_Window *window = SDL_CreateWindow(
    "SDL Game",

SDL_Surface *windowSurface = SDL_GetWindowSurface(window);
SDL_Surface *renderTarget = SDL_CreateRGBSurface(0, SCREEN_WIDTH, SCREEN_HEIGHT, 32, 0, 0, 0, 0);
SDL_Renderer *renderer = SDL_CreateSoftwareRenderer(renderTarget);


SDL_Surface *surfPlayer = IMG_Load("res/img/my_sprite.png");
SDL_Texture *player = SDL_CreateTextureFromSurface(renderer, surfPlayer);

SDL_Rect playerFrame = { 0, 0, 8, 8 };
SDL_Rect playerRect = { 0, 0, playerFrame.w, playerFrame.h };

bool running = true;
SDL_Event e;
while (running) {
    while(SDL_PollEvent(&e)) {
        switch (e.type) {
            case SDL_WINDOWEVENT_CLOSE:
            case SDL_QUIT:
                running = false;

            case SDL_KEYDOWN:
                if (e.key.keysym.sym == SDLK_q)
                    running = false;

    SDL_SetRenderDrawColor(renderer, 0x80, 0x80, 0x80, 0xff);

    SDL_RenderCopyEx(renderer, player, &playerFrame, &playerRect, 0, NULL, SDL_FLIP_HORIZONTAL); 

    SDL_BlitScaled(renderTarget, NULL, windowSurface, NULL);




This only works with textures that doesn’t have an alpha channel. If they do, they get mixed up.
(I tried 8 and 32bit depths for images, without success)

Per-pixel stuff is faster with surfaces, this the only reason I’m not using SDL_Renderer in hardware mode.
(Sorry for not being so polite, I’m in quite of a rush in my friend’s place)

Thanks in advance, and thanks for all the community for the great work you all have been doing, just terrific!

Aren’t you confusing things here? Shouldn’t you use SDL_RenderPresent(renderer); here?


The only problem I see is that black is transparent with the SDL_BLENDMODE_BLEND and 24-bit surfaces when the texture is not flipped and blitted without scaling. How odd.

Can you describe how the image is mixed up? Or even better, if you have time, can you complete your snippet to a working example including the image? That way we can dig into the problem properly.

@Acry: This is not necessary since SDL_Render routines are operating on the surface’s pixels.

@ChliHug: Here’s what it looks like:

(The rectangle and line are just for you to see that other things are not really affected by this, the problem is in the sprite in the top left corner)
One dirty of a workaround is to have sprite sheets with the first tile transparent. For some magical reason this… thing… doesn’t happen.

Also it doesn’t happen if you only have one tile!

Thanks again guys, I never thought you’d even answer this!

I’m interested in checking if there’s an issue with SDL here. How’s it supposed to look?

I just found the issue with the problem I had. It’s a bug in the run-length encoder and it sometimes make black transparent with certain opaque surfaces. I don’t think this applies to you here, though.

I’ll create a fully working example of the issue when I get home, but they basically never get black or white, just wrong, messed up.
Another thing is, when I set the destination rectangle to at least 1 pixel wider or higher it renders OK.

Sorry if I’m not being very clear, as soon as I show the example I believe you guys will understand it.

I’m in quite of a rush this month, didn’t get to do what I said I would, sorry guys.
Did any of you get to draw sprites with SDL_RenderCopyEx with an SDL_Renderer created with SDL_CreateSoftwareRenderer without any problems? Thanks again!