1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* demoscene-eo, an ASCII art demoscene written as a gift for Emmanuel Otton retirement
* Copyright (C) 2019 XXXXXX XXXXXXX <xxxxxx@xxxxxx.fr>
*
* 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 <http://www.gnu.org/licenses/>
*/
#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;
}
|