struggling with loading bitmap

SGDK only sub forum

Moderator: Stef

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

Post by matteus » Mon Mar 03, 2014 11:54 am

Stef wrote:It's me, again a missed message.. i don't understand ^^
Well the compression information is given in the .res file, just look in the SPRITE definition of the rescomp.txt file, you will see that is pretty easy =)
Oh that's where the compression is defined! .RES file controls compression, etc Silly me! that's what the "-1" means!

Thanks Stef really appreciate the response :)

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

Post by Stef » Mon Mar 03, 2014 1:24 pm

matteus wrote: Oh that's where the compression is defined! .RES file controls compression, etc Silly me! that's what the "-1" means!

Thanks Stef really appreciate the response :)
Yeah exactly, the -1 parameter just mean "auto compression" so it will use the best compression scheme depending your image.
You can set it to 0 (no compression) or fixed value (1, 2...) to use a specific compression scheme.

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

Post by matteus » Tue Mar 04, 2014 12:39 am

Stef wrote:
matteus wrote: Oh that's where the compression is defined! .RES file controls compression, etc Silly me! that's what the "-1" means!

Thanks Stef really appreciate the response :)
Yeah exactly, the -1 parameter just mean "auto compression" so it will use the best compression scheme depending your image.
You can set it to 0 (no compression) or fixed value (1, 2...) to use a specific compression scheme.
Removed compress and now working at full speed (so much so I'm having to put a waittick in!

I'm presently optimising the palette in the next 10 seconds of animation to allow dithering to soften the low res of the animation, while maximising the colour.

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

Post by matteus » Tue Mar 04, 2014 9:37 am

Update video time: https://www.youtube.com/watch?v=a0YJu9p ... ata_player

Probably the last one for a while until I make decent progress animation wise :)

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

Post by Chilly Willy » Tue Mar 04, 2014 6:28 pm

Looks really good. :D

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

Post by Stef » Tue Mar 04, 2014 10:55 pm

Looks nice and smooth !
Test at least on Fusion as older emulators (as Gens) does not emulate VRAM access time so it will be a lot faster than Real Hardware in active period.

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

Post by matteus » Wed Mar 05, 2014 12:35 am

Update video:

http://youtu.be/3n5rci_SC2o

Managed to implement a masked frame on Pane A but seem to have lost the initial fade transition on the animation :(

I used

Code: Select all

VDP_setBackgroundColor(32);
Which I believe should have set the transparency to colour 0 of palette 3? I could be wrong :/

Update: Oh wait! Is it is because pane B uses a colour specific to it's palette own palette position 0. Which in most cases will be the only colour in a 1bpp image (doh) on the initial fade in???

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

Post by matteus » Tue Mar 11, 2014 12:13 am

I figured it has been a few days so it was time for an update :)

http://youtu.be/7yHF3VzqH9w

I'm not entirely sure whats happening with the tiles in some of the frames :/ I'm going to need to do some serious optimizing to keep the palettes displaying correctly!

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

Post by matteus » Tue Mar 11, 2014 9:22 am

Stef have you any idea what would cause the weird corruption in some frames? I can only guess it is something to do with the way I batch process the images or the way in which the SGDK converts the images to tiles...

What confused me is that the frames before and after the on screen corruption are not that different to one another.

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

Post by Stef » Tue Mar 11, 2014 12:38 pm

A good practice is to use sort of double buffering as i already explained, do you use it ? so while you are uploading an image the previous one remains visible and when the new one is ready you switch to it.
If you don't do that you may see corruption sometime as you may display an image partially changed. Another problem you may experience if the way you are dealing with VRAM, from what i remember you use a simple index position test, you should be sure that position test is safe enough...

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

Post by matteus » Tue Mar 11, 2014 5:54 pm

Stef wrote:A good practice is to use sort of double buffering as i already explained, do you use it ? so while you are uploading an image the previous one remains visible and when the new one is ready you switch to it.
If you don't do that you may see corruption sometime as you may display an image partially changed. Another problem you may experience if the way you are dealing with VRAM, from what i remember you use a simple index position test, you should be sure that position test is safe enough...
I get the impression it maybe because i'm still not entirely sure what the ind value is used for?

Code: Select all

    u16 ind = TILE_USERINDEX;
    u16 i = 0;
    u16 pal = PAL0;
    u16 ypos = 0;
    u16 vpos = 0;

    VDP_drawImageEx(APLAN, &border, TILE_ATTR_FULL(PAL3, FALSE, FALSE, FALSE, ind), 0, 0, TRUE, TRUE);
    VDP_setBackgroundColor(32);

    u16 newInd = TILE_USERINDEX + border.tileset->numTile;

        for(i = 0; i < 214; i++)
        {
            if(i == 37) {
               //music
                SND_startPlay_PCM(thundercats_music, sizeof(thundercats_music), SOUND_RATE_8000, SOUND_PAN_CENTER, FALSE);
            }
            u16 nextypos =  ypos ^ 0x20;
            VDP_setVerticalScroll(BPLAN, vpos);
            VDP_drawImageEx(BPLAN, images[i], TILE_ATTR_FULL(pal, FALSE, FALSE, FALSE, ind), 7, vpos + 4, TRUE, TRUE);
            if (ind == (newInd + 540)) {
                ind = newInd;
            } else {
                ind = newInd + 540;
            }
            pal ^= 1;
            waitTick(10);
            ypos = nextypos;
        }

    while(1)
    {
            VDP_waitVSync();
    }
    return 0;
Last edited by matteus on Wed Mar 12, 2014 1:51 pm, edited 1 time in total.

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

Post by matteus » Wed Mar 12, 2014 9:58 am

I've modified the code (which I will post tonight).

I have been debugging the VRAM, while also displaying a count of the number of tiles in use on the A Plan.

The code makes sure that the tile count is big enough for 2 screen at 216x160 plus the A Plan border tiles.

I have notice some corruption towards the bottom of the VRAM not far beyond the allocated VRAM space for the Font tiles but I don't understand how that is becoming corrupted :/

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

Post by Stef » Wed Mar 12, 2014 8:10 pm

It would be nice if you can post the complete code as it seems some parts are missing in the one you posted !

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

Post by matteus » Thu Mar 13, 2014 6:41 pm

Code: Select all

#include <genesis.h>

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

int main()
{

   // initialization
    VDP_setScreenWidth320();

    const Image *images[214] = {
      &frame1,
      &frame2,
      &frame3,
      &frame4,
      &frame5,
      &frame6,
      &frame7,
      &frame8,
      &frame9,
      &frame10,
      &frame11,
      &frame12,
      &frame13,
      &frame14,
      &frame15,
      &frame16,
      &frame17,
      &frame18,
      &frame19,
      &frame20,
      &frame21,
      &frame22,
      &frame23,
      &frame24,
      &frame25,
      &frame26,
      &frame27,
      &frame28,
      &frame29,
      &frame30,
      &frame31,
      &frame32,
      &frame33,
      &frame34,
      &frame35,
      &frame36,
      &frame37,
      &frame38,
      &frame39,
      &frame40,
      &frame41,
      &frame42,
      &frame43,
      &frame44,
      &frame45,
      &frame46,
      &frame47,
      &frame48,
      &frame49,
      &frame50,
      &frame51,
      &frame52,
      &frame53,
      &frame54,
      &frame55,
      &frame56,
      &frame57,
      &frame58,
      &frame59,
      &frame60,
      &frame61,
      &frame62,
      &frame63,
      &frame64,
      &frame65,
      &frame66,
      &frame67,
      &frame68,
      &frame69,
      &frame70,
      &frame71,
      &frame72,
      &frame73,
      &frame74,
      &frame75,
      &frame76,
      &frame77,
      &frame78,
      &frame79,
      &frame80,
      &frame81,
      &frame82,
      &frame83,
      &frame84,
      &frame85,
      &frame86,
      &frame87,
      &frame88,
      &frame89,
      &frame90,
      &frame91,
      &frame92,
      &frame93,
      &frame94,
      &frame95,
      &frame96,
      &frame97,
      &frame98,
      &frame99,
      &frame100,
      &frame101,
      &frame102,
      &frame103,
      &frame104,
      &frame105,
      &frame106,
      &frame107,
      &frame108,
      &frame109,
      &frame110,
      &frame111,
      &frame112,
      &frame113,
      &frame114,
      &frame115,
      &frame116,
      &frame117,
      &frame118,
      &frame119,
      &frame120,
      &frame121,
      &frame122,
      &frame123,
      &frame124,
      &frame125,
      &frame126,
      &frame127,
      &frame128,
      &frame129,
      &frame130,
      &frame131,
      &frame132,
      &frame133,
      &frame134,
      &frame135,
      &frame136,
      &frame137,
      &frame138,
      &frame139,
      &frame140,
      &frame141,
      &frame142,
      &frame143,
      &frame144,
      &frame145,
      &frame146,
      &frame147,
      &frame148,
      &frame149,
      &frame150,
      &frame151,
      &frame152,
      &frame153,
      &frame154,
      &frame155,
      &frame156,
      &frame157,
      &frame158,
      &frame159,
      &frame160,
      &frame161,
      &frame162,
      &frame163,
      &frame164,
      &frame165,
      &frame166,
      &frame167,
      &frame168,
      &frame169,
      &frame170,
      &frame171,
      &frame172,
      &frame173,
      &frame174,
      &frame175,
    &frame176,
    &frame177,
    &frame178,
    &frame179,
    &frame180,
    &frame181,
    &frame182,
    &frame183,
    &frame184,
    &frame185,
    &frame186,
    &frame187,
    &frame188,
    &frame189,
    &frame190,
    &frame191,
    &frame192,
    &frame193,
    &frame194,
    &frame195,
    &frame196,
    &frame197,
    &frame198,
    &frame199,
    &frame200,
    &frame201,
    &frame202,
    &frame203,
    &frame204,
    &frame205,
    &frame206,
    &frame207,
    &frame208,
    &frame209,
    &frame210,
    &frame211,
    &frame212,
    &frame213,
    &frame214
    };

    u16 ind = TILE_USERINDEX;
    u16 i = 0;
    u16 pal = PAL0;
    u16 ypos = 0;
    u16 vpos = 0;
    char str[8];

    //while(1)
    //{

    VDP_drawImageEx(APLAN, &border, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, ind), 0, 0, TRUE, TRUE);
    //VDP_setBackgroundColor(35);

    ind += border.tileset->numTile;

    u16 newInd = ind;

    u16 maxInd = newInd + 1080;

    intToStr(ind, str, 1);
    VDP_setTextPlan(APLAN);
    VDP_setTextPalette(PAL3);
    VDP_drawText(str, 0, 0);

        for(i = 174; i < 214; i++)
        {
            //if(i == 37) {
               //music
            //    SND_startPlay_PCM(thundercats_music, sizeof(thundercats_music), SOUND_RATE_8000, SOUND_PAN_CENTER, FALSE);
            //}
            if (ind == maxInd) {
                intToStr(maxInd, str, 1);
                VDP_drawText(str, 0, 1);
                ind = newInd;
            }
            u16 nextypos =  ypos ^ 0x20;
            VDP_setVerticalScroll(BPLAN, vpos);
            VDP_drawImageEx(BPLAN, images[i], TILE_ATTR_FULL(pal, FALSE, FALSE, FALSE, ind), 7, vpos + 4, TRUE, TRUE);
            ind += 540;

            pal ^= 1;
            //waitTick(10);
            waitTick(100);
            ypos = nextypos;
        }

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

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

Post by Stef » Fri Mar 14, 2014 12:03 am

Ok, some parts are really obscure and i'm even wondering how t worked ^^ You have 2 variables : vpos and ypos, you modify ypos only and use vpos only to define image position O_o ? Also you test ind with == instead of >= ...

Here is a version that should work better:

Code: Select all

...
maxInd = TILE_USERINDEX + TILE_USERLENGTH - 1;
...

for(i = 174; i < 214; i++)
{
    ...
    Image *img = images[i];
    // number of tile of current image
    u16 numTile = img->tileset->numTile;

    // no enough vram space for the current image ? restart 
    if ((ind + numTile) >= maxInd)
        ind = newInd;
            
    u16 nextvpos =  vpos ^ 0x20;
    VDP_drawImageEx(BPLAN, images[i], TILE_ATTR_FULL(pal, FALSE, FALSE, FALSE, ind), 7, nextvpos + 4, TRUE, TRUE);
    // move to new image
    VDP_waitVSync();
    VDP_setVerticalScroll(BPLAN, nextvpos);

    ind += numTile;
    pal ^= 1;
    vpos = nextvpos;
    waitTick(100);
}
Last edited by Stef on Fri Mar 14, 2014 9:03 am, edited 1 time in total.

Post Reply