/* * nikwi-sdl12.c: the part of the SDL 1.2 API that Nikwi Deluxe uses, on top of SDL2, for the * fredygames.com browser build (Emscripten). See nikwi-sdl12.h. * * The game draws into the "screen" surface of SDL_SetVideoMode (here a 16-bit RGB565 surface in memory, * which is what the game's own graphics code assumes); each SDL_Flip uploads it to a streaming texture * and presents it. * * Copyright (C) 2026 FredyGames. Distributed under the same zlib license as Nikwi Deluxe's src/. */ #include "nikwi-sdl12.h" #undef SDL_PollEvent static SDL_Window *window = NULL; static SDL_Renderer *renderer = NULL; static SDL_Texture *texture = NULL; static SDL_Surface *screen = NULL; SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags) { (void) bpp; (void) flags; if (window == NULL) { window = SDL_CreateWindow ("Nikwi", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0); if (window == NULL) return NULL; renderer = SDL_CreateRenderer (window, -1, 0); if (renderer == NULL) return NULL; } if (texture != NULL) SDL_DestroyTexture (texture); if (screen != NULL) SDL_FreeSurface (screen); texture = SDL_CreateTexture (renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height); screen = SDL_CreateRGBSurfaceWithFormat (0, width, height, 16, SDL_PIXELFORMAT_RGB565); return screen; } int SDL_Flip (SDL_Surface * surface) { if (surface != screen || texture == NULL) return -1; SDL_UpdateTexture (texture, NULL, screen->pixels, screen->pitch); SDL_RenderClear (renderer); SDL_RenderCopy (renderer, texture, NULL, NULL); SDL_RenderPresent (renderer); return 0; } void SDL_WM_SetCaption (const char *title, const char *icon) { (void) icon; if (window != NULL && title != NULL) SDL_SetWindowTitle (window, title); } int nikwi_PollEvent (SDL_Event * event) { while (SDL_PollEvent (event)) { if (event->type == SDL_KEYDOWN && event->key.repeat) continue; return 1; } return 0; }