SDL:在另一个纹理上渲染纹理 [英] SDL: Render Texture on top of another texture
问题描述
我在以下方面遇到麻烦:
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 texture, and I want to draw red rectangles on top of this blue rect. However i want them to restrict the render only on this rectangle. Like the following image:
我阅读了一些关于它们之间纹理破裂的信息,或者类似的信息,但是我不确定这是否可行。
I read something about texture blit between them or something like that but im not sure if this is posible.
我的代码如下:
SDL_RenderCopy(ren,bluetexture,NULL,dBLUErect);
SDL_RenderCopy(ren,redtexture,NULL,dREDrect);
SDL_RenderPresent(ren);
有人知道如何在SDL 2.0中做到这一点吗?
Any one knows about how to do this in SDL 2.0? thats what Im using by the way.
推荐答案
火星答案无效,因为它绘制了黑色纹理,因此无法画出任何东西
Mars answer didnt work because it drew a black texture and nothing could be drawn on that.
但是,这可行!
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);
干杯。
这篇关于SDL:在另一个纹理上渲染纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!