You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Builds a mask render texture by drawing a shape to it.
Then renders something to a second render texture before changing the blend mode to alpha only and drawing the mask.
The blend mode will cause ONLY the alpha values from the mask be written to the destination texture, thus setting the mask alpha in the render texture used to draw.
#include "rlgl.h"
#define GL_SRC_ALPHA 0x0302
#define GL_MIN 0x8007
{
Tx = LoadTexture("parrots.png");
SetTextureFilter(Tx, TEXTURE_FILTER_TRILINEAR);
Camera.zoom = 1;
// build the mask
RenderTexture mask = LoadRenderTexture(512, 512);
BeginTextureMode(mask);
ClearBackground(BLANK);
DrawCircle(256, 256, 250, WHITE);
EndTextureMode();
// build the image
MaskedImage = LoadRenderTexture(512, 512);
BeginTextureMode(MaskedImage);
ClearBackground(RED);
DrawTexture(Tx, 0, 0, WHITE);
DrawText("I AM TEXT", 0, 128, 40, GREEN);
// force the blend mode to only set the alpha of the destination
rlSetBlendFactors(GL_SRC_ALPHA, GL_SRC_ALPHA, GL_MIN);
rlSetBlendMode(BLEND_CUSTOM);
// draw the mask
DrawTexture(mask.texture, 0, 0, WHITE);
// put the blend mode back
rlSetBlendMode(BLEND_ALPHA);
EndTextureMode();
// don't need the mask anymore
UnloadRenderTexture(mask);
}
void SpriteView::OnShow(const Rectangle& contentArea)
{
ClearBackground(Colors::DarkGray);
BeginMode2D(Camera);
DrawUtils::DrawGrid2D(Vector2Zero(), (int)RectTools::MaxSize(contentArea)/2, 100, Colors::Gray, Colors::DarkBlue);
DrawTextureRec(MaskedImage.texture, Rectangle{ 0,0, (float)MaskedImage.texture.width, (float)-MaskedImage.texture.height }, Vector2Zero(), WHITE);
EndMode2D();
DrawText(TextFormat("Zoom:%.1f%%", Camera.zoom * 100), 0, (int)contentArea.height - 20, 20, Colors::White);
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Builds a mask render texture by drawing a shape to it.
Then renders something to a second render texture before changing the blend mode to alpha only and drawing the mask.
The blend mode will cause ONLY the alpha values from the mask be written to the destination texture, thus setting the mask alpha in the render texture used to draw.
Beta Was this translation helpful? Give feedback.
All reactions