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