MaskCompositeScene 在 Scene 级遮罩渲染时执行复合运算,支持自定义源绘制回调。
| 函数 | 说明 |
|---|---|
int xgeShapeExMaskCompositeScene(xge_shape_ex_scene pMaskScene, int iMethod, int iOutputBlend, xge_rect_t tSourceBounds, xge_shape_ex_draw_proc pSourceDraw, void* pSourceUser, float fTolerance, const xge_shape_ex_matrix_t* pParentMatrix, int bScreenSpace) | Scene 遮罩复合运算 |
gcc -O2 -I. -o ch56.exe ch56_main.c build\xge.lib -lm -lws2_32 -liphlpapi -lgdi32 -luser32 -lshell32 -lopengl32 -lole32 -lwinmm -lavrt
.\ch56.exe
// 自定义源绘制回调
static void DrawSource(void* pUser) {
xge_shape_ex src = (xge_shape_ex)pUser;
xgeShapeExDraw(src, 0.25f);
}
// 构建遮罩 Scene
xge_shape_ex_scene maskScene = NULL;
xgeShapeExSceneCreate(&maskScene);
xgeShapeExSceneAdd(maskScene, g_maskShape);
// 执行复合运算
xge_rect_t bounds = { 0, 0, 800, 600 };
xgeShapeExMaskCompositeScene(maskScene,
XGE_SHAPE_EX_MASK_ALPHA,
XGE_BLEND_ALPHA,
bounds,
DrawSource, g_contentShape,
0.25f, NULL, 0);将以下代码保存为 ch56_main.c,编译后运行即可看到 Scene 遮罩复合运算效果:
#include "xge.h"
static void DrawSource(void* pUser) {
xge_shape_ex src = (xge_shape_ex)pUser;
xgeShapeExDraw(src, 0.25f);
}
static int onFrame(void* pUser) {
(void)pUser;
xgeClear(0x081114FF);
// 遮罩形状:径向渐变圆
xge_shape_ex maskShape = NULL;
xgeShapeExCreate(&maskShape);
xgeShapeExAppendCircle(maskShape, 400, 300, 200, 200, 1);
xge_shape_ex_color_stop_t stops[] = {
{ 0.0f, 0xFFFFFFFF },
{ 1.0f, 0xFFFFFF00 },
};
xgeShapeExFillRadialGradient(maskShape, 400,300,200, 400,300,
XGE_SHAPE_EX_GRADIENT_USER_SPACE, stops, 2);
// 内容:彩色矩形
xge_shape_ex content = NULL;
xgeShapeExCreate(&content);
xgeShapeExAppendRect(content, 100,100, 600,400, 0,0, 1);
xgeShapeExFillColor(content, 0x4FD8C2FF);
// 构建遮罩 Scene
xge_shape_ex_scene maskScene = NULL;
xgeShapeExSceneCreate(&maskScene);
xgeShapeExSceneAdd(maskScene, maskShape);
// 执行复合运算
xge_rect_t bounds = { 0, 0, 800, 600 };
xgeShapeExMaskCompositeScene(maskScene,
XGE_SHAPE_EX_MASK_ALPHA,
XGE_BLEND_ALPHA,
bounds, DrawSource, content,
0.25f, NULL, 0);
xgeShapeExSceneDestroy(maskScene);
xgeShapeExDestroy(content);
xgeShapeExDestroy(maskShape);
return XGE_OK;
}
int main(void) {
xge_desc_t d = {0};
d.iWidth = 800;
d.iHeight = 600;
d.sTitle = "ch56 - Mask Composite";
d.iFlags = XGE_INIT_VSYNC;
xgeInit(&d);
xgeRun(onFrame, NULL);
xgeUnit();
return 0;
}