MiterLimit 防止锐角处产生过长尖刺;NonScaling 让描边宽度不受变换缩放影响。
| 函数 | 说明 |
|---|---|
int xgeShapeExStrokeMiterLimit(xge_shape_ex pShape, float fLimit) | 设置斜接限制 |
int xgeShapeExStrokeMiterLimitGet(xge_shape_ex pShape, float* pLimit) | 获取斜接限制 |
int xgeShapeExStrokeNonScaling(xge_shape_ex pShape, int bNonScaling) | 设置非缩放描边 |
int xgeShapeExStrokeNonScalingGet(xge_shape_ex pShape, int* pNonScaling) | 获取非缩放状态 |
gcc -O2 -I. -o ch48.exe ch48_main.c build\xge.lib -lm -lws2_32 -liphlpapi -lgdi32 -luser32 -lshell32 -lopengl32 -lole32 -lwinmm -lavrt
.\ch48.exe
// 锐角三角形 — 观察不同 MiterLimit 效果
float limits[] = { 1.0f, 4.0f, 20.0f };
for (int i = 0; i < 3; i++) {
xge_shape_ex s = NULL;
xgeShapeExCreate(&s);
// 尖锐三角形
xgeShapeExMoveTo(s, 100+i*250, 400);
xgeShapeExLineTo(s, 200+i*250, 100);
xgeShapeExLineTo(s, 300+i*250, 400);
xgeShapeExClose(s);
xgeShapeExStrokeColor(s, 0xFFB454FF);
xgeShapeExStrokeWidth(s, 8.0f);
xgeShapeExStrokeJoin(s, XGE_SHAPE_EX_JOIN_MITER);
xgeShapeExStrokeMiterLimit(s, limits[i]);
xgeShapeExDraw(s, 0.25f);
xgeShapeExDestroy(s);
}xge_shape_ex shape = NULL;
xgeShapeExCreate(&shape);
xgeShapeExAppendRect(shape, -50,-50, 100,100, 0,0, 1);
xgeShapeExStrokeColor(shape, 0x4FD8C2FF);
xgeShapeExStrokeWidth(shape, 2.0f);
// 启用非缩放 → 放大 3 倍后描边仍为 2px
xgeShapeExStrokeNonScaling(shape, 1);
xgeShapeExTransformScale(shape, 3.0f, 3.0f);
xgeShapeExTransformTranslate(shape, 400, 300);
xgeShapeExDraw(shape, 0.25f);将以下代码保存为 ch48_main.c,编译后运行即可看到 MiterLimit 与 NonScaling 描边效果:
#include "xge.h"
static int onFrame(void* pUser) {
(void)pUser;
xgeClear(0x081114FF);
// MiterLimit 对比:三个尖锐三角形
float limits[] = { 1.0f, 4.0f, 20.0f };
for (int i = 0; i < 3; i++) {
xge_shape_ex s = NULL;
xgeShapeExCreate(&s);
xgeShapeExMoveTo(s, 60+i*250, 250);
xgeShapeExLineTo(s, 160+i*250, 50);
xgeShapeExLineTo(s, 260+i*250, 250);
xgeShapeExClose(s);
xgeShapeExStrokeColor(s, 0xFFB454FF);
xgeShapeExStrokeWidth(s, 8.0f);
xgeShapeExStrokeJoin(s, XGE_SHAPE_EX_JOIN_MITER);
xgeShapeExStrokeMiterLimit(s, limits[i]);
xgeShapeExDraw(s, 0.25f);
xgeShapeExDestroy(s);
}
// NonScaling 描边:放大 3 倍后描边仍为 2px
xge_shape_ex ns = NULL;
xgeShapeExCreate(&ns);
xgeShapeExAppendRect(ns, -50,-50, 100,100, 0,0, 1);
xgeShapeExStrokeColor(ns, 0x4FD8C2FF);
xgeShapeExStrokeWidth(ns, 2.0f);
xgeShapeExStrokeNonScaling(ns, 1);
xgeShapeExTransformScale(ns, 3.0f, 3.0f);
xgeShapeExTransformTranslate(ns, 400, 430);
xgeShapeExDraw(ns, 0.25f);
xgeShapeExDestroy(ns);
return XGE_OK;
}
int main(void) {
xge_desc_t d = {0};
d.iWidth = 800;
d.iHeight = 600;
d.sTitle = "ch48 - MiterLimit & NonScaling";
d.iFlags = XGE_INIT_VSYNC;
xgeInit(&d);
xgeRun(onFrame, NULL);
xgeUnit();
return 0;
}