/* * bnxsdl12.c: the part of the SDL 1.2 API that Biniax-2 uses, on top of SDL2, for the fredygames.com * browser build (Emscripten). See bnxsdl12.h. * * The game draws into the "screen" surface of SDL_SetVideoMode (here 32 bits); each SDL_Flip uploads * it to a streaming texture and presents it. * * Copyright (C) 2026 FredyGames. Distributed under the same zlib license as Biniax-2. */ #include "bnxsdl12.h" 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 ("BINIAX-2", 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_RGB888, SDL_TEXTUREACCESS_STREAMING, width, height); screen = SDL_CreateRGBSurfaceWithFormat (0, width, height, 32, SDL_PIXELFORMAT_RGB888); 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 SDL_SetAlpha (SDL_Surface * surface, Uint32 flags, Uint8 alpha) { if (surface == NULL) return -1; if (flags & SDL_SRCALPHA) { SDL_SetSurfaceBlendMode (surface, SDL_BLENDMODE_BLEND); SDL_SetSurfaceAlphaMod (surface, alpha); } else { SDL_SetSurfaceBlendMode (surface, SDL_BLENDMODE_NONE); SDL_SetSurfaceAlphaMod (surface, 255); } return 0; } SDL_Surface * SDL_DisplayFormat (SDL_Surface * surface) { /* like SDL 1.2: the screen's format, without per-pixel alpha */ if (surface == NULL || screen == NULL) return NULL; return SDL_ConvertSurface (surface, screen->format, 0); }