|
- #include "sdl_effect.h"
-
- /*
- static const uint8_t the_effect[3][3][4] = {
- {{14, 0, 216, 204}, {16, 0, 0, 217}, {21, 225, 1, 0},},
- {{81, 0, 1, 1}, {83, 1, 0, 3}, {72, 2, 0, 0},},
- {{ 5, 0, 252, 245}, { 6, 0, 0, 243}, {10, 236, 1, 0},},
- };
-
- static const int effect_w = 3;
- static const int effect_h = 3;
- */
-
- static const uint8_t the_effect[2][2][4] = {
- {{ 25, 0, 0, 0}, { 1, 0, 0, 0},},
- {{144, 0, 0, 0}, {133, 0, 0, 0},},
- };
-
- static const int effect_w = 2;
- static const int effect_h = 2;
-
-
- sdl_effect* effect_init(SDL_Renderer* renderer,
- int view_w, int view_h) {
- const int tex_w = view_w * 2;
- const int tex_h = view_h * 2;
-
- SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
-
- SDL_Texture* effect = SDL_CreateTexture(
- renderer, SDL_PIXELFORMAT_BGRA8888,
- SDL_TEXTUREACCESS_STREAMING, tex_w, tex_h
- );
-
- void* pixels = NULL;
- int pitch = 0;
- SDL_LockTexture(effect, NULL, &pixels, &pitch);
-
- uint8_t* dst_line = (uint8_t*)pixels;
- for (int y = 0; y < tex_h; ++y) {
- uint8_t* dst = dst_line;
- for (int x = 0; x < tex_w; ++x) {
- dst[0] = the_effect[y % effect_h][x % effect_w][0];
- dst[1] = the_effect[y % effect_h][x % effect_w][1];
- dst[2] = the_effect[y % effect_h][x % effect_w][2];
- dst[3] = the_effect[y % effect_h][x % effect_w][3];
- dst += 4;
- }
- dst_line += pitch;
- }
-
- SDL_UnlockTexture(effect);
-
- SDL_SetTextureBlendMode(effect, SDL_BLENDMODE_BLEND);
-
- return (sdl_effect*)effect;
- }
-
- void effect_done(sdl_effect* effect) {
- if (effect) {
- SDL_DestroyTexture((SDL_Texture*)effect);
- }
- }
-
- void effect_apply(sdl_effect* effect, SDL_Renderer* renderer,
- const SDL_Rect* rect) {
- if (effect) {
- SDL_RenderCopy(renderer, (SDL_Texture*)effect,
- NULL, rect);
- }
- }
|