Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprite Not Showing Up... #28

Open
Rubberduckycooly opened this issue Jun 16, 2018 · 2 comments
Open

Sprite Not Showing Up... #28

Rubberduckycooly opened this issue Jun 16, 2018 · 2 comments

Comments

@Rubberduckycooly
Copy link

I Have Created a Loader to load .gif images that is based off src_lib\loadbitmap.h but when i load a sprite using this method, nothing is displayed...

When i check the values the width, height, bit_depth and palette are all correct and assigned but the image still isn't showing up...

Here is My Code (I am using gif_lib (http://giflib.sourceforge.net) to get the data for the .gif images):

#include "..\src\GifLib\gif_lib.h"

static TLN_Bitmap LoadGIF(const char* filename)
{
	//Init
	TLN_Bitmap bitmap = NULL;
	GifFileType* Gif = DGifOpenFileName(filename, 0);
	DGifSlurp(Gif);

	//General Gif Values
	int width = Gif->Image.Width; std::cout << "Image Width = " << width << std::endl;
	int height = Gif->Image.Height; std::cout << "Image Height = " << height << std::endl;
	int bit_depth = Gif->SColorResolution; std::cout << "Colour = " << bit_depth << std::endl;

	bitmap = TLN_CreateBitmap(width, height, bit_depth);

	//Load ScanLines
	int pitch = TLN_GetBitmapPitch(bitmap);
	int l;

	for (l = 0; l<height; l++)
	{
		uint8_t* line = TLN_GetBitmapPtr(bitmap, 0, l);
	}

	//Colour Palette Values
	TLN_Palette pal;

	int palette_entries = Gif->SColorMap->ColorCount;
	int c;
	pal = TLN_CreatePalette(palette_entries);
	std::cout << palette_entries << std::endl;
	for (c = 0; c < palette_entries; c++)
	{
		TLN_SetPaletteColor(pal, c, Gif->SColorMap->Colors[c].Red, Gif->SColorMap->Colors[c].Green, Gif->SColorMap->Colors[c].Blue);
	}
	TLN_SetBitmapPalette(bitmap, pal);

	/* bitmap loaded */
	if (bitmap)
	{
		/* accept only 8 bpp */
		int bpp = TLN_GetBitmapDepth(bitmap);
		if (bpp == 8)
			TLN_SetLastError(TLN_ERR_OK);
		else
		{
			TLN_DeleteBitmap(bitmap);
			bitmap = NULL;
		}
	}

	if (!bitmap)
		TLN_SetLastError(TLN_ERR_WRONG_FORMAT);

	return bitmap;
}
@megamarc
Copy link
Owner

I haven't tried the sample but the code seems correct.
BUT: what you're loading is a TLN_Bitmap and then you complain about sprites not showing up. I think there's a confusion here. To show sprites, you need a TLN_Spriteset object. A spriteset contains a bitmap and other information. I'm afraid you're mismatching resource types. Could you post the code that calls and uses your LoadGIF function? I guess the error is there.

@Rubberduckycooly
Copy link
Author

Rubberduckycooly commented Jun 24, 2018

This Bit of code load the sprite sheet:

TLN_Bitmap b = PSDK::SpriteSheet::LoadGIF(DFM->GetItemFromData("data/Sonic1.gif").c_str());
TLN_SpriteData* sd = new TLN_SpriteData(); sd->x = sd->y = 1; sd->w = 28; sd->h = 40;
TLN_Spriteset spriteset = TLN_CreateSpriteset(b, sd, 1);
//TLN_SetSpritePalette(0, pal->Palettes[pal->curPalette]);
TLN_SetSpriteSet(0, spriteset);
TLN_ConfigSprite(0, spriteset, TLN_TileFlags::FLAG_NONE);
TLN_SetSpritePicture(0, 0);
TLN_SetSpritePicture(0, 0);
TLN_SetSpritePosition(0, 50, 50);

and this bit is the full class that handles it:
class SpriteSheet
{
public:
SpriteSheet(const char* path)
{
spriteSheet = LoadGIF(path);
palette = TLN_GetBitmapPalette(spriteSheet);
}
~SpriteSheet() {}

static TLN_Bitmap LoadGIF(const char* filename)
{
	//Init
	TLN_Bitmap bitmap = NULL;
	GifFileType* Gif = DGifOpenFileName(filename, 0);
	DGifSlurp(Gif);
	FILE* img;

	/* open file */
	img = fopen(filename, "r");
	if (!img)
		return NULL;

	//General Gif Values
	int width = Gif->Image.Width; std::cout << "Image Width = " << width << std::endl;
	int height = Gif->Image.Height; std::cout << "Image Height = " << height << std::endl;
	int bit_depth = Gif->SColorResolution; std::cout << "Colour = " << bit_depth << std::endl;

	bitmap = TLN_CreateBitmap(width, height, bit_depth);

	//Load ScanLines
	int pitch = TLN_GetBitmapPitch(bitmap);
	int l;
	std::vector<int> Lines;
	GifPixelType* gifline = new GifPixelType(); 

	for (l = 0; l < height; l++)
	{
		//Lines.push_back(DGifGetLine(Gif, gifline, width));
		uint8_t* line = TLN_GetBitmapPtr(bitmap, 0, height - l - 1);
		fread(line, pitch, 1, img);
		std::cout << l << std::endl;
	}

	//Colour Palette Values
	TLN_Palette pal;

	int palette_entries = Gif->SColorMap->ColorCount;
	int c;
	pal = TLN_CreatePalette(palette_entries);
	std::cout << palette_entries << std::endl;
	for (c = 0; c < palette_entries; c++)
	{
		TLN_SetPaletteColor(pal, c, Gif->SColorMap->Colors[c].Red, Gif->SColorMap->Colors[c].Green, Gif->SColorMap->Colors[c].Blue);
		std::cout << "R = " << (int)Gif->SColorMap->Colors[c].Red << " G = " << (int)Gif->SColorMap->Colors[c].Green << " B = " << (int)Gif->SColorMap->Colors[c].Blue << std::endl;
	}
	TLN_SetBitmapPalette(bitmap, pal);

	/* bitmap loaded */
	if (bitmap)
	{
		/* accept only 8 bpp */
		int bpp = TLN_GetBitmapDepth(bitmap);
		if (bpp == 8)
			TLN_SetLastError(TLN_ERR_OK);
		else
		{
			TLN_DeleteBitmap(bitmap);
			bitmap = NULL;
		}
	}

	if (!bitmap)
		TLN_SetLastError(TLN_ERR_WRONG_FORMAT);

	return bitmap;
}

TLN_Bitmap spriteSheet;
TLN_Palette palette;

private:

};
Hope that is what you wanted/needed! @megamarc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants