/* * 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(graphical_env_t *ge, scene00_env_t *se) { SDL_Surface *bmpSurf = SDL_LoadBMP("./res/eo1.bmp"); se->eo1 = SDL_CreateTextureFromSurface(ge->sdl_rndr, bmpSurf); SDL_FreeSurface(bmpSurf); return 0; } void scene00_free(graphical_env_t *ge, scene00_env_t *se) { SDL_DestroyTexture(se->eo1); se->eo1=NULL; } int scene00_next(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; SDL_Renderer *r = ge->sdl_rndr; // Local vars int res; // 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); // [...] // Copy the SDL screen to SDL debug window (and display it, not mandatory) SDL_SetRenderTarget(r, NULL); SDL_RenderCopy(r, ge->sdl_target, NULL, NULL); SDL_RenderPresent(r); // Download the rendered texture from videocard to main memory res = SDL_RenderReadPixels(r, NULL, 0, ge->raw_target, 256*4); // "convert" the raw pixel stream to ASCII art on caca canevas if ( res == 0 ) 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; }