struggling with loading bitmap

SGDK only sub forum

Moderator: Stef

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

Post by Stef » Thu Feb 13, 2014 10:31 pm

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

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Post by matteus » Mon Feb 17, 2014 1:23 pm

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?

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Mon Feb 17, 2014 7:53 pm

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.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Post by matteus » Mon Feb 17, 2014 8:04 pm

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

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Mon Feb 17, 2014 8:23 pm

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.

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

Post by Stef » Mon Feb 17, 2014 11:58 pm

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.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Update on Thundercats demo

Post by matteus » Tue Feb 18, 2014 12:06 am

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);
Last edited by matteus on Tue Feb 18, 2014 2:54 pm, edited 1 time in total.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Post by matteus » Tue Feb 18, 2014 12:09 am

Thought I'd upload a video of my work in progress :)

http://youtu.be/fwAWC89TE5A

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Post by matteus » Tue Feb 18, 2014 4:51 pm

I've been poking around in the SGDK do I need to use VDP_clearPlan or VDP_resetScreen before loading my new Images?

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

Post by Stef » Tue Feb 18, 2014 7:28 pm

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.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Post by matteus » Tue Feb 18, 2014 8:45 pm

How would I load images one after another? There seems to be a blank screen delay inbetween loading each image into the pane

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

Post by Stef » Tue Feb 18, 2014 8:53 pm

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.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Post by matteus » Tue Feb 18, 2014 10:30 pm

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.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Post by matteus » Tue Feb 18, 2014 10:54 pm

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

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Wed Feb 19, 2014 12:09 am

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.

Post Reply