Page 1 of 1

Strange garbled graphics

Posted: Sat Jan 23, 2016 5:12 am
by POLYGAMe
Hi there,

I'm trying to load my road on plane b and my sky on plane a. When I load each of them separately it works fine but when I try to load both, I get bits of the road across the top of the screen. What could cause this? Here are some shots and the code I'm using to get the images on screen. I'm a total noob at this so have probably done something really stupid...

Code: Select all

 // DRAW SKY
        u16 ind_tileset;
        ind_tileset = TILE_USERINDEX;
        VDP_loadTileSet(sky.tileset, ind_tileset, FALSE);
        Map *map = unpackMap(sky.map, NULL);
        VDP_setMapEx(APLAN, map, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, ind_tileset), 0, 0, 0, 0, 40, 12);

        // DRAW ROAD
        u16 ind_tileset2;
        ind_tileset2 = TILE_USERINDEX;
        VDP_loadTileSet(road.tileset, ind_tileset2, FALSE);
        Map *map2 = unpackMap(road.map, NULL);
        VDP_setMapEx(BPLAN, map2, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, ind_tileset2), 0, 12, 0, 0, 40, 16);

Re: Strange garbled graphics

Posted: Sat Jan 23, 2016 8:19 am
by dub
If I read your code, i see you use the same tile_index

Code: Select all

u16 ind_tileset;
        ind_tileset = TILE_USERINDEX;
        ...
        u16 ind_tileset2;
        ind_tileset2 = TILE_USERINDEX;
Maybe you write tile at the same position in VRAM. You can look in debug mode your vram.
Add this to make test :

Code: Select all

u16 ind_tileset;
        ind_tileset = TILE_USERINDEX;
        ...
        u16 ind_tileset2;
        ind_tileset2 = TILE_USERINDEX + sky.tileset->numTile;
Like this you'll write the road tile after the sky tile.

Re: Strange garbled graphics

Posted: Sat Jan 23, 2016 9:40 am
by POLYGAMe
I thought it might be the tile set! Thanks!
As I'm not great with C, would you mind telling me what "->" does? It's been so long since I've used C. lol.

Re: Strange garbled graphics

Posted: Sat Jan 23, 2016 10:28 am
by dub
It's a long time for me too, maybe someone can explain more clearly (in English).
the -> is the object of a structure.

I don't have the struct of tileset but you can see with this :
typedef struct
{
u16 compression;
u16 w;
u16 h;
const Palette *palette;
const u8 *image;
} Bitmap;
For reading the width of the bitmap, you can make Bitmap->w

Re: Strange garbled graphics

Posted: Sat Jan 23, 2016 2:29 pm
by Stef
It's a bit more tight that that :p
Using -> mean that you access your data through a pointer.

For instance if you do:

Code: Select all

Bitmap myBitmap;
then myBitmap is a Bitmap structure and you need to access fields through . operator:

Code: Select all

v = myBitmap.width;
But if you do:

Code: Select all

Bitmap *myBitmapPointer;
then myBitmapPointer is a pointer on a Bitmap structure and you need to access fields through -> operator:

Code: Select all

v = myBitmapPointer->width;
You really need to understand what is a pointer and how that work else you will get many troubles later with your C code ;)

Re: Strange garbled graphics

Posted: Sat Jan 23, 2016 6:04 pm
by dub
Thanks master :mrgreen:

I always forget the pointer.

Re: Strange garbled graphics

Posted: Sat Jan 23, 2016 7:51 pm
by POLYGAMe
Stef wrote: You really need to understand what is a pointer and how that work else you will get many troubles later with your C code ;)
Yeah I have a basic grasp of how they work but it's very basic. Haha. Haven't used pointers in five years; not since university. Most of my development has been in Unity so this is a steep learning curve! I'll get there though :)

Re: Strange garbled graphics

Posted: Sun Jan 24, 2016 12:12 am
by POLYGAMe
dub wrote:If I read your code, i see you use the same tile_index

Code: Select all

u16 ind_tileset;
        ind_tileset = TILE_USERINDEX;
        ...
        u16 ind_tileset2;
        ind_tileset2 = TILE_USERINDEX;
Maybe you write tile at the same position in VRAM. You can look in debug mode your vram.
Add this to make test :

Code: Select all

u16 ind_tileset;
        ind_tileset = TILE_USERINDEX;
        ...
        u16 ind_tileset2;
        ind_tileset2 = TILE_USERINDEX + sky.tileset->numTile;
Like this you'll write the road tile after the sky tile.
This worked. Thanks!