DropShadow 投影、Fill 颜色填充、Tint 双色调映射、Tritone 三色调映射,丰富场景视觉表现。
| 函数 | 说明 |
|---|---|
int xgeShapeExSceneEffectDropShadow(xge_shape_ex_scene pScene, uint32_t iColor, float fAngleDegrees, float fDistance, float fSigma, int iQuality) | 投影 |
int xgeShapeExSceneEffectFill(xge_shape_ex_scene pScene, uint32_t iColor) | 颜色填充覆盖 |
int xgeShapeExSceneEffectTint(xge_shape_ex_scene pScene, uint32_t iBlackColor, uint32_t iWhiteColor, float fIntensity) | 双色调映射 |
int xgeShapeExSceneEffectTritone(xge_shape_ex_scene pScene, uint32_t iShadowColor, uint32_t iMidtoneColor, uint32_t iHighlightColor, int iBlend) | 三色调映射 |
gcc -O2 -I. -o ch71.exe ch71_main.c build\xge.lib -lm -lws2_32 -liphlpapi -lgdi32 -luser32 -lshell32 -lopengl32 -lole32 -lwinmm -lavrt
.\ch71.exe
xge_shape_ex_scene card = NULL;
xgeShapeExSceneCreate(&card);
// ... 添加卡片内容 ...
// 投影:黑色半透明, 45°方向, 距离6px, 模糊4
xgeShapeExSceneEffectDropShadow(card,
0x00000080, // 颜色 (半透明黑)
45.0f, // 角度
6.0f, // 距离
4.0f, // 模糊 sigma
1); // 品质
// 双色调:暗部→深蓝, 亮部→暖白, 强度 0.6
xgeShapeExSceneEffectTint(card,
0x1A237EFF, 0xFFF8E1FF, 0.6f);
// 三色调:暗→蓝, 中间→灰, 亮→金
xgeShapeExSceneEffectTritone(card,
0x0D47A1FF, 0x9E9E9EFF, 0xFFD54FFF,
XGE_BLEND_ALPHA);
// 纯色填充(剪影效果)
xgeShapeExSceneEffectFill(card, 0xFF6B5EFF);将以下代码保存为 ch71_main.c,编译后运行即可看到投影 + 色调动画效果:
#include "xge.h"
static xge_shape_ex_scene g_card = NULL;
static int g_iFrame = 0;
static int onFrame(void* pUser) {
(void)pUser;
xgeClear(0x081114FF);
g_iFrame++;
// 动画投影距离:模拟按下/弹起
float dist = 4.0f + 3.0f * (float)sin(g_iFrame * 0.05f);
xgeShapeExSceneEffectClear(g_card);
xgeShapeExSceneEffectDropShadow(g_card,
0x00000080, 45.0f, dist, 4.0f, 1);
// 色调动画:强度随时间变化
float intensity = 0.3f + 0.3f * (float)sin(g_iFrame * 0.03f);
xgeShapeExSceneEffectTint(g_card,
0x1A237EFF, 0xFFF8E1FF, intensity);
xgeShapeExSceneDraw(g_card, 0.25f);
return XGE_OK;
}
int main(void) {
xge_desc_t d = {0};
d.iWidth = 800;
d.iHeight = 600;
d.sTitle = "ch71 - DropShadow/Tint";
d.iFlags = XGE_INIT_VSYNC;
xgeInit(&d);
// 构建卡片组
xgeShapeExSceneCreate(&g_card);
xge_shape_ex bg = NULL;
xgeShapeExCreate(&bg);
xgeShapeExAppendRect(bg, 250,180, 300,240, 12,12, 1)
xgeShapeExFillColor(bg, 0xE0E0E0FF);
xgeShapeExSceneAdd(g_card, bg);
xgeShapeExDestroy(bg);
xge_shape_ex icon = NULL;
xgeShapeExCreate(&icon);
xgeShapeExAppendCircle(icon, 400, 270, 40, 1);
xgeShapeExFillColor(icon, 0x4FD8C2FF);
xgeShapeExSceneAdd(g_card, icon);
xgeShapeExDestroy(icon);
xgeRun(onFrame, NULL);
xgeShapeExSceneEffectClear(g_card);
xgeShapeExSceneDestroy(g_card);
xgeUnit();
return 0;
}