mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
This commit is contained in:
parent
bafbeabf95
commit
ed0c40533f
@ -119,12 +119,12 @@ void CBitmap32::QuadInstance::putToGL() const
|
||||
|
||||
/*********** CBitmap32 ***********/
|
||||
|
||||
CBitmap32::CBitmap32(ui32 w, ui32 h, const ColorRGB pixBuff[]) : CImage(w, h)
|
||||
CBitmap32::CBitmap32(ui32 w, ui32 h, const ColorRGB pixBuff[], bool bgra) : CImage(w, h), formatBGRA(bgra)
|
||||
{
|
||||
const ui32 size = w * h;
|
||||
buffer = new ColorRGBA[size];
|
||||
const ui32 pixNum = w * h;
|
||||
buffer = new ColorRGBA[pixNum];
|
||||
|
||||
for (ui32 it=0; it<size; ++it)
|
||||
for (ui32 it=0; it<pixNum; ++it)
|
||||
{
|
||||
memcpy(&buffer[it], &pixBuff[it], 3);
|
||||
buffer[it].comp.A = 255;
|
||||
@ -132,6 +132,15 @@ CBitmap32::CBitmap32(ui32 w, ui32 h, const ColorRGB pixBuff[]) : CImage(w, h)
|
||||
}
|
||||
|
||||
|
||||
CBitmap32::CBitmap32(ui32 w, ui32 h, const ColorRGBA pixBuff[], bool bgra) : CImage(w, h), formatBGRA(bgra)
|
||||
{
|
||||
const ui32 pixNum = w * h;
|
||||
buffer = new ColorRGBA[pixNum];
|
||||
|
||||
memcpy(buffer, pixBuff, pixNum * sizeof(ColorRGBA));
|
||||
}
|
||||
|
||||
|
||||
CBitmap32::~CBitmap32()
|
||||
{
|
||||
delete buffer;
|
||||
@ -140,7 +149,7 @@ CBitmap32::~CBitmap32()
|
||||
|
||||
void CBitmap32::textureTransfer()
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
|
||||
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA8, width, height, 0, formatBGRA ? GL_BGRA : GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
||||
}
|
||||
|
||||
|
||||
@ -176,7 +185,7 @@ void CBitmap32::putAt(Point p, TransformFlags flags)
|
||||
void CBitmap32::putAt(Point p, TransformFlags flags, float scale)
|
||||
{
|
||||
QuadInstance qi(p);
|
||||
qi.transform(flags, width, height, width*scale, height*scale);
|
||||
qi.transform(flags, width, height, (ui32)(width*scale), (ui32)(height*scale));
|
||||
|
||||
GL2D::useNoShader();
|
||||
bindTexture();
|
||||
@ -325,7 +334,7 @@ void CPalettedBitmap::putAt(Point p, TransformFlags flags, float scale)
|
||||
GL2D::assignTexture(GL_TEXTURE1, GL_TEXTURE_1D, palette.getTexHandle());
|
||||
GL2D::assignTexture(GL_TEXTURE0, GL_TEXTURE_RECTANGLE, texHandle);
|
||||
GL2D::usePaletteBitmapShader(p.x, p.y);
|
||||
glRecti(p.x, p.y, p.x + width*scale, p.y + height*scale);
|
||||
glRecti(p.x, p.y, p.x + (ui32)(width*scale), p.y + (ui32)(height*scale));
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,6 +78,7 @@ class CBitmap32 : public CImage
|
||||
{
|
||||
friend class CImage;
|
||||
ColorRGBA* buffer;
|
||||
bool formatBGRA;
|
||||
|
||||
struct CoordBind {
|
||||
Point texture, vertex;
|
||||
@ -95,7 +96,8 @@ class CBitmap32 : public CImage
|
||||
};
|
||||
|
||||
protected:
|
||||
CBitmap32(ui32 w, ui32 h, const ColorRGB pixBuff[]); // 24bit RGB source
|
||||
CBitmap32(ui32 w, ui32 h, const ColorRGB pixBuff[], bool bgra = true); // 24bit RGB source
|
||||
CBitmap32(ui32 w, ui32 h, const ColorRGBA pixBuff[], bool bgra = true); // 32bit RGBA source
|
||||
virtual void textureTransfer();
|
||||
|
||||
public:
|
||||
|
@ -19,6 +19,7 @@ CImage * CImage::makeBySDL(void* data, size_t fileSize, const char* fileExt)
|
||||
const_cast<char*>(fileExt)); //pass extension without dot (+1 character)
|
||||
if (ret)
|
||||
{
|
||||
CImage * img;
|
||||
if (ret->format->palette)
|
||||
{
|
||||
//set correct value for alpha\unused channel
|
||||
@ -26,11 +27,22 @@ CImage * CImage::makeBySDL(void* data, size_t fileSize, const char* fileExt)
|
||||
ret->format->palette->colors[i].unused = 255;
|
||||
|
||||
CPaletteRGBA* pal = new CPaletteRGBA((ColorRGBA*)ret->format->palette->colors);
|
||||
return new CPalettedBitmap(ret->w, ret->h, *pal, (ui8*)ret->pixels);
|
||||
img = new CPalettedBitmap(ret->w, ret->h, *pal, (ui8*)ret->pixels);
|
||||
}
|
||||
else if (ret->format->BytesPerPixel == 3)
|
||||
{
|
||||
img = new CBitmap32(ret->w, ret->h, (ColorRGB*)ret->pixels);
|
||||
}
|
||||
else if (ret->format->BytesPerPixel == 4)
|
||||
{
|
||||
img = new CBitmap32(ret->w, ret->h, (ColorRGBA*)ret->pixels);
|
||||
}
|
||||
|
||||
return new CBitmap32(ret->w, ret->h, (ColorRGB*)ret->pixels);
|
||||
SDL_FreeSurface(ret);
|
||||
return img;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,7 +50,7 @@ PImage CManager::getImage(const std::string& fname)
|
||||
|
||||
if (img_tmp == nullptr)
|
||||
{
|
||||
tlog1 << "Iage " << fname << " not loaded!\n";
|
||||
tlog1 << "Image " << fname << " not loaded!\n";
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user