Browse Source

texture alpha/color mods

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
3b2479c791
2 changed files with 43 additions and 1 deletions
  1. 5
    1
      core.mod/src/entities/EntItemStack.cc
  2. 38
    0
      libswan/include/swan/gfxutil.h

+ 5
- 1
core.mod/src/entities/EntItemStack.cc View File

@@ -17,7 +17,11 @@ EntItemStack::EntItemStack(const Swan::Context &ctx, const Swan::SRF &params):

void EntItemStack::draw(const Swan::Context &ctx, Swan::Win &win) {
SDL_Rect rect = item_->image_.frameRect();
win.showTexture(body_.pos_, item_->image_.texture_.get(), &rect,

SDL_Texture *tex = item_->image_.texture_.get();
Swan::TexColorMod darken(tex, 220, 220, 220);

win.showTexture(body_.pos_, tex, &rect,
{ .hscale = 0.5, .vscale = 0.5 });
}


+ 38
- 0
libswan/include/swan/gfxutil.h View File

@@ -28,4 +28,42 @@ private:
RaiiPtr<SDL_Surface> surf_ = makeRaiiPtr<SDL_Surface>(nullptr, SDL_FreeSurface);
};

class TexColorMod {
public:
TexColorMod(const TexColorMod &) = delete;
TexColorMod(TexColorMod &&) = delete;

TexColorMod(SDL_Texture *tex, uint8_t r, uint8_t g, uint8_t b): tex_(tex) {
SDL_GetTextureColorMod(tex_, &r_, &g_, &b_);
SDL_SetTextureColorMod(tex_, r, g, b);
}

~TexColorMod() {
SDL_SetTextureColorMod(tex_, r_, g_, b_);
}

private:
SDL_Texture *tex_;
uint8_t r_, g_, b_;
};

class TexAlphaMod {
public:
TexAlphaMod(const TexAlphaMod &) = delete;
TexAlphaMod(TexAlphaMod &&) = delete;

TexAlphaMod(SDL_Texture *tex, uint8_t alpha): tex_(tex) {
SDL_GetTextureAlphaMod(tex_, &alpha_);
SDL_SetTextureAlphaMod(tex_, alpha);
}

~TexAlphaMod() {
SDL_SetTextureAlphaMod(tex_, alpha_);
}

private:
SDL_Texture *tex_;
uint8_t alpha_;
};

}

Loading…
Cancel
Save