From 2efc9022bf064136bb7cd25bd59971f2b419ff48 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 27 Nov 2022 18:53:12 +0100 Subject: Switch completely to SDL2 version The now legacy version of LimoX with GTK4 and libstrophe is now not part of the main branch anymore. There might be a legacy branch keeping this version at the time of reading. This cut of implemented functionality is motivated by these reasons: - Implementing XMPP is fun, educative and gives full control. - Low level graphics with SDL2 is portable, fast, educative an mature. - I do not have to use GLib and a crazy event loop anymore (run and hide) --- gui.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 gui.c (limited to 'gui.c') diff --git a/gui.c b/gui.c new file mode 100644 index 0000000..04a53b3 --- /dev/null +++ b/gui.c @@ -0,0 +1,65 @@ + + +/* mention the SDL2 documentation at http://wiki.libsdl.org/APIByCategory */ + + +#include +#include + + +void gui_run(void) { + + bool quit = false; + SDL_Event event; + SDL_Window* window; + SDL_Renderer* renderer; + SDL_Texture* texture; + uint32_t* pixels; + + // init SDL2 and create window + SDL_Init(SDL_INIT_VIDEO); + window = SDL_CreateWindow("LimoX", + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, + 0 + ); + + // output video driver to stderr + fprintf(stderr, "SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver()); + + // create and initialize renderer, texture and pixel buffer + renderer = SDL_CreateRenderer(window, -1, 0); + texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STATIC, 640, 480); + pixels = malloc(sizeof(uint32_t) * 640 * 480); + memset(pixels, 255, 640 * 480 * sizeof(uint32_t)); + + // handle failed window creation + if (window == NULL) { + fprintf(stderr, "Failed to create SDL2 window!\n"); + return; + } else { + while (!quit) { + SDL_UpdateTexture(texture, NULL, pixels, 640 * sizeof(uint32_t)); + SDL_WaitEvent(&event); + switch (event.type) + { + case SDL_QUIT: + quit = true; + break; + } + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, texture, NULL, NULL); + SDL_RenderPresent(renderer); + } + SDL_DestroyWindow(window); + } + + free(pixels); + + // TODO this seems to end in memory access errors but ... why? + //SDL_DestroyTexture(texture); + //SDL_DestroyRenderer(renderer); + + SDL_Quit(); + +} -- cgit v1.2.3-70-g09d2