c++ - SDL:在另一个纹理之上渲染纹理

标签 c++ textures rendering sdl blit

我遇到以下问题:

我需要在另一个纹理之上渲染一个纹理,然后渲染那个主纹理。 例如,我有蓝色矩形纹理,我想在这个蓝色矩形上绘制红色矩形。但是我希望他们只在这个矩形上限制渲染。就像下面的图片: enter image description here

我读到了一些关于它们之间的纹理 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/

相关文章:

c++ - QT通过C++添加Map QML Items

python - Maya Python,连接到 2 个列表

opencv - 图片中特定区域的纹理识别

c++ - OpenGL 中的复杂纹理映射?

java - 如何修复 javafx 中的渲染错误(ComboBox、ListView)

html - HTML 标题和列表的呈现

c++ - 在 Windows 10 上使用 D3D11 调试层和 VS2013

c++ - LAPACKE 函数中对角化所需的完整矩阵或三角部分?

c++ - 为什么我的 UWP 游戏在发布时比在 Debug模式下慢?

iphone - OpenGL ES (iPhone) 多重纹理 (2D) 代码