onRender method
Override for custom rendering.
Implementation
@override
void onRender(Canvas canvas, Matrix4 viewProjection) {
final mvp = viewProjection * worldMatrix;
final center4 = mvp.transformed(Vector4(0, 0, 0, 1));
if (center4.w <= 0.001) return;
final ndcX = center4.x / center4.w;
final ndcY = center4.y / center4.w;
final depth = center4.w;
final scaledFontSize = fontSize / depth;
canvas.save();
canvas.translate(ndcX, ndcY);
final textPainter = TextPainter(
text: TextSpan(
text: text,
style: TextStyle(
color: color,
fontSize: scaledFontSize,
fontWeight: fontWeight,
),
),
textDirection: TextDirection.ltr,
textAlign: textAlign,
)..layout(maxWidth: 800 / depth);
textPainter.paint(
canvas,
Offset(-textPainter.width / 2, -textPainter.height / 2),
);
canvas.restore();
}