From 21e8cf0d116abbc165f8a2409c11851186415d32 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 18 Jun 2025 13:08:51 +0800 Subject: [PATCH] add Dart/headless example --- examples/dart/cli_headless/.gitignore | 4 +++ examples/dart/cli_headless/CHANGELOG.md | 3 ++ examples/dart/cli_headless/README.md | 3 ++ .../dart/cli_headless/analysis_options.yaml | 30 +++++++++++++++++ examples/dart/cli_headless/bin/example.dart | 32 +++++++++++++++++++ examples/dart/cli_headless/pubspec.yaml | 15 +++++++++ 6 files changed, 87 insertions(+) create mode 100644 examples/dart/cli_headless/.gitignore create mode 100644 examples/dart/cli_headless/CHANGELOG.md create mode 100644 examples/dart/cli_headless/README.md create mode 100644 examples/dart/cli_headless/analysis_options.yaml create mode 100644 examples/dart/cli_headless/bin/example.dart create mode 100644 examples/dart/cli_headless/pubspec.yaml diff --git a/examples/dart/cli_headless/.gitignore b/examples/dart/cli_headless/.gitignore new file mode 100644 index 00000000..10abc991 --- /dev/null +++ b/examples/dart/cli_headless/.gitignore @@ -0,0 +1,4 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ +output/** diff --git a/examples/dart/cli_headless/CHANGELOG.md b/examples/dart/cli_headless/CHANGELOG.md new file mode 100644 index 00000000..effe43c8 --- /dev/null +++ b/examples/dart/cli_headless/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/examples/dart/cli_headless/README.md b/examples/dart/cli_headless/README.md new file mode 100644 index 00000000..aee1def6 --- /dev/null +++ b/examples/dart/cli_headless/README.md @@ -0,0 +1,3 @@ +# cli_headless + +An example of Thermion running via Dart CLI with no hardware accelerated rendering surface. \ No newline at end of file diff --git a/examples/dart/cli_headless/analysis_options.yaml b/examples/dart/cli_headless/analysis_options.yaml new file mode 100644 index 00000000..dee8927a --- /dev/null +++ b/examples/dart/cli_headless/analysis_options.yaml @@ -0,0 +1,30 @@ +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options diff --git a/examples/dart/cli_headless/bin/example.dart b/examples/dart/cli_headless/bin/example.dart new file mode 100644 index 00000000..31737846 --- /dev/null +++ b/examples/dart/cli_headless/bin/example.dart @@ -0,0 +1,32 @@ +import 'dart:io'; +import 'dart:isolate'; + +import 'package:thermion_dart/thermion_dart.dart'; +import 'package:thermion_dart/src/filament/src/implementation/ffi_filament_app.dart'; + +void main() async { + await FFIFilamentApp.create(); + final (width, height) = (500, 500); + final sc = await FilamentApp.instance!.createHeadlessSwapChain(width, height); + var viewer = ThermionViewerFFI(); + await viewer.initialized; + + await FilamentApp.instance!.register(sc, viewer.view); + + await viewer.view.setFrustumCullingEnabled(false); + await viewer.setBackgroundColor(1, 0, 1, 1); + await viewer.setViewport(width, height); + final result = await FilamentApp.instance!.capture( + sc, + view: viewer.view, + ); + + final bitmap = await pixelBufferToBmp(result.first.$2, width, height, + hasAlpha: true, isFloat: true); + + var outfile = File("output/render.bmp"); + outfile.parent.create(); + outfile.writeAsBytesSync(bitmap); + await FilamentApp.instance!.destroy(); + Isolate.current.kill(); +} diff --git a/examples/dart/cli_headless/pubspec.yaml b/examples/dart/cli_headless/pubspec.yaml new file mode 100644 index 00000000..979743ae --- /dev/null +++ b/examples/dart/cli_headless/pubspec.yaml @@ -0,0 +1,15 @@ +name: example_cli +description: A sample command-line application. +version: 1.0.0 + +environment: + sdk: ^3.3.0 + +dependencies: + thermion_dart: + path: ../../../thermion_dart + +dev_dependencies: + ffigen: ^11.0.0 + lints: ^3.0.0 + test: ^1.24.0