SDL: Render Texture on top of another texture

前端 未结 2 595
终归单人心
终归单人心 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:49

    Mars answer didnt work because it drew a black texture and nothing could be drawn on that.

    But THIS WORKS!:

    SDL_Texture* auxtexture = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 500, 500);
    
    //change the rendering target
    
    SDL_SetTextureBlendMode(auxtexture, SDL_BLENDMODE_BLEND);
    SDL_SetRenderTarget(ren, auxtexture);
    
    //render what we want
    triangle->render(ren); //render my class triangle e.g
    
    
    //change the target back to the default and then render the aux
    
    SDL_SetRenderTarget(ren, NULL); //NULL SETS TO DEFAULT
    SDL_RenderCopy(ren, auxtexture, NULL, canvas->drect);
    SDL_DestroyTexture(auxtexture);
    

    Cheers.

提交回复
热议问题