Page 1 of 1

Drawing graphics to different planes

Posted: Sat Mar 22, 2014 9:29 pm
by Kuroto
First posted this in the Megadrive/Genesis section (right here).

I managed to draw a fullscreen background using SGDK on Plane B.
However, i'm trying to draw a logo on Plane A, using the same method, which doesn't really work.

It does load, but it's on the bottom of Plane B (i checked in Gens KMOD's Plane explorer).

MintyTheCat already said something about priorities, but i'm not sure where to look for those.
2. without thinking too much about it I would say that you need to check your Priority settings. In the MD all Tiles are positioned according to each Tile's Tile-Map Entry found in the Tile-Map so if you are not sure you can interrogate that to make sure that you end up with the correct settings for the Tiles and indeed the Planes. There are rules but if A:Pri=1 and B:Pri=1 then A 'wins'. So check that B:Priority is set and see that A's is not.

Code: Select all

#include <genesis.h> 



struct genresTiles 
{ 
      u16 *pal;       //pointer to pal data 
      u32 *tiles;      //pointer to tiles data 
      u16 width;      //width in tiles 
      u16 height;      //height in tiles 
      u16 compressedSize; //0 in this demo, more coming soon 
}; 



extern struct genresTiles citybg; 
extern struct genresTiles logo; 

#define TILE1   1 
#define TILE2   1 



int main( ) 
{ 
   VDP_setPalette(PAL1, citybg.pal); 

   // load tiles in VRAM 
   //  arg0 = tiles data 
   //  arg1 = index for first destination tile 
   //  arg2 = number of tiles to load 
   //  arg3 = use DMA (1) or not (0) 
   VDP_loadTileData(citybg.tiles, TILE1, citybg.width*citybg.height, 0); 
   VDP_loadTileData(logo.tiles, TILE2, logo.width*logo.height, 0); 

    // City background fill 
   VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 0, -4, citybg.width, citybg.height); 
   VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 16, -4, citybg.width, citybg.height); 
   VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 32, -4, citybg.width, citybg.height); 
   VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE2), 0, -4, logo.width, logo.height); 


   VDP_drawText("SCORE:", 0,0); 
   VDP_drawText("00", 38, 0); 


   while(1) 
   { 
      VDP_waitVSync(); 
   } 
   return 0; 
} 
Any help is greatly appreciated. :)

Thanks in advance!

-Steve

Posted: Sun Mar 23, 2014 12:22 am
by Kuroto
OK, so after searching around a bit on the forum, i've tried a completely different approach.
Now i'm able to draw to both planes, but the background image doesn't start at the top-left of the screen. Instead, it starts at the bottom-left.

The logo draws correctly.

However, if i look at the plane explorer in Gens Kmod, i can still see data from the logo on the B plane, which of course also displays on the screen.

This is my current code:

Code: Select all

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

int main( )
{
   VDP_drawBitmap(VDP_PLAN_B, &bgcity, 0, 0);
   VDP_drawBitmap(VDP_PLAN_A, &gamelogo, 7, 4);
   VDP_drawText("SCORE: 0", 0, 0);

   while(1)
   {
      VDP_waitVSync();
   }
   return 0;
}
Also, is there a way to repeat an image?

Thanks in advance! :)

Posted: Sun Mar 23, 2014 3:59 pm
by Stef
Hi Kuroto,

Actually the VDP_drawBitmap(..) method is practical but always allocate the image at the same position (will be changed in the next version) so when you do 2 calls to VDP_drawBitmap(..) the second image will erase part of first one. It's better to use ...Ex method to have more control.

Also you should use VDP_drawImageEx(..) method instead (and so declare your resources as IMAGE) which is better as it removes duplicates tile and is faster to work with :)

So you should finally end with a code similar to that :

Code: Select all

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

int main( )
{
    u16 tileIndex = TILE_USERINDEX;

    VDP_drawImageEx(VDP_PLAN_B, &bgcity, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, tileIndex), 0, 0, TRUE, TRUE);
    tileIndex += bgcity.tileset->numTile;
    VDP_drawImageEx(VDP_PLAN_A, &gamelogo, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, tileIndex), 7, 4, TRUE, TRUE);
    tileIndex += gamelogo.tileset->numTile;

   VDP_drawText("SCORE: 0", 0, 0);

   while(1)
   {
      VDP_waitVSync();
   }

   return 0;
} 
What you mean by repeat the image ? If you mean sort of image tiling, just use a tiled image as source, rescomp will automatically create the big tilemap for you :)

Posted: Sun Mar 23, 2014 4:38 pm
by Kuroto
Hi Stef,

Thanks for the info.

I had an error when compiling the code you posted, but after searching the forums i've changed this code:

Code: Select all

u16 tileIndex = TILE_USER_INDEX;
into

Code: Select all

u16 tileIndex = TILE_USERINDEX;
and it works perfectly now! Thanks! :D


What I mean by repeating an image is, say I have my background, which I want to use to fill the whole screen. How would i do that?
Or should i just enlarge the picture to completely fill the screen?

Here's what i get now:
Image

(Yes, i might recreate this ridiculous game on the Genny. Don't judge me :lol: )

I need to fix the graphics with the right palette, so i might as well enlarge the image. But won't it use too much memory then?

Posted: Sun Mar 23, 2014 4:58 pm
by Stef
Oh yeah i made a small copy / paste mistake, i fixed it in the original post !
If you use the IMAGE resource type then SGDK automatically optimize your image and detect duplicated tiles so yeah, you can use large images while keeping small memory usage :)

Edit: I was not aware about this game, look like a simple gameplay but addictive ;) And actually if you complete it it would be already a nice achievement ;)

Posted: Sun Mar 23, 2014 5:07 pm
by Kuroto
OK, great. I'll just recreate the background image so it's larger.

Next step: Sprites :p I'm really starting to enjoy this.

Posted: Sun Mar 23, 2014 6:06 pm
by Kuroto
This looks much better :)

Image

Re: Drawing graphics to different planes

Posted: Mon Dec 14, 2015 8:47 pm
by alko
whether is possible to change priority draw PLANES ?
in order to draw APLAN over sprite-layer.

Re: Drawing graphics to different planes

Posted: Tue Dec 15, 2015 8:19 am
by dub
hi, if you look at the doc, you have :

Code: Select all

#define TILE_ATTR_FULL (   pal,  
    prio,  
    flipV,  
    flipH,  
    index  
 )     (((flipH) << 11) + ((flipV) << 12) + ((pal) << 13) + ((prio) << 15) + (index)) 


Encode tile attributes for tilemap data.
Parameters:
pal Palette index  
prio Tile priority  
flipV Vertical flip  
flipH Horizontal flip  
index Tile index  
So you must change prio=1 for PlaneA and prio=0 for Sprites.

VDP_drawImageEx(VDP_PLAN_A, &gamelogo, TILE_ATTR_FULL(PAL1, TRUE, FALSE, FALSE, tileIndex), 7, 4, TRUE, TRUE);
SPR_initSprite(&sprites[pl_numSprite], &shmup_sprite, fix32ToInt(pl_posX), fix32ToInt(pl_posY), TILE_ATTR(PAL3, FALSE, FALSE, FALSE));

Re: Drawing graphics to different planes

Posted: Tue Dec 15, 2015 9:53 am
by alko
danke schön

yet i'm trying make an animated background. But obtained only lags, and static background.

Code: Select all

static void fon_anim()
{
fon_anim_count++;
if(fon_anim_count<10)
{ 
VDP_drawImageEx(BPLAN, &fon1, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, ind), 0, 0, FALSE, TRUE);
//ind += fon1.tileset->numTile;
}
else{ 
VDP_drawImageEx(BPLAN, &fon2, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, ind), 0, 0, FALSE, TRUE);
//ind += fon1.tileset->numTile;
}
if(fon_anim_count>=20)fon_anim_count=0;
}

Re: Drawing graphics to different planes

Posted: Tue Dec 15, 2015 11:04 am
by dub
I think you can't reload all the Plan. You have just a small time for drawing tiles in background. But a expert can explain better.

If you try to load a full plan, the Megadrive need many frames. So you lose fps.

When you want to make background animation, I use two methods :
- you change only the tiles in background/plan
- you change tiles in VDP directly, so you'll see the plan changing.
Of course you need to know where doing change. So I use array for my plan.

If it's flappy background, you can show image of what you want to obtain.

Re: Drawing graphics to different planes

Posted: Tue Dec 15, 2015 6:22 pm
by alko
much time expended on unpack and loading to vdp-ram.
Maybe somehow create cache in system-ram where unpack the images?