Simple noob Pals/tiles question
Moderator: Stef
Simple noob Pals/tiles question
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
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
- Attachments
-
- Captura.PNG (29.67 KiB) Viewed 10951 times
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
Re: Simple noob Pals/tiles question
There's only three bits per color in the palette entry, so you only get eight shades, ignoring shadow or highlight effects.
Re: Simple noob Pals/tiles question
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
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
Re: Simple noob Pals/tiles question
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".
Re: Simple noob Pals/tiles question
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 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)
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 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 (608 Bytes) Viewed 10869 times
-
- Captura2.PNG (23.43 KiB) Viewed 10869 times
-
- 64tiles.zip
- (199 Bytes) Downloaded 240 times
Re: Simple noob Pals/tiles question
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
no way, I don't understand, it's like color pal is not reading properly
Re: Simple noob Pals/tiles question
Can you inline the code here?
Re: Simple noob Pals/tiles question
Same that 'background tutorial'
resource.res
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;
}
Re: Simple noob Pals/tiles question
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).
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 (8.53 KiB) Viewed 10744 times
Re: Simple noob Pals/tiles question
Hmmmm
Loaded 2 different images and found something strange:
So I check Sample/Sprites tutorial. Correct code is:
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.
Well, why we need to get TILE_USERINDEX and add manually tiles to not start from tile 0 when using VDP_drawImageEx?
Loaded 2 different images and found something strange:
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;
}
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;
}
I think is just because both images have white color. Not important I think.
Well, why we need to get TILE_USERINDEX and add manually tiles to not start from tile 0 when using VDP_drawImageEx?
Re: Simple noob Pals/tiles question
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?
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?
Re: Simple noob Pals/tiles question
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
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
Re: Simple noob Pals/tiles question
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;
Re: Simple noob Pals/tiles question
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.Grind wrote: ↑Sun Mar 03, 2019 4:34 pmThe 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;