我遇到以下问题:
我需要在另一个纹理之上渲染一个纹理,然后渲染那个主纹理。 例如,我有蓝色矩形纹理,我想在这个蓝色矩形上绘制红色矩形。但是我希望他们只在这个矩形上限制渲染。就像下面的图片:
我读到了一些关于它们之间的纹理 blit 或类似的东西,但我不确定这是否可行。
我的代码是这样的:
SDL_RenderCopy(ren,bluetexture,NULL,dBLUErect);
SDL_RenderCopy(ren,redtexture,NULL,dREDrect);
SDL_RenderPresent(ren);
有人知道如何在 SDL 2.0 中执行此操作吗?顺便说一下,这就是我使用的。
最佳答案
Mars answer 没有用,因为它画了一个黑色的纹理,上面什么也画不了。
但这行得通!
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);
干杯。
关于c++ - SDL:在另一个纹理之上渲染纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18647592/