examples/text.c
1#include "alba.h"
2
3int main()
4{
5 AlbaWindowOptions options = {0};
6 options.clear_color.r = 0.02;
7 options.clear_color.g = 0.02;
8 options.clear_color.b = 0.02;
9 AlbaWindow* window = alba_create_window(&options);
10
11 const AlbaString text1 = alba_create_string("7 lm francesco ß AVA fi ff", 0);
12 alba_draw_text(window, (AlbaVector){100, 100}, text1, (AlbaTextStyle){.font_size = 28});
13
14 const AlbaString text2 = alba_create_string("Дуо вёжи дёжжэнтиюнт ут हालाँकि प्रचलित रूप पूजा 🍔", 0);
15 alba_draw_text(window, (AlbaVector){100, 150}, text2, (AlbaTextStyle){0});
16
17 const AlbaString text3 = alba_create_string(
18 "DESCRIPTION\n The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free(). The free() function frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc(), calloc(), or realloc(). Otherwise, or if free(ptr) has already been called before, undefined behavior occurs. If ptr is NULL, no operation is performed. The calloc() function allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. The memory is set to zero. If nmemb or size is 0, then calloc() returns either NULL, or a unique pointer value that can later be successfully passed to free(). If the multiplication of nmemb and size would result in integer overflow, then calloc() returns an error. By contrast, an integer overflow would not be detected in the following call to malloc(), with the result that an incorrectly sized block of memory would be allocated: malloc(nmemb * size); The realloc() function changes the size of the memory block pointed to by ptr to size bytes. The contents will be unchanged in the range from the start of the region up to the minimum of the old and new sizes. If the new size is larger than the old size, the added memory will not be initialized. If ptr is NULL, then the call is equivalent to malloc(size), for all values of size; if size is equal to zero, and ptr is not NULL, then the call is equivalent to free(ptr). Unless ptr is NULL, it must have been returned by an earlier call to malloc(), calloc(), or realloc(). If the area pointed to was moved, a free(ptr) is done. The reallocarray() function changes the size of the memory block pointed to by ptr to be large enough for an array of nmemb elements, each of which is size bytes. It is equivalent to the call realloc(ptr, nmemb * size); However, unlike that realloc() call, reallocarray() fails safely in the case where the multiplication would overflow. If such an overflow occurs, reallocarray() returns NULL, sets errno to ENOMEM, and leaves the original block of memory unchanged. RETURN VALUE The malloc() and calloc() functions return a pointer to the allocated memory, which is suitably aligned for any built-in type. On error, these functions return NULL. N",
19 0
20 );
21 alba_draw_text(window, (AlbaVector){100, 200}, text3, (AlbaTextStyle){0});
22
23 while (!alba_window_should_close(window))
24 {
25 alba_window_render(window);
26 }
27
28 alba_string_release(&text1);
29 alba_string_release(&text2);
30 alba_string_release(&text3);
31
32 alba_window_release(window);
33 alba_release();
34}