Page 4 of 10

Posted: Thu Feb 13, 2014 10:31 pm
by Stef
Well done :) Your code with the drawImageEx(..) methods looks perfectly correct. I think you have another problem as internally the VDP_drawImage(..) method use VDP_drawImageEx(..) with some defaults parameters values but i can't find what is wrong with your code again. About the color 0, you have to use a image software which allow you to define which color is stored at index 0, personally i use gimp of mtPaint for that but you may use PNG format with transparency (i think rescomp handle it correctly).

Posted: Mon Feb 17, 2014 1:23 pm
by matteus
Stef wrote:Well done :) Your code with the drawImageEx(..) methods looks perfectly correct. I think you have another problem as internally the VDP_drawImage(..) method use VDP_drawImageEx(..) with some defaults parameters values but i can't find what is wrong with your code again. About the color 0, you have to use a image software which allow you to define which color is stored at index 0, personally i use gimp of mtPaint for that but you may use PNG format with transparency (i think rescomp handle it correctly).
Mmm I'm at a bit of a deadend with this I shall post the image with the palette issue tonight. Stef could it be something to do with the fade in not fading correctly?

Additionally if I wanted to make the background animate and load in different image files how would I do this? would I be able to set a delay between loading and showing images?

Posted: Mon Feb 17, 2014 7:53 pm
by Chilly Willy
When you use the extended function, you don't set the palette, leaving it black. You then do the fade in. The fade routine uses an 8.8 fixed point number for the fade. This means that the colors won't be EXACTLY right, depending on the exact color and the length of the fade. I suggest doing an explicit set palette with the desired palette after the fade to be sure the correct colors are loaded.

Posted: Mon Feb 17, 2014 8:04 pm
by matteus
Chilly Willy wrote:When you use the extended function, you don't set the palette, leaving it black. You then do the fade in. The fade routine uses an 8.8 fixed point number for the fade. This means that the colors won't be EXACTLY right, depending on the exact color and the length of the fade. I suggest doing an explicit set palette with the desired palette after the fade to be sure the correct colors are loaded.
Fantastic! Thank you for setting me straight on that one Chilly! :)

I did it and it's working!!!! :D

Posted: Mon Feb 17, 2014 8:23 pm
by Chilly Willy
It would be closer to a correct palette is the fade code rounded the values instead of truncating, but they'd still be somewhat off. The code could be made better by adding rounding, and then do an explicit palette set with the dst palette for the last step of the fade.

EDIT: Thinking about it, rounding could make the values too high, which if the value is F could result in wrapping around. Fortunately, the MD doesn't use b0, so AND the value with E first, then calculate the step with rounding. If the value E goes too high due to fixed point imprecision, no big deal since F is the same as E on the MD.

Posted: Mon Feb 17, 2014 11:58 pm
by Stef
Oh ok that was again that fade palette issue. Indeed it is a good practice to set the destination palette after the fade operation. I plan to fix that at somepoint so it will always set the destination palette after the fade is done.

Update on Thundercats demo

Posted: Tue Feb 18, 2014 12:06 am
by matteus
I've got the screen loading and displaying graphics on both panes now :)

I've also fathomed how to get music running, however I'm still noticing a bug when I fade and load in the next images.

I simply use the fadeOutAll and then reset the palettes to black and load the new images in? That should work shouldn't it? I notice a nasty line of tiles on the new character image though. From looking at the image I get the impression old tile data is being held in memory and the new palette is being applied to it?

Code: Select all

// fade all out
    VDP_fadeOutAll(20, FALSE);

    // so lets start again

    // set all palettes to black
    VDP_setPaletteColors(0, palette_black, 64);

    // load background
    ind = TILE_USERINDEX;

    VDP_drawImageEx(BPLAN, &tygra_background_image, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 0, FALSE, TRUE);
    ind += tygra_background_image.tileset->numTile;

    VDP_drawImageEx(APLAN, &tygra_image, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, ind), 23, 4, FALSE, TRUE);
    ind += tygra_image.tileset->numTile;

    // prepare palette
    memcpy(&palette[0], tygra_background_image.palette->data, 16 * 2);
    memcpy(&palette[16], tygra_image.palette->data, 16 * 2);

    VDP_fadeIn(0, (2 * 16) - 1, palette, 20, FALSE);

    VDP_setPalette(0, tygra_background_image.palette->data);
    VDP_setPalette(1, tygra_image.palette->data);

Posted: Tue Feb 18, 2014 12:09 am
by matteus
Thought I'd upload a video of my work in progress :)

http://youtu.be/fwAWC89TE5A

Posted: Tue Feb 18, 2014 4:51 pm
by matteus
I've been poking around in the SGDK do I need to use VDP_clearPlan or VDP_resetScreen before loading my new Images?

Posted: Tue Feb 18, 2014 7:28 pm
by Stef
I reply here about your PM as well as it can be interesting for anyone in general.
To start with you don't need to clear the screen when loading a new image, the new image should erase the previous one. Then we come to your second question... there is no way to load a full screen image at 24 fps and it is even worse if you want to refresh plan A and plan B. The VRam bandwidth is quite limited, if you consume the whole vblank period you only have about 7 KB to 8 KB per frame... it is far from the needed 14KB needed to maitains 24 fps and only for a single plan. If you plan to use compression you also have to take the unpacking time in account... If your image contains many identicals tiles then loading can be faster but for complexes images you will never achieve 24 FPS.
I believe 12 FPS is the maximum when you refresh a complete plan on a NTSC system and probably 17 FPS on a PAL system.

Posted: Tue Feb 18, 2014 8:45 pm
by matteus
How would I load images one after another? There seems to be a blank screen delay inbetween loading each image into the pane

Posted: Tue Feb 18, 2014 8:53 pm
by Stef
You need to deal with a sort of double buffer.
Display image A while you are loading image B.
When image B is loaded switch display to image B then load next image (image A) and so on... For that you can use the vertical scrolling to switch between the 2 images for instance.

Posted: Tue Feb 18, 2014 10:30 pm
by matteus
Stef wrote:You need to deal with a sort of double buffer.
Display image A while you are loading image B.
When image B is loaded switch display to image B then load next image (image A) and so on... For that you can use the vertical scrolling to switch between the 2 images for instance.
Ohhhh! so you can't use both panes at once! Gutted I'll look at vertical scrolling then.

Posted: Tue Feb 18, 2014 10:54 pm
by matteus
The following code leaves PLAN B with a mess of tiles on reloading... Any ideas?

Code: Select all

#include <genesis.h>

#include "gfx.h"
#include "music.h"

int main()
{
    u16 palette[64];
    u16 ind;

   // initialization
    VDP_setScreenWidth320();
    VDP_setScreenHeight224();

    VDP_resetScreen();

    int i = 0;

    for (i = 0; i < 10; i++)
    {

        // load background
        ind = TILE_USERINDEX;

        VDP_drawImageEx(BPLAN, &panthro_image, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 22, 5, FALSE, TRUE);
        ind += panthro_image.tileset->numTile;

        // set pallettes
        VDP_setPalette(0, panthro_image.palette->data);

        waitTick(150);

        // so lets start again

        // load background
        ind = TILE_USERINDEX;

        VDP_drawImageEx(APLAN, &tygra_image, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, ind), 23, 4, FALSE, TRUE);
        ind += tygra_image.tileset->numTile;

        VDP_setPalette(1, tygra_image.palette->data);

        waitTick(150);

    }

    while(1)
    {
            VDP_waitVSync();
    }
    return 0;
}

Posted: Wed Feb 19, 2014 12:09 am
by Chilly Willy
EDIT: Sorry, need to look closer at the code...

Okay, you're setting the tile index for planes A and B to the same value. The whole point of adding numTiles to ind after drawing the image is to find the next free place in the tiles so that you don't overlap. You reset ind to TILE_USERINDEX before the next draw, which means it draws right over top of tiles already in use.