Strange garbled graphics

SGDK only sub forum

Moderator: Stef

Post Reply
POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Strange garbled graphics

Post by POLYGAMe » Sat Jan 23, 2016 5:12 am

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);
Attachments
SKY.png
SKY.png (20.21 KiB) Viewed 2525 times
ROAD.png
ROAD.png (7.78 KiB) Viewed 2525 times
BOTH.png
BOTH.png (20.18 KiB) Viewed 2525 times

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Strange garbled graphics

Post by dub » Sat Jan 23, 2016 8:19 am

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.

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Strange garbled graphics

Post by POLYGAMe » Sat Jan 23, 2016 9:40 am

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.

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Strange garbled graphics

Post by dub » Sat Jan 23, 2016 10:28 am

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

Stef
Very interested
Posts: 3043
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Strange garbled graphics

Post by Stef » Sat Jan 23, 2016 2:29 pm

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 ;)

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Strange garbled graphics

Post by dub » Sat Jan 23, 2016 6:04 pm

Thanks master :mrgreen:

I always forget the pointer.

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Strange garbled graphics

Post by POLYGAMe » Sat Jan 23, 2016 7:51 pm

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 :)

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Strange garbled graphics

Post by POLYGAMe » Sun Jan 24, 2016 12:12 am

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!

Post Reply