SDL: Render Texture on top of another texture

前端 未结 2 596
终归单人心
终归单人心 2020-12-17 23:47

i am having trouble with the following:

I need to render a texture on top of another texture and then render that main texture. For example I have the blue rectangle

2条回答
  •  庸人自扰
    2020-12-18 00:28

    First, you need to create your texture on which you want to draw with SDL_TEXTUREACCESS_TARGET flag. So create back texture like this:

    back = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, 50, 50);
    

    Then, when calling drawing functions, you need to set the back texture as the target, like so:

    SDL_SetRenderTarget(renderer, back);
    

    Then you draw what you want, and after that you change the target to null:

    SDL_SetRenderTarget(renderer, NULL);
    

    And render back texture:

    SDL_RenderCopy(renderer, back, NULL, &some_rect);
    

提交回复
热议问题