• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

How i can active Transparence

Yoah, nice.
So, show us your mapeditor, otitemeditor, sprite editor compatible with this sprite format.
Then we'll add it to otclient :)
 
I got a custom type of sprite editor. It save in alpha code, and not alpha code. I use with NO alpha code in mapeditor and itemeditor. And ALPHA CODE on client.
So its just a sprite editor who save on alpha code, btw... it dont have source :/
 
Code:
while(read < pixelDataSize && writePos < SPRITE_DATA_SIZE) {
            uint16 transparentPixels = m_spritesFile->getU16();
            uint16 coloredPixels = m_spritesFile->getU16();

            for(int i = 0; i < transparentPixels && writePos < SPRITE_DATA_SIZE; i++) {
                pixels[writePos + 0] = 0x00;
                pixels[writePos + 1] = 0x00;
                pixels[writePos + 2] = 0x00;
                pixels[writePos + 3] = 0x00;
                writePos += 4;
            }

            for(int i = 0; i < coloredPixels && writePos < SPRITE_DATA_SIZE; i++) {
                pixels[writePos + 0] = m_spritesFile->getU8();
                pixels[writePos + 1] = m_spritesFile->getU8();
                pixels[writePos + 2] = m_spritesFile->getU8();
                pixels[writePos + 3] = 0xFF;
                writePos += 4;
            }

            read += 4 + (3 * coloredPixels);
        }
this needs to be changed

changing
Code:
for(int i = 0; i < coloredPixels && writePos < SPRITE_DATA_SIZE; i++) {
                pixels[writePos + 0] = m_spritesFile->getU8();
                pixels[writePos + 1] = m_spritesFile->getU8();
                pixels[writePos + 2] = m_spritesFile->getU8();
                pixels[writePos + 3] = 0xFF;
                writePos += 4;
            }
to
Code:
for(int i = 0; i < coloredPixels && writePos < SPRITE_DATA_SIZE; i++) {
                pixels[writePos + 0] = m_spritesFile->getU8();
                pixels[writePos + 1] = m_spritesFile->getU8();
                pixels[writePos + 2] = m_spritesFile->getU8();
                pixels[writePos + 3] = m_spritesFile->getU8();
                writePos += 4;
            }
(or
Code:
for(int i = 0; i < coloredPixels && writePos < SPRITE_DATA_SIZE; i++) 
		{
                for(int j=0; j<4; j++)
				{
					pixels[writePos + j] = m_spritesFile->getU8();
				}
                writePos += 4;
        }
, but it really doesn't matter) and
Code:
read += 4 + (3 * coloredPixels);
to
Code:
 read += 4 + (4 * coloredPixels);
it CAN work as long as format is close enough
(so, if format contains additional alpha channel it should work if I understand the format of array returned by getPixelData()


But if you want to help devs then you have to make some check to determine spr format and use method fitting the format, code made this way can be included in main branch

edited for compressed format, closer to the original
 
Last edited:
Then we've no idea how your spr format looks like.
If you ever find out, share your editor, code it as a Game Feature and make a pull request to otclient.

Edit:
Aw man, you gave it so easy.

Code:
for(int i = 0; i < transparentPixels && writePos < SPRITE_DATA_SIZE; i++) {
                pixels[writePos + 0] = 0x00;
                pixels[writePos + 1] = 0x00;
                pixels[writePos + 2] = 0x00;
                pixels[writePos + 3] = 0x00;
                writePos += 4;
            }

This should stay. It's part of compression.
 
well, this one can be usefull for fully transparent pixels, as it doesn't have to contain all (in this case)4 channels
umm..., so this part should stay, and the last one also I guess ;d
 
Also, there're that 3 bytes before each sprite.
Maybe add a new one, to check if it uses transparency or not.
If we do this your way, it'll increase spr file about 20mb.

Edit:
You'll be lucky if it works, cause we've no idea how your format looks like.
I wouldnt do this zakius' way.
 
adding fourth channel with the same avg not_fully_transparent pixels count would increase spr size by about 1/3 I guess...
and there can be some mistakes in my way, I just looked at the code and it seems to be pretty easy :D
as there are 3 variables read and one set to 255 in normal way then pixels array stores 4 channels already, so we just have to read fourth one right?

in original format there are
Code:
// skip color key
        m_spritesFile->getU8();
        m_spritesFile->getU8();
        m_spritesFile->getU8();
, but new one doesn't really have to contain fourth one here as it is skipped anyway, maybe
Code:
SPRITE_DATA_SIZE = SPRITE_SIZE*SPRITE_SIZE*4
should be changed, the SPRITE_DATA_SIZE possibly should be increased, but as it is already 4 I don't really know wth
(and if we are here already, shouldn't the 4 in
Code:
m_spritesFile->seek(((id-1) * 4) + m_spritesOffset);
be changed to some const depending on spr format after the change?)
 
Last edited:
Yeah, there are some ints that have to be changedd and we don't know your format yet, I just assumed what would be easiest to do
BEWARE: RETARDS GUESS BELOW THIS LINE
---------------------------------------------------
change both 4 to 5
--------------------------------------------------
end of plain guessing, if it will work then I'm genius or complete idiot :D
 
Compiling = 100% without errors But in game :

View attachment 18993

That was expected, we don't know how your format is or if it was even done correctly.

Zakius, your code is fine.
It's just not optimized.

Code:
for(int i = 0; i < coloredPixels && writePos < SPRITE_DATA_SIZE; i++) 
		{
                for(int j=0; j<4; j++)
				{
					pixels[writePos + j] = m_spritesFile->getU8();
				}
                writePos += 4;
        }

This for ain't good. Sometimes it's better to have a few lines more than a line less but harder to understand.
 
after editing that post it should support original format compression (x, x, x, 0 doesn't have to contain 4 numbers)
and that loop, yeah, it contains the same number of lines, just few chars less :D
it was just as alternative
ok, SPRITE_DATA_SIZE should stay as 4, but is 4 in seeking good?
 
just a question

i'm make it correct

Baxnie mode dont work too D;
Code:
#include "spritemanager.h"
#include "game.h"
#include <framework/core/resourcemanager.h>
#include <framework/core/filestream.h>
#include <framework/graphics/image.h>

SpriteManager g_sprites;

SpriteManager::SpriteManager()
{
    m_spritesCount = 0;
    m_signature = 0;
}

void SpriteManager::terminate()
{
    unload();
}

bool SpriteManager::loadSpr(std::string file)
{
    m_spritesCount = 0;
    m_signature = 0;
    m_loaded = false;
    try {
        file = g_resources.guessFilePath(file, "spr");

        m_spritesFile = g_resources.openFile(file);
        // cache file buffer to avoid lags from hard drive
        m_spritesFile->cache();

        m_signature = m_spritesFile->getU32();
        m_spritesCount = g_game.getFeature(Otc::GameSpritesU32) ? m_spritesFile->getU32() : m_spritesFile->getU16();
        m_spritesOffset = m_spritesFile->tell();
        m_loaded = true;
        return true;
    } catch(stdext::exception& e) {
        g_logger.error(stdext::format("Failed to load sprites from '%s': %s", file, e.what()));
        return false;
    }
}

void SpriteManager::unload()
{
    m_spritesCount = 0;
    m_signature = 0;
    m_spritesFile = nullptr;
}

ImagePtr SpriteManager::getSpriteImage(int id)
{
    try {
        enum {
            SPRITE_SIZE = 32,
            SPRITE_DATA_SIZE = SPRITE_SIZE*SPRITE_SIZE*4
        };

        if(id == 0 || !m_spritesFile)
            return nullptr;

        m_spritesFile->seek(((id-1) * 4) + m_spritesOffset);

        uint32 spriteAddress = m_spritesFile->getU32();

        // no sprite? return an empty texture
        if(spriteAddress == 0)
            return nullptr;

        m_spritesFile->seek(spriteAddress);

        // skip color key
        m_spritesFile->getU8();
        m_spritesFile->getU8();
        m_spritesFile->getU8();

        uint16 pixelDataSize = m_spritesFile->getU16();

        ImagePtr image(new Image(Size(SPRITE_SIZE, SPRITE_SIZE)));

        uint8 *pixels = image->getPixelData();
        int writePos = 0;
        int read = 0;

        // decompress pixels
        while(read < pixelDataSize && writePos < SPRITE_DATA_SIZE) {
            uint16 coloredPixels = m_spritesFile->getU16();
            uint16 transparentPixels = m_spritesFile->getU16();

        for(int i = 0; i < transparentPixels && writePos < SPRITE_DATA_SIZE; i++) {
                pixels[writePos + 0] = 0x00;
                pixels[writePos + 1] = 0x00;
                pixels[writePos + 2] = 0x00;
                pixels[writePos + 3] = 0x00;
                writePos += 4;
            }

        for(int i = 0; i < coloredPixels && writePos < SPRITE_DATA_SIZE; i++)
		{
                for(int j=0; j<4; j++)
				{
					pixels[writePos + j] = m_spritesFile->getU8();
				}
                writePos += 4;
        }

            read += 4 + (4 * coloredPixels);
        }

        // fill remaining pixels with alpha
        while(writePos < SPRITE_DATA_SIZE) {
            pixels[writePos + 0] = 0x00;
            pixels[writePos + 1] = 0x00;
            pixels[writePos + 2] = 0x00;
            pixels[writePos + 3] = 0x00;
            writePos += 4;
        }

        return image;
    } catch(stdext::exception& e) {
        g_logger.error(stdext::format("Failed to get sprite id %d: %s", id, e.what()));
        return nullptr;
    }
}
 
it is the same as without loop
explain us your format or else we won't be able to help
 
Last edited:
in this case, could you send ust the spr file?
if it is any good format then it can become official, if not then possibly someone can convert it
 
Back
Top