chore: add Dart/windows-only example project

This commit is contained in:
Nick Fisher
2024-11-02 13:10:36 +11:00
parent 9c6b2a92ac
commit 27e1456b9f
7 changed files with 113 additions and 0 deletions

3
examples/dart/cli_windows/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

View File

@@ -0,0 +1,3 @@
## 1.0.0
- Initial version.

View File

@@ -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
```

View File

@@ -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

View File

@@ -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<String> arguments) async {
var lib = DynamicLibrary.open("thermion_windows.dll");
var createWindow = lib.lookupFunction<Int Function(Int width, Int height, Int left, Int top), int Function(int, int, int, int)>("create_thermion_window");
var update = lib.lookupFunction<Void Function(), void Function()>("update");
var hwnd = createWindow(500, 500, 0, 0);
update();
final resourceLoader = calloc<ResourceLoaderWrapper>(1);
var loadToOut = NativeCallable<
Void Function(Pointer<Char>,
Pointer<ResourceBuffer>)>.listener(DartResourceLoader.loadResource);
resourceLoader.ref.loadToOut = loadToOut.nativeFunction;
var freeResource = NativeCallable<Void Function(ResourceBuffer)>.listener(
DartResourceLoader.freeResource);
resourceLoader.ref.freeResource = freeResource.nativeFunction;
var viewer = ThermionViewerFFI(
resourceLoader: resourceLoader.cast<Void>());
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));
}
}

View File

@@ -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

Binary file not shown.