init with waymini
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/* Example program that links against the waymini library.
|
||||
* No external dependencies beyond waymini itself and the C standard library.
|
||||
*/
|
||||
|
||||
#include "waymini.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void on_key(void *user, uint32_t keycode, uint32_t state) {
|
||||
(void)user;
|
||||
const char *label = state ? "down" : "up ";
|
||||
printf("key %s: %u\n", label, keycode);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
uint32_t w = 800, h = 480;
|
||||
|
||||
struct waymini *wm = waymini_create(w, h, on_key, NULL);
|
||||
if (!wm) return 1;
|
||||
|
||||
printf("surface: %ux%u stride=%u\n",
|
||||
waymini_get_width(wm), waymini_get_height(wm), waymini_get_stride(wm));
|
||||
|
||||
uint8_t *pixels = (uint8_t *)waymini_get_pixels(wm);
|
||||
if (!pixels) {
|
||||
waymini_destroy(wm);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Fill a simple gradient. Each row is stride bytes. */
|
||||
for (uint32_t y = 0; y < h; y++) {
|
||||
for (uint32_t x = 0; x < w; x++) {
|
||||
size_t i = (size_t)y * waymini_get_stride(wm) + (size_t)x * 4;
|
||||
pixels[i + 0] = (uint8_t)(y * 255 / h); /* B */
|
||||
pixels[i + 1] = 0x00; /* G */
|
||||
pixels[i + 2] = (uint8_t)(x * 255 / w); /* R */
|
||||
pixels[i + 3] = 0xFF; /* A (ignored for XRGB) */
|
||||
}
|
||||
}
|
||||
|
||||
waymini_present(wm);
|
||||
pixels[200001] = 255;
|
||||
|
||||
while (!waymini_should_close(wm)) {
|
||||
if (waymini_dispatch(wm) < 0) break;
|
||||
}
|
||||
|
||||
waymini_destroy(wm);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user