/* * demoscene-eo, an ASCII art demoscene written as a gift for Emmanuel Otton retirement * Copyright (C) 2019 XXXXXX XXXXXXX * * This file is part of demoscene-eo. * * demoscene-eo is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * demoscene-eo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with demoscene-eo. If not, see */ #include "scene00.h" int scene00_init_gl(graphical_env_t *ge, scene00_env_t *se) { TRACE("call"); return 0; } int scene00_init_sdl(graphical_env_t *ge, scene00_env_t *se) { TRACE("call"); SDL_Surface *bmpSurf = SDL_LoadBMP("./res/eo1.bmp"); se->eo1 = SDL_CreateTextureFromSurface(ge->sdl_rndr, bmpSurf); SDL_FreeSurface(bmpSurf); return 0; } int scene00_init_caca(graphical_env_t *ge, scene00_env_t *se) { TRACE("call"); return 0; } void scene00_free_gl(graphical_env_t *ge, scene00_env_t *se) { TRACE("call"); } void scene00_free_sdl(graphical_env_t *ge, scene00_env_t *se) { TRACE("call"); SDL_DestroyTexture(se->eo1); se->eo1=NULL; } void scene00_free_caca(graphical_env_t *ge, scene00_env_t *se) { TRACE("call"); } int scene00_next_gl(graphical_env_t *ge, scene00_env_t *se) { TRACE_CALL_ONCE; return 0; } int scene00_next_sdl(graphical_env_t *ge, scene00_env_t *se) { // Shorthands SDL_Renderer *r = ge->sdl_rndr; TRACE_CALL_ONCE; // https://gist.github.com/Twinklebear/8265888 // https://forums.libsdl.org/viewtopic.php?p=51634 // Render all the stuff on target texture SDL_SetRenderTarget(r, ge->sdl_target); SDL_RenderCopy(r, se->eo1, NULL, NULL); // [...] #ifdef DEBUG // Copy the target texture to SDL debug window (and display it, not mandatory) SDL_SetRenderTarget(r, NULL); SDL_RenderCopy(r, ge->sdl_target, NULL, NULL); SDL_RenderPresent(r); SDL_SetRenderTarget(r, ge->sdl_target); #endif // Download the rendered texture from videocard to main memory SDL_RenderReadPixels(r, NULL, 0, ge->raw_target, FBUF_W*4); return 0; } int scene00_next_caca(graphical_env_t *ge, scene00_env_t *se) { // Shorthands caca_canvas_t *cv = ge->cv; int w = ge->w, h = ge->h; Uint32 frame = ge->sc_framecount; TRACE_CALL_ONCE; // "convert" the raw pixel stream from SDL to ASCII art on caca canevas caca_dither_bitmap(cv, 0, 0, w, h, ge->d, ge->raw_target); // Add things on top of caca canvas caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE); caca_put_str(cv, (w-17)/2, h/2, "This is a message"); caca_draw_line(cv,6,6,w-14,11, '*'); caca_draw_thin_line(cv,frame%10,frame%10,w-10+frame%10,h-10+frame%10); if (frame >= 100) { return 1; } return 0; }