Skip to content

Commit 7f0a5b7

Browse files
update doc/QuickStart.md
1 parent baba3aa commit 7f0a5b7

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

doc/QuickStart.md

+37-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--------
2-
**DISCLAIMER: This project is very much a Work In Progress. We're making it accessible in this very early state so that participants to the [Wheel Reinvention Jam 2023](https://handmade.network/jam/2023) can try it out and maybe use it as their jamming platform. Expect bugs, missing and/or incomplete features, unstable APIs, and sparse documentation. Some current issues might be a show stopper for you, so make sure you can build and run the sample apps before jumping in.**
2+
**DISCLAIMER: This project is very much a Work In Progress. Expect bugs, missing and/or incomplete features, unstable APIs, and sparse documentation. Some current issues might be a show stopper for you, so make sure you can build and run the sample apps before jumping in.**
33

44
**If you do choose to try out Orca anyway, well thanks! We'll do our best to answer your questions, and we'd really appreciate to hear your feedback!**
55

@@ -13,16 +13,41 @@ This is a short introduction to developing an application that can be run by the
1313

1414
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.
1515

16-
Orca also ships with a core library, written in C, which facilitates interaction with the Orca runtime and provides features like UI. This library should be compiled along with your app as part of producing your WebAssembly module.
16+
Orca also ships with a core library, written in C, 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.
1717

1818
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.
1919

2020
![Basic structure of a C app](images/app_c.png)
2121

22+
For example, here's how we build the WebAssembly module for our Breakout example app:
23+
24+
```
25+
ORCA_DIR=$(orca sdk-path)
26+
27+
wasmFlags=(--target=wasm32 \
28+
-mbulk-memory \
29+
-g -O2 \
30+
-D__ORCA__ \
31+
-Wl,--no-entry \
32+
-Wl,--export-dynamic \
33+
--sysroot "$ORCA_DIR"/orca-libc \
34+
-I "$ORCA_DIR"/src \
35+
-I "$ORCA_DIR"/src/ext)
36+
37+
clang "${wasmFlags[@]}" -L "$ORCA_DIR"/bin -lorca_wasm -o module.wasm src/main.c
38+
39+
```
40+
2241
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.
2342

2443
![Example Orca application bundle](images/app_bundle.png)
2544

45+
For example here's how we bundle the breakout example app:
46+
47+
```
48+
orca bundle --name Breakout --icon icon.png --resource-dir data module.wasm
49+
```
50+
2651
## Basic structure
2752

2853
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`.
@@ -69,26 +94,27 @@ ORCA_EXPORT void oc_on_init(void)
6994

7095
### Graphics surfaces
7196

72-
The next line of `oc_on_init()` creates a _graphics surface_. A surface represents a destination you can draw into using a specific API. In this sample, we're going to use a canvas surface, which allows drawing with a 2D vector graphics API. Other samples use a GLES surface to draw with the OpenGL ES API.
97+
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.
7398

74-
Before drawing into it, the surface must be selected as the current surface by calling `oc_surface_select()`. Once all drawing is done you can display the result by calling `oc_surface_present()`.
99+
We first create a _canvas renderer_. From that renderer we can then create a _graphics surface_ compatible for drawing 2D vector graphics.
75100

76101
```c
77102
oc_surface surface = { 0 };
78-
oc_canvas canvas = { 0 };
103+
oc_canvas_renderer renderer = { 0 };
104+
oc_canvas_context context = { 0 };
79105

80106
ORCA_EXPORT void oc_on_init(void)
81107
{
82108
// ...
83-
surface = oc_surface_canvas();
84-
canvas = oc_canvas_create();
109+
renderer = oc_canvas_renderer_create();
110+
surface = oc_canvas_surface_create(renderer);
85111
// ...
86112
}
87113
```
88114
89115
### Canvas
90116
91-
After creating the surface, we create a _canvas_. 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()`.
117+
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()`.
92118
93119
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()`.
94120
@@ -97,13 +123,12 @@ To summarize, the general structure of canvas drawing code is like the following
97123
```c
98124
ORCA_EXPORT void oc_on_frame_refresh(void)
99125
{
100-
oc_canvas_select(canvas); // make the canvas current
126+
oc_canvas_context_select(context); // make the canvas current
101127
102128
//... add commands to the canvas command buffer using drawing functions
103129
104-
oc_surface_select(surface); // select the canvas surface
105-
oc_render(canvas); // render the canvas commands into it
106-
oc_surface_present(surface); // display the result
130+
oc_canvas_render(renderer, context, surface); // render the canvas commands into the surface
131+
oc_canvas_present(renderer, surface); // display the surface
107132
}
108133
```
109134

0 commit comments

Comments
 (0)