Simple noob Pals/tiles question

SGDK only sub forum

Moderator: Stef

Post Reply
danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Simple noob Pals/tiles question

Post by danibus » Sun Feb 24, 2019 7:14 pm

Just learning SGDK
Doing some stuff with tiles.
I just load 1 Tile in VRAM at position 1..

Draw tile on screen, draw again with another pal in another position, draw again with priority, etc.

Open GensKmod and check debug > VRAM

1. I see 4 default pals (grey, red, green, blue)... but also there are another one (ust down 4 pals), with all colors (2 reds, 2 blues, 2 grays, 2 browns, ...)
2. Why default pals are 7 different gradient of i.e. red, and rest of pal are same red color, why not put 16 different reds in red pal (same with other pals)
3. VRAM. I see my tile at position 0x1 but... why there are also different tiles with pal colors

Pls see attached

I know, noob making noob questions :oops:
Attachments
Captura.PNG
Captura.PNG (29.67 KiB) Viewed 10490 times

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: Simple noob Pals/tiles question

Post by Chilly Willy » Mon Feb 25, 2019 12:05 am

There's only three bits per color in the palette entry, so you only get eight shades, ignoring shadow or highlight effects.

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: Simple noob Pals/tiles question

Post by Grind » Mon Feb 25, 2019 1:12 am

SGDK loads solid blocks of each palette color into the first 16 tiles in VRAM by default. That's why TILE_USERINDEX is 16. You can ignore/overwrite them if you don't use them, though.

And I think that 5th palette is just a Gens Kmod thing. For example if your game fades to black (all 4 palettes go black) you can pick that with your mouse and still see all the tiles in VRAM

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Simple noob Pals/tiles question

Post by Sik » Mon Feb 25, 2019 2:42 am

Yeah, that 5th palette is just so you can still see the tiles in the VRAM debugger even if all palettes become a solid color from fading or the like. It doesn't exist on the actual hardware.
Sik is pronounced as "seek", not as "sick".

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Simple noob Pals/tiles question

Post by danibus » Wed Feb 27, 2019 8:26 pm

New question. Did background tutorial, you know, moon.bmp
Ok worked.
Then I asked me how many tiles did SGDK made from moon.bmp
64x64px -> 8x8 tiles = 64 tiles

But... if some tiles are same tile? I mean, i.e. black tiles.
Does SGDK put in VRAM just 1 tile for black tiles to avoid repeating?

So I draw 64 tiles in 64x64 bitmap, each one 8x8 pixels, attached.

I expected to have only 2 tiles in VRAM or 64, but something strange happens. First colors are not the one I put in file (red, black, gray).
Also VRAM "cut tiles", I didn't get "perfect square 8x8 tiles". Upper part is in another tile.
I changed colors but same happens.

PD: Also... I think... I can choose any color using drwaing program, but maybe is not in Megadrive pallete. Is this the explanation?
I use GraphicsGale to draw.

PD: also attached GensKmod VRAM image, as you see green everywhere :roll: strange dots just down :?:
See Tile 0x0001, it's not correct square like I drew :?:

This is my image I put in zip file, I attach like PNG to watch in forum (don't dowload image, just the ZIP that is below all images)
Attachments
tiles.png
tiles.png (608 Bytes) Viewed 10408 times
Captura2.PNG
Captura2.PNG (23.43 KiB) Viewed 10408 times
64tiles.zip
(199 Bytes) Downloaded 225 times

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Simple noob Pals/tiles question

Post by danibus » Fri Mar 01, 2019 10:43 am

I used this rgb values 0, 32, 64, 96, 128, 160, 192, 224

no way, I don't understand, it's like color pal is not reading properly

vnsbr
Interested
Posts: 48
Joined: Sun Dec 17, 2017 4:13 pm

Re: Simple noob Pals/tiles question

Post by vnsbr » Fri Mar 01, 2019 11:05 am

Can you inline the code here?

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Simple noob Pals/tiles question

Post by danibus » Fri Mar 01, 2019 2:14 pm

Same that 'background tutorial'

resource.res

Code: Select all

IMAGE block "my64tiles.bmp" 0

Code: Select all

#include <genesis.h>
#include "resources.h"

int main()
{
	// get the palette data of block
	VDP_setPalette(PAL2, block.palette->data);

	// load bitmap data of block  in VRAM and draw
	VDP_drawImageEx(PLAN_A, &block , TILE_ATTR_FULL(PAL2, 0, 0, 0, 1), 12, 12, 0, CPU);

	while(1)
	{
		VDP_waitVSync();
	}

	return 0;
}

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Simple noob Pals/tiles question

Post by danibus » Sat Mar 02, 2019 11:17 pm

Finally I surrender and changed from BMP to PNG, it's working perfectly with PNG, don't know why BMP fails with colors and reading tiles.

With PNG SGDK only reads 2 tiles and colors are almost correct (used RGB gray (224, 224, 224), it shows as white in GensKmod).
Attachments
Captura3.PNG
Captura3.PNG (8.53 KiB) Viewed 10283 times

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Simple noob Pals/tiles question

Post by danibus » Sun Mar 03, 2019 3:19 am

Hmmmm

Loaded 2 different images and found something strange:
Captura4.PNG
Captura4.PNG (47.84 KiB) Viewed 10273 times

Code: Select all

#include <genesis.h>
#include "resources.h"

int main()
{
	VDP_setPalette(PAL0, block.palette->data);
	VDP_setPalette(PAL1, block2.palette->data);

	VDP_drawImageEx(PLAN_A, &block ,  TILE_ATTR_FULL(PAL0, 0, 0, 0, 1),  3,  3, 1, CPU);
	VDP_drawImageEx(PLAN_B, &block2 , TILE_ATTR_FULL(PAL1, 0, 0, 0, 1), 15, 15, 1, CPU);

	while(1)
	{
		VDP_waitVSync();
	}
	return 0;
}
So I check Sample/Sprites tutorial. Correct code is:

Code: Select all

#include <genesis.h>
#include "resources.h"

int main()
{
    u16 palette[64];
    u16 ind;			//16 bits unsigned integer (equivalent to unsigned short).

    VDP_setPaletteColors(0, (u16*) palette_black, 64); //palette_black

	// get the palette data of block
	VDP_setPalette(PAL0, block.palette->data);
	VDP_setPalette(PAL1, block2.palette->data);

	// load bitmap data of block  in VRAM and draw
	ind = TILE_USERINDEX;
	VDP_drawImageEx(PLAN_A, &block ,  TILE_ATTR_FULL(PAL0, 0, 0, 0, 1),  3,  3, 1, CPU);
	ind += bgb_image.tileset->numTile;
	VDP_drawImageEx(PLAN_B, &block2 , TILE_ATTR_FULL(PAL1, 0, 0, 0, 1), 15, 15, 1, CPU);
	ind += bga_image.tileset->numTile;

	while(1)
	{
		VDP_waitVSync();
	}

	return 0;
}
Now working well. Well... more or less. See this white dots? Why white dots in moon tiles?
I think is just because both images have white color. Not important I think.
Captura5.PNG
Captura5.PNG (42.76 KiB) Viewed 10273 times


Well, why we need to get TILE_USERINDEX and add manually tiles to not start from tile 0 when using VDP_drawImageEx?

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: Simple noob Pals/tiles question

Post by Grind » Sun Mar 03, 2019 2:16 pm

The first palette has dark gray in color index 2 which the moon uses, the second palette has white in color index 2. So when you show the moon tiles with the second palette, it gets drawn with white at index 2 and black everywhere else.

I'm not sure if I understand your question at the end. You can load at whatever index you want. Or are you asking why SGDK even needs to know the index at all?

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Simple noob Pals/tiles question

Post by danibus » Sun Mar 03, 2019 2:37 pm

I though that if I load 2 different images, they would be stored as tiles in VRAM, but seems that second one is stored over first one if I don't increment ind.

As I was following tutorial, not sure about what TILE_USERINDEX and 'ind' does. I think is like a pointer to 'still-not-used' VRAM. But how knows XD

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: Simple noob Pals/tiles question

Post by Grind » Sun Mar 03, 2019 4:34 pm

The last argument of TILE_ATTR_FULL is the tile index. That should be ind. You can replace TILE_USERINDEX with 1 if you don't care about those 15 boxes at the start of VRAM.

Code: Select all

// load bitmap data of block  in VRAM and draw
ind = TILE_USERINDEX;
VDP_drawImageEx(PLAN_A, &block ,  TILE_ATTR_FULL(PAL0, 0, 0, 0, ind),  3,  3, 1, CPU);
ind += bgb_image.tileset->numTile;
VDP_drawImageEx(PLAN_B, &block2 , TILE_ATTR_FULL(PAL1, 0, 0, 0, ind), 15, 15, 1, CPU);
ind += bga_image.tileset->numTile;

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Simple noob Pals/tiles question

Post by danibus » Sun Mar 03, 2019 11:35 pm

Grind wrote:
Sun Mar 03, 2019 4:34 pm
The last argument of TILE_ATTR_FULL is the tile index. That should be ind. You can replace TILE_USERINDEX with 1 if you don't care about those 15 boxes at the start of VRAM.

Code: Select all

// load bitmap data of block  in VRAM and draw
ind = TILE_USERINDEX;
VDP_drawImageEx(PLAN_A, &block ,  TILE_ATTR_FULL(PAL0, 0, 0, 0, ind),  3,  3, 1, CPU);
ind += bgb_image.tileset->numTile;
VDP_drawImageEx(PLAN_B, &block2 , TILE_ATTR_FULL(PAL1, 0, 0, 0, ind), 15, 15, 1, CPU);
ind += bga_image.tileset->numTile;
Thanks, I forgot about last argument of TILE_ATTR_FULL. As I put '1' in second image, SGDK put its tiles over the tiles of first image.

Post Reply