diff --git a/examples/dart/cli_windows/.gitignore b/examples/dart/cli_windows/.gitignore new file mode 100644 index 00000000..3a857904 --- /dev/null +++ b/examples/dart/cli_windows/.gitignore @@ -0,0 +1,3 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ diff --git a/examples/dart/cli_windows/CHANGELOG.md b/examples/dart/cli_windows/CHANGELOG.md new file mode 100644 index 00000000..effe43c8 --- /dev/null +++ b/examples/dart/cli_windows/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/examples/dart/cli_windows/README.md b/examples/dart/cli_windows/README.md new file mode 100644 index 00000000..08de33db --- /dev/null +++ b/examples/dart/cli_windows/README.md @@ -0,0 +1,7 @@ +# Thermion Example - Dart/Windows-only (no Flutter) + +A (Windows-only) command-line application that renders into a window without Flutter. + +``` +dart --enable-experiment=native-assets bin\cli_windows.dart +``` \ No newline at end of file diff --git a/examples/dart/cli_windows/analysis_options.yaml b/examples/dart/cli_windows/analysis_options.yaml new file mode 100644 index 00000000..dee8927a --- /dev/null +++ b/examples/dart/cli_windows/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_windows/bin/cli_windows.dart b/examples/dart/cli_windows/bin/cli_windows.dart new file mode 100644 index 00000000..4a1e5cc6 --- /dev/null +++ b/examples/dart/cli_windows/bin/cli_windows.dart @@ -0,0 +1,52 @@ +import 'dart:ffi'; +import 'dart:io'; + +import 'package:ffi/ffi.dart'; +// import 'package:thermion_dart/thermion_dart/thermion_viewer_ffi.dart'; +import 'package:thermion_dart/src/utils/src/dart_resources.dart'; +import 'package:thermion_dart/src/viewer/src/ffi/src/thermion_viewer_ffi.dart'; +import 'package:thermion_dart/src/viewer/src/ffi/src/thermion_dart.g.dart'; + +void main(List arguments) async { + var lib = DynamicLibrary.open("thermion_windows.dll"); + var createWindow = lib.lookupFunction("create_thermion_window"); + var update = lib.lookupFunction("update"); + var hwnd = createWindow(500, 500, 0, 0); + update(); + + final resourceLoader = calloc(1); + + var loadToOut = NativeCallable< + Void Function(Pointer, + Pointer)>.listener(DartResourceLoader.loadResource); + + resourceLoader.ref.loadToOut = loadToOut.nativeFunction; + var freeResource = NativeCallable.listener( + DartResourceLoader.freeResource); + resourceLoader.ref.freeResource = freeResource.nativeFunction; + + var viewer = ThermionViewerFFI( + + resourceLoader: resourceLoader.cast()); + + await viewer.initialized; + var swapChain = await viewer.createSwapChain(hwnd); + var view = await viewer.getViewAt(0); + await view.updateViewport(500, 500); + + await view.setRenderable(true, swapChain); + + await viewer.setBackgroundColor(1.0, 0.0, 0.0, 1.0); + + var skyboxPath = File("..\\..\\assets\\default_env_skybox.ktx").absolute; + + await viewer.loadSkybox("file://${skyboxPath.uri.toFilePath(windows: true)}"); + while(true) { + await viewer.render(); + update(); + await Future.delayed(Duration(milliseconds: 16)); + } + + + +} diff --git a/examples/dart/cli_windows/pubspec.yaml b/examples/dart/cli_windows/pubspec.yaml new file mode 100644 index 00000000..6b398062 --- /dev/null +++ b/examples/dart/cli_windows/pubspec.yaml @@ -0,0 +1,18 @@ +name: cli_windows +description: A sample command-line application with basic argument parsing. +version: 0.0.1 +# repository: https://github.com/my_org/my_repo + +environment: + sdk: ^3.6.0-326.0.dev + +# Add regular dependencies here. +dependencies: + args: ^2.5.0 + thermion_dart: + path: F:\Projects\thermion\thermion_dart + ffi: ^2.1.3 + +dev_dependencies: + lints: ^5.0.0 + test: ^1.24.0 diff --git a/examples/dart/cli_windows/thermion_windows.dll b/examples/dart/cli_windows/thermion_windows.dll new file mode 100644 index 00000000..638caeef Binary files /dev/null and b/examples/dart/cli_windows/thermion_windows.dll differ