Skip to content

Commit dd2c484

Browse files
move docs to main repo
1 parent eb4ca30 commit dd2c484

File tree

11 files changed

+499
-0
lines changed

11 files changed

+499
-0
lines changed

.github/workflows/build-doc-site.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: build-site
2+
on:
3+
push:
4+
branches:
5+
- martin/api-spec
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Configure Git Credentials
12+
run: |
13+
git config user.name 'github-actions[bot]'
14+
git config user.email 'github-actions[bot]@users.noreply.github.com'
15+
- uses: actions/setup-python@v5
16+
with:
17+
python-version: 3.x
18+
- name: buid api doc
19+
run: |
20+
pip install libclang
21+
python scripts/gen_doc.py src/api.json doc/mkdocs
22+
- name: build site
23+
run: |
24+
pip install mkdocs
25+
cd ./doc/mkdocs
26+
mkdocs build
27+
- name: Upload Artifact
28+
uses: actions/upload-pages-artifact@v1
29+
with:
30+
# location of the coverage artifacts
31+
path: "./doc/mkdocs/site"
32+
33+
deploy:
34+
runs-on: ubuntu-latest
35+
needs: build
36+
37+
permissions:
38+
pages: write
39+
id-token: write
40+
41+
environment:
42+
# environment created automatically by GitHub
43+
name: github-pages
44+
url: ${{ steps.deployment.outputs.page_url }}
45+
46+
steps:
47+
- name: Deploy to GitHub Pages
48+
id: deployment
49+
uses: actions/deploy-pages@v2

doc/mkdocs/docs/QuickStart.md

+238
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
2+
# Quick Start
3+
4+
This is a short introduction to developing an application that can be run by the Orca runtime. We'll present the basic structure of an Orca application, and walk through a simple example in C.
5+
6+
## What is an Orca app?
7+
8+
An Orca app is a WebAssembly module designed for the Orca runtime. Your app interacts with the Orca runtime via WebAssembly imports and exports. For example, you can import functions from the Orca runtime to get user input, and export functions to the Orca runtime to draw to the screen.
9+
10+
You can, in principle, write an Orca app in any programming language that supports WebAssembly. However, at this early stage, C is the only officially supported language.
11+
12+
Orca also ships with a core library which facilitates interaction with the Orca runtime and provides features like UI. It also ships with a C standard library implementation designed to work on WebAssembly. These libraries should be linked to your app as part of producing your WebAssembly module. You can get the paths to these libraries by running `orca sdk-path`:
13+
14+
- The Orca core library is located in `$(orca sdk-path)/bin`
15+
- The Orca lib C root is located in `$(orca sdk-path)/orca-libc`
16+
17+
![Basic structure of a C app](images/app_c.png)
18+
19+
For example, here's how we build the WebAssembly module for our Breakout example app:
20+
21+
```
22+
ORCA_DIR=$(orca sdk-path)
23+
24+
wasmFlags=(--target=wasm32 \
25+
-mbulk-memory \
26+
-g -O2 \
27+
-Wl,--no-entry \
28+
-Wl,--export-dynamic \
29+
--sysroot "$ORCA_DIR"/orca-libc \
30+
-I "$ORCA_DIR"/src \
31+
-I "$ORCA_DIR"/src/ext)
32+
33+
clang "${wasmFlags[@]}" -L "$ORCA_DIR"/bin -lorca_wasm -o module.wasm src/main.c
34+
35+
```
36+
37+
Once you have compiled your WebAssembly module, you can bundle this module into an executable using the `orca bundle` command. The application bundle can include images, fonts, or any other private data that the app needs in order to function. These files can be read or written from the app without asking the user for permission. The resulting Orca executables are therefore self-contained.
38+
39+
![Example Orca application bundle](images/app_bundle.png)
40+
41+
For example here's how we bundle the breakout example app:
42+
43+
```
44+
orca bundle --name Breakout --icon icon.png --resource-dir data module.wasm
45+
```
46+
47+
## Basic structure
48+
49+
Orca exposes a number of types and functions to applications. In order to use them the first thing to do is to include `orca.h`.
50+
51+
```c
52+
#include<orca.h>
53+
```
54+
55+
The Orca runtime manages the application's window and event loop. In order to receive a specific kind of event, you can define an associated _event handler_ and export it to the runtime. For instance, to be notified when your application's window is resized, you should define the `oc_on_resize()` handler:
56+
57+
```c
58+
ORCA_EXPORT void oc_on_resize(u32 width, u32 height)
59+
{
60+
// handle the window resize event
61+
}
62+
```
63+
64+
The `ORCA_EXPORT` macro makes the handler visible to the Orca runtime, which automatically binds it to the window resize event.
65+
66+
Handlers are optional. If you don't care about an event, you can just omit the associated handler. However, you will almost certainly want to define at least two important handlers:
67+
68+
- `oc_on_init()` is called once when your application starts and can be use to initialize your application's resources.
69+
- `oc_on_frame_refresh()` is called when your application needs to render a new frame, typically tied to the refresh rate of the monitor.
70+
71+
For a list of available handlers and their signatures, see the [app cheatsheet](../doc/cheatsheets/cheatsheet_app.h).
72+
73+
74+
## Clock example
75+
76+
Let's look at the [clock example](../samples/clock). This is a simple app that shows an analog clock and showcases a couple of interesting Orca APIs.
77+
78+
Open [`main.c`](../samples/clock/src/main.c) and look at the definition of `oc_on_init()`. This handler is called when the application starts, right after the application window has been created.
79+
80+
The first thing we do here is set the title and dimensions of the window. We then create the graphics resources that we'll use to draw the clock onto the window.
81+
82+
```c
83+
ORCA_EXPORT void oc_on_init(void)
84+
{
85+
oc_window_set_title(OC_STR8("clock"));
86+
oc_window_set_size((oc_vec2){ .x = 400, .y = 400 });
87+
// ...
88+
}
89+
```
90+
91+
### Graphics surfaces
92+
93+
Orca apps can create several _graphics surfaces_. A surface represents a destination you can draw into using a specific API. In this sample, we're going to use the canvas API, which allows drawing with a 2D vector graphics API. Other samples use a GLES surface to draw with the OpenGL ES API.
94+
95+
We first create a _canvas renderer_. From that renderer we can then create a _graphics surface_ compatible for drawing 2D vector graphics.
96+
97+
```c
98+
oc_surface surface = { 0 };
99+
oc_canvas_renderer renderer = { 0 };
100+
oc_canvas_context context = { 0 };
101+
102+
ORCA_EXPORT void oc_on_init(void)
103+
{
104+
// ...
105+
renderer = oc_canvas_renderer_create();
106+
surface = oc_canvas_surface_create(renderer);
107+
// ...
108+
}
109+
```
110+
111+
### Canvas
112+
113+
After creating the surface, , we create a _canvas context_. A canvas holds some context for drawing commands, like the current color or stroke width, as well as a command buffer that records all drawing commands. All canvas drawing functions use an implicit _current canvas_. You can select a canvas to be the current canvas by calling `oc_canvas_select()`, as seen at the begining of `oc_on_frame_refresh()`.
114+
115+
Canvas drawing functions like `oc_fill()` or `oc_stroke` merely add to the current canvas command buffer. You can later render those commands onto a canvas surface by calling `oc_render()`.
116+
117+
To summarize, the general structure of canvas drawing code is like the following:
118+
119+
```c
120+
ORCA_EXPORT void oc_on_frame_refresh(void)
121+
{
122+
oc_canvas_context_select(context); // make the canvas current
123+
124+
//... add commands to the canvas command buffer using drawing functions
125+
126+
oc_canvas_render(renderer, context, surface); // render the canvas commands into the surface
127+
oc_canvas_present(renderer, surface); // display the surface
128+
}
129+
```
130+
131+
### Drawing
132+
133+
Canvas drawing functions can be roughly divided into three groups:
134+
135+
- Path functions like `oc_line_to()` or `oc_cubic_to()` are used to specify paths using lines and curves.
136+
- Attribute setup functions like `oc_set_color()` or `oc_set_width()` are used to set attributes used by subsequent commands.
137+
- Command functions like `oc_stroke()` and `oc_fill()` encode commands into the canvas command buffer using the current path and attributes.
138+
139+
Some helpers combine a path specification and a command, like `oc_circle_fill()`.
140+
141+
As an example, the back of the clock is drawn using these two calls:
142+
143+
```c
144+
oc_set_color_rgba(1, 1, 1, 1);
145+
oc_circle_fill(centerX, centerY, clockRadius);
146+
```
147+
148+
For a list of canvas drawing functions, see the [graphics API cheatsheet](../doc/cheatsheets/cheatsheet_graphics.h).
149+
150+
#### Transforms
151+
152+
A special case of attribute setting function is the pair `oc_matrix_multiply_push()` and `oc_matrix_pop()`, which are used to manipulate a stack of transform matrices:
153+
154+
- `oc_matrix_multiply_push()` multiplies the matrix currently on top of the stack with its argument, and pushes the result on the stack.
155+
- `oc_matrix_pop()` pops a matrix from the stack.
156+
157+
The matrix on the top of the stack at the time a command is encoded is used to transform the path of that command.
158+
159+
You can see an example of using transform matrices when drawing the clock's hands:
160+
161+
```c
162+
// hour hand
163+
oc_matrix_multiply_push(mat_transform(centerX, centerY, hoursRotation));
164+
{
165+
oc_set_color_rgba(.2, 0.2, 0.2, 1);
166+
oc_rounded_rectangle_fill(0, -7.5 * uiScale, clockRadius * 0.5f, 15 * uiScale, 5 * uiScale);
167+
}
168+
oc_matrix_pop();
169+
```
170+
171+
### Fonts and text
172+
173+
Going back to `oc_init()`, after creating a surface and a canvas, we create a font that we will use to draw the numbers on the clock's face:
174+
175+
```c
176+
oc_unicode_range ranges[5] = {
177+
OC_UNICODE_BASIC_LATIN,
178+
OC_UNICODE_C1_CONTROLS_AND_LATIN_1_SUPPLEMENT,
179+
OC_UNICODE_LATIN_EXTENDED_A,
180+
OC_UNICODE_LATIN_EXTENDED_B,
181+
OC_UNICODE_SPECIALS
182+
};
183+
184+
font = oc_font_create_from_path(OC_STR8("/segoeui.ttf"), 5, ranges);
185+
```
186+
187+
The font is loaded from a font file located in a data folder inside the app bundle. By default, Orca apps use this data folder as their "root" for file operations.
188+
189+
Along with the path of the font file, we pass to the creation function the unicode ranges we want to load.
190+
191+
We then use the font to draw the clock's face:
192+
193+
```c
194+
// clock face
195+
for(int i = 0; i < oc_array_size(clockNumberStrings); ++i)
196+
{
197+
oc_rect textRect = oc_font_text_metrics(font, fontSize, clockNumberStrings[i]).ink;
198+
199+
const f32 angle = i * ((M_PI * 2) / 12.0f) - (M_PI / 2);
200+
oc_mat2x3 transform = mat_transform(centerX - (textRect.w / 2) - textRect.x,
201+
centerY - (textRect.h / 2) - textRect.y,
202+
angle);
203+
204+
oc_vec2 pos = oc_mat2x3_mul(transform, (oc_vec2){ clockRadius * 0.8f, 0 });
205+
206+
oc_set_color_rgba(0.2, 0.2, 0.2, 1);
207+
oc_text_fill(pos.x, pos.y, clockNumberStrings[i]);
208+
}
209+
```
210+
211+
### Logging and asserts
212+
213+
The runtime has a console overlay whose visiblity can be toggled on and off with `⌘ + Shift + D` on macOS, or `Ctrl + Shift + D` on Windows. Your application can log messages, warnings, or errors to that console using the following functions:
214+
215+
```c
216+
void oc_log_info(const char* fmt, ...); // informational messages
217+
void oc_log_warning(const char* fmt, ...); // warnings, displayed in orange.
218+
void oc_log_error(const char* fmt, ...); // errors, displayed in red.
219+
```
220+
221+
If you started the application from a terminal, the log entries are also duplicated there.
222+
223+
You can assert on a condition using `OC_ASSERT(test, fmt, ...)`. If the test fails, the runtime displays a message box and terminates the application.
224+
225+
You can unconditionally abort the application with a message box using `OC_ABORT(fmt, ...)`.
226+
227+
## Where to go next?
228+
229+
For more examples of how to use Orca APIs, you can look at the other [sample apps](https://github.com/orca-app/orca/samples):
230+
231+
- [breakout](https://github.com/orca-app/orca/samples/breakout) is a mini breakout game making use of the vector graphics API. It demonstrates using input and drawing images.
232+
- [triangle](https://github.com/orca-app/orca/samples/triangle) shows how to draw a spining triangle using the GLES API.
233+
- [fluid](https://github.com/orca-app/orca/samples/fluid) is a fluid simulation using a more complex GLES setup.
234+
- [ui](https://github.com/orca-app/orca/samples/ui) showcases the UI API and Orca's default UI widgets.
235+
236+
For a list of Orca APIs, you can look at the [API cheatsheets](https://github.com/orca-app/orca/doc/cheatsheets).
237+
238+
You can also ask questions in the [Handmade Network Discord](https://discord.gg/hmn), in particular in the [#orca](https://discord.com/channels/239737791225790464/1121811864066732082) channel.

doc/mkdocs/docs/building.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Building
2+
3+
The following instructions are only relevant for those who want to develop the orca runtime or orca cli tool.
4+
5+
## Requirements
6+
7+
All of the installation requirements for regular users also apply for developers, with these additions:
8+
9+
- [Python 3.10](https://www.python.org/) or newer
10+
- MSVC (Visual Studio 2022 17.5 or newer) (Windows only)
11+
- This can be installed through the [Visual Studio Community](https://visualstudio.microsoft.com/) installer. Ensure that your Visual Studio installation includes "Desktop development with C++".
12+
- Please note the version requirement! Orca requires C11 atomics, which were only added to MSVC in late 2022.
13+
- Xcode command-line tools (Mac only)
14+
- These can be installed with `xcode-select --install`.
15+
16+
## Building from source
17+
18+
19+
First clone the orca repo: `git clone https://github.com/orca-app/orca.git`
20+
21+
#### Angle and Dawn
22+
23+
Orca depends on Angle for OpenGL ES, and Dawn for WebGPU. You can either build them locally, or grab a precompiled binary built in CI:
24+
25+
- To build locally:
26+
- `cd` to the orca directory
27+
- run `./orcadev build-angle --release`
28+
- run `./orcadev build-dawn --release`
29+
30+
- To use a precompiled binary:
31+
- Go to [https://github.com/orca-app/orca/actions/workflows/build-all.yaml](https://github.com/orca-app/orca/actions/workflows/build-all.yaml)
32+
- Download the artifacts from a previous run.
33+
- On ARM macs, download `angle-mac-arm64` and `dawn-mac-arm64`.
34+
- On Intel macs, download `angle-mac-x64` and `dawn-mac-x64`.
35+
- On Windows, download `angle-windows-x64` and `dawn-windows-x64`.
36+
- Unzip the artifacts and put their content in the `build` directory at the root of the orca repo (you can create that directory if it doesn't exist).
37+
38+
You only need to do this once, until we change the Angle or Dawn versions we depend on.
39+
40+
#### Building Orca
41+
42+
- `cd` to the orca directory and run `./orcadev build` (macOS) or `orcadev build` (Windows)
43+
- If this is the first time you build orca, and you have skipped the previous section, this will print a message telling you you first need to build Angle and Dawn.
44+
45+
#### Installing a dev version of the tooling and SDK
46+
47+
- Inside the repo, run `./orcadev install directory`. This will install a dev version of the tooling and SDK into `directory`.
48+
- Make sure `directory` is in your `PATH` environment variable.
49+
50+
You can then use this dev version normally through the `orca` command line tool.
51+
52+
53+
### FAQ
54+
55+
**I am getting errors about atomics when building the runtime on Windows.**
56+
57+
Please ensure that you have the latest version of Visual Studio and MSVC installed. The Orca runtime requires the use of C11 atomics, which were not added to MSVC until late 2022.

doc/mkdocs/docs/css/extra.css

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
div.col-md-9 h1:first-of-type {
2+
text-align: center;
3+
font-size: 60px;
4+
font-weight: 300;
5+
}
6+
7+
8+
div.col-md-9>p:first-of-type {
9+
text-align: center;
10+
}

doc/mkdocs/docs/faq.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# FAQ
2+
3+
**What platforms does Orca support?**
4+
5+
We currently support Windows 10 and up, and macOS 13 and up. We plan to expand to more platforms in the future.
6+
7+
**What languages can I use with Orca?**
8+
9+
In principle, you can use any language and toolchain that can produce a WebAssembly module and bind to the Orca APIs. However, several important parts of Orca, such as the UI, are provided as part of the core library and are written in C. Therefore, at this early stage, it may be difficult to use any language other than C or C-style C++.
10+
11+
We're currently working with contributors to add support for Odin and Zig, and we look forward to expanding the number of officially-supported languages in the future.
12+
13+
**Which WebAssembly features does Orca support?**
14+
15+
We currently use [wasm3](https://github.com/wasm3/wasm3) for our interpreter. We therefore support whatever features wasm3 supports. In practice this means all WebAssembly 1.0 features, bulk memory operations, and a couple other small features.
16+
17+
18+
**I am getting errors saying that `orca` is not found.**
19+
20+
Please ensure that you have installed Orca to your system per the installation instructions above. Please also ensure that the Orca install directory is on your PATH.
21+
22+
**I am getting errors from wasm-ld saying libclang_rt.builtins-wasm32.a is not found.**
23+
24+
Please ensure that you downloaded and installed `libclang_rt.builtins-wasm32.a` into clang's library directory as per the requirements instructions above.

doc/mkdocs/docs/images/app_bundle.png

37.5 KB
Loading

doc/mkdocs/docs/images/app_c.png

25.7 KB
Loading
184 KB
Binary file not shown.

0 commit comments

Comments
 (0)