mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
restore outfit colors
* rework sprite manager and ThingType * render colored outfits again compatible with OpenGL 1
This commit is contained in:
@@ -31,7 +31,8 @@ Image::Image(const Size& size, int bpp, uint8 *pixels)
|
||||
m_size = size;
|
||||
m_bpp = bpp;
|
||||
m_pixels.resize(size.area() * bpp);
|
||||
memcpy(&m_pixels[0], pixels, m_pixels.size());
|
||||
if(pixels)
|
||||
memcpy(&m_pixels[0], pixels, m_pixels.size());
|
||||
}
|
||||
|
||||
ImagePtr Image::load(const std::string& file)
|
||||
@@ -62,3 +63,23 @@ ImagePtr Image::loadPNG(const std::string& file)
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
void Image::overwriteMask(const Color& maskedColor, const Color& insideColor, const Color& outsideColor)
|
||||
{
|
||||
assert(m_bpp == 4);
|
||||
|
||||
for(int p=0;p<getPixelCount();p++) {
|
||||
uint8& r = m_pixels[p*4 + 0];
|
||||
uint8& g = m_pixels[p*4 + 1];
|
||||
uint8& b = m_pixels[p*4 + 2];
|
||||
uint8& a = m_pixels[p*4 + 3];
|
||||
|
||||
Color pixelColor(r,g,b,a);
|
||||
Color writeColor = (pixelColor == maskedColor) ? insideColor : outsideColor;
|
||||
|
||||
r = writeColor.r();
|
||||
g = writeColor.g();
|
||||
b = writeColor.b();
|
||||
a = writeColor.a();
|
||||
}
|
||||
}
|
||||
|
@@ -29,13 +29,19 @@
|
||||
class Image
|
||||
{
|
||||
public:
|
||||
Image(const Size& size, int bpp, uint8 *pixels);
|
||||
Image(const Size& size, int bpp = 4, uint8 *pixels = nullptr);
|
||||
|
||||
static ImagePtr load(const std::string& file);
|
||||
static ImagePtr loadPNG(const std::string& file);
|
||||
|
||||
const std::vector<uint8>& getPixels() { return m_pixels; }
|
||||
void overwriteMask(const Color& maskedColor, const Color& insideColor = Color::white, const Color& outsideColor = Color::alpha);
|
||||
|
||||
std::vector<uint8>& getPixels() { return m_pixels; }
|
||||
uint8* getPixelData() { return &m_pixels[0]; }
|
||||
int getPixelCount() { return m_size.area(); }
|
||||
const Size& getSize() { return m_size; }
|
||||
int getWidth() { return m_size.width(); }
|
||||
int getHeight() { return m_size.height(); }
|
||||
int getBpp() { return m_bpp; }
|
||||
|
||||
private:
|
||||
|
@@ -23,12 +23,18 @@
|
||||
#include "texture.h"
|
||||
#include "graphics.h"
|
||||
#include "framebuffer.h"
|
||||
#include "image.h"
|
||||
|
||||
Texture::Texture()
|
||||
{
|
||||
m_textureId = 0;
|
||||
}
|
||||
|
||||
Texture::Texture(const ImagePtr& image)
|
||||
{
|
||||
internalLoadGLTexture(image->getPixelData(), image->getBpp(), image->getWidth(), image->getHeight());
|
||||
}
|
||||
|
||||
Texture::Texture(int width, int height, int channels, uchar *pixels)
|
||||
{
|
||||
// generate opengl texture
|
||||
|
@@ -29,6 +29,7 @@ class Texture : public std::enable_shared_from_this<Texture>
|
||||
{
|
||||
public:
|
||||
Texture();
|
||||
Texture(const ImagePtr& image);
|
||||
Texture(int width, int height, int channels, uchar* pixels = NULL);
|
||||
virtual ~Texture();
|
||||
|
||||
|
Reference in New Issue
Block a user