diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-03-10 14:59:14 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-03-10 14:59:14 +0100 |
| commit | 1100562e29f6476448b656dbddd4cf22505523f6 (patch) | |
| tree | 442eec492199104bd49dfd74474ce89ade8fcac9 /content/notes/2023-05-27-drawing-pixels-in-plan9.md | |
| parent | a40d80be378e46a6c490e1b99b0d8f4acd968503 (diff) | |
| download | mitjafelicijan.com-1100562e29f6476448b656dbddd4cf22505523f6.tar.gz | |
Move back to JBMAFP
Diffstat (limited to 'content/notes/2023-05-27-drawing-pixels-in-plan9.md')
| -rw-r--r-- | content/notes/2023-05-27-drawing-pixels-in-plan9.md | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/content/notes/2023-05-27-drawing-pixels-in-plan9.md b/content/notes/2023-05-27-drawing-pixels-in-plan9.md new file mode 100644 index 0000000..5b5115d --- /dev/null +++ b/content/notes/2023-05-27-drawing-pixels-in-plan9.md | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | --- | ||
| 2 | title: "Drawing Pixels in Plan9" | ||
| 3 | url: /drawing-pixels-in-plan9.html | ||
| 4 | date: 2023-05-27T17:41:33+02:00 | ||
| 5 | type: note | ||
| 6 | draft: false | ||
| 7 | --- | ||
| 8 | |||
| 9 | I have started exploring Plan9's graphics capabilities. This is a hello world | ||
| 10 | alternative for drawing that draws a yellow square on a blue background. | ||
| 11 | |||
| 12 | More information: | ||
| 13 | |||
| 14 | - [draw.h header file](https://github.com/0intro/plan9/blob/main/sys/include/draw.h) | ||
| 15 | contains all the drawing functions | ||
| 16 | - [draw man page](https://9fans.github.io/plan9port/man/man3/draw.html) | ||
| 17 | has a bit more digestable descriptions of the draw functions | ||
| 18 | - [graphics man page](https://9fans.github.io/plan9port/man/man3/graphics.html) | ||
| 19 | has a bit more digestable descriptions of the graphics functions | ||
| 20 | - [all man pages](https://9fans.github.io/plan9port/man/man3/) | ||
| 21 | can be a valuable resource for learning about the system | ||
| 22 | |||
| 23 |  | ||
| 24 | |||
| 25 | ```c | ||
| 26 | // main.c | ||
| 27 | #include <u.h> | ||
| 28 | #include <libc.h> | ||
| 29 | #include <draw.h> | ||
| 30 | #include <cursor.h> | ||
| 31 | |||
| 32 | void | ||
| 33 | main() | ||
| 34 | { | ||
| 35 | ulong co; | ||
| 36 | Image *im, *bg; | ||
| 37 | co = 0x0000FFFF; | ||
| 38 | |||
| 39 | if (initdraw(nil, nil, argv0) < 0) | ||
| 40 | { | ||
| 41 | sysfatal("%s: %r", argv0); | ||
| 42 | } | ||
| 43 | |||
| 44 | im = allocimage(display, Rect(0, 0, 300, 300), RGB24, 0, DYellow); | ||
| 45 | bg = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, co); | ||
| 46 | |||
| 47 | if (im == nil || bg == nil) | ||
| 48 | { | ||
| 49 | sysfatal("not enough memory"); | ||
| 50 | } | ||
| 51 | |||
| 52 | draw(screen, screen->r, bg, nil, ZP); | ||
| 53 | draw(screen, screen->r, im, nil, Pt(-40, -40)); | ||
| 54 | |||
| 55 | flushimage(display, Refnone); | ||
| 56 | |||
| 57 | // Wait 10 seconds before exiting. | ||
| 58 | sleep(10000); | ||
| 59 | |||
| 60 | exits(nil); | ||
| 61 | } | ||
| 62 | ``` | ||
| 63 | |||
| 64 | And then compile with `mk` (mkfile below): | ||
| 65 | |||
| 66 | ```makefile | ||
| 67 | # mkfile | ||
| 68 | </$objtype/mkfile | ||
| 69 | |||
| 70 | RC=/rc/bin | ||
| 71 | BIN=/$objtype/bin | ||
| 72 | MAN=/sys/man | ||
| 73 | |||
| 74 | main: | ||
| 75 | $CC $CFLAGS main.c | ||
| 76 | $LD $LDFLAGS -o main main.$O | ||
| 77 | ``` | ||
| 78 | |||
| 79 | And run with `./main`. To exit the program, press `Delete key` (strange but this | ||
| 80 | is the alternative for Ctrl+C). | ||
| 81 | |||
| 82 | *This is **very cool** indeed!* | ||
