Page 2 of 3

Posted: Tue Oct 11, 2011 9:13 am
by Stef
sega16 wrote:Using this code it will double SOME lines but not all.I believe the reason for this is because the code is not fast enough but what could I do to make it better?
If you have H Int at each scanline your code should fit in a very small amount of cycles : we have about 488 68k cycles by scanline but the SGDK H int handler already eat a part of it (about 120 cycles) so it leave 350 cycles for your code.

You don't have to check for end of screen as H Int doesn't happen during VBlank so you can do frame initialization process in the V Int callback instead.

your H Int code can be :

Code: Select all

    *((u16 *) GFX_DATA_PORT) = vscroll;
    if (the_scroll ^= 1) vscroll--;
Then your V Int code should end by :

Code: Select all

    ...
    // re init VScroll
    vscroll=0x800; 
    // prepare H Int V Scroll writes
    *((u32 *) GFX_CTRL_PORT) = GFX_WRITE_VSRAM_ADDR(0);

Re: Raster Effect with Gendev ( SGDK)

Posted: Thu Jan 14, 2016 8:15 pm
by alko
Shalom.

Please show me the complete source code of this effect (vertical scaling).

Re: Raster Effect with Gendev ( SGDK)

Posted: Sat Jan 16, 2016 1:53 pm
by alko
8) I really need this effect 8)

Re: Raster Effect with Gendev ( SGDK)

Posted: Wed Feb 10, 2016 6:39 pm
by alko
up...

Re: Raster Effect with Gendev ( SGDK)

Posted: Wed Mar 30, 2016 12:48 pm
by alko
alko wrote:Shalom.

Please show me the complete source code of this effect (vertical scaling).
:oops: It is even possible to implement by means of SGDK?

Re: Raster Effect with Gendev ( SGDK)

Posted: Wed Mar 30, 2016 8:25 pm
by ehaliewicz
alko wrote:
alko wrote:Shalom.

Please show me the complete source code of this effect (vertical scaling).
:oops: It is even possible to implement by means of SGDK?
What are you trying to do? Scaling sprites vertically?

Edit: nevermind, read the first page of the thread

Re: Raster Effect with Gendev ( SGDK)

Posted: Wed Mar 30, 2016 9:02 pm
by alko

Re: Raster Effect with Gendev ( SGDK)

Posted: Sat Apr 02, 2016 5:18 pm
by Stef
Just use the h interrupt callback for that :)

Use :

Code: Select all

// Set H-Int callback
SYS_setHIntCallback(&hint_cb);
// enable H-Interrupt
VDP_setHInterrupt(1);
// set H-int line count occorence
VDP_setHIntCounter(1)
to define the hint callback method and enable H-Int for each scanline.
Then in the H-int callback you need to modify the Vertical scroll value using:

Code: Select all

void hint_cb()
{
  // modify vertical scroll
  VDP_setVerticalScroll(BPLAN, scrollValue);
}
of course you have to set a specific 'scrollValue' at each scanline to give scaling effect.

Re: Raster Effect with Gendev ( SGDK)

Posted: Mon Apr 04, 2016 5:45 pm
by alko
background is flattened, but an image is unstable.

Image

Code: Select all

....
static u32 vscrol;
void hint_cb()
{
   VDP_setVerticalScroll(PLAN_B, vscrol);
   vscrol += 8;
}

main()
{
...
while(TRUE)
{
...
SYS_setHIntCallback(&hint_cb);
VDP_setHInterrupt(1);
VDP_setHIntCounter(1);
VDP_waitVSync();   
}

}


Re: Raster Effect with Gendev ( SGDK)

Posted: Tue Apr 05, 2016 3:24 pm
by Stef
Are you resetting 'vscrol' at V-Int ? looks like you aren't..

Re: Raster Effect with Gendev ( SGDK)

Posted: Tue Apr 05, 2016 5:52 pm
by alko
Stef wrote:Are you resetting 'vscrol' at V-Int ? looks like you aren't..
Oh, thanx! :roll:

Yet I keep getting flattened image.
How do stretch the picture?

Re: Raster Effect with Gendev ( SGDK)

Posted: Tue Apr 05, 2016 8:39 pm
by Stef
Decrease 'vscrol' instead of increasing it =)
Using fix16 value will allow you to have smooth vertical scaling.

Re: Raster Effect with Gendev ( SGDK)

Posted: Tue Feb 02, 2021 1:13 pm
by danibus
Would you be so kind to provide an example? I'm trying to strech and scroll a plane (not sprites)
I want to use a plane to show a path, like sonic 3d bonus path or similar.
This is SGDK old version.

Trying with no success :(

This is my code, something is missed I think, nothing happens (?)

Code: Select all

#include <genesis.h>

static u32 vscrol;
            
            void hint_cb()
            {
               VDP_setVerticalScroll(PLAN_B, vscrol);
               vscrol += 8;
            }

int main(){

    s16 id_tile_inicial = 0;
    s16 id_tile_final_planB = 0;
    s16 id_tile_final_planA = 0;

    //PLANO B
    VDP_drawImageEx(PLAN_B, &fondo_fase3B, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, id_tile_inicial), 0, 0, FALSE, TRUE);
    id_tile_final_planB = id_tile_inicial + fondo_fase3B.tileset->numTile;
    //PLANO A
    VDP_drawImageEx(PLAN_A, &fondo_fase3A, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, id_tile_final_planB), 0, 0, FALSE, TRUE);
    id_tile_final_planA = id_tile_final_planB + fondo_fase3A.tileset->numTile;

	while (1) {

        VDP_setScreenWidth320();
        SPR_init();

        SYS_setHIntCallback(&hint_cb);
        VDP_setHInterrupt(1);
        VDP_setHIntCounter(1);

        SPR_update();
        VDP_waitVSync();
	}

	return 0;
}


Re: Raster Effect with Gendev ( SGDK)

Posted: Tue Feb 02, 2021 9:16 pm
by Joe Musashi
Here's a quick example how this can be done with SGDK 1.60.

scaling.png
scaling.png (16.45 KiB) Viewed 8491 times

In this example HInt and VInt look like this:

Code: Select all

    static u8    lineDisplay  = 0;          // line position on display screen
    static fix16 lineGraphics = 0;          // line position in graphics texture
    static fix16 scroll       = 0;          // scrolling offset
    static fix16 scale        = FIX16(4.0); // scaling factor

    void HIntHandler()
    {
        // Set line to display
        VDP_setVerticalScroll(BG_B, fix16ToInt(lineGraphics) - lineDisplay);

        // Determine next graphics line to display (+1 means image is unscaled)
        lineGraphics += scale;

        // Count raster lines
        lineDisplay++;

        // Decrease scaling factor each line
        scale -= FIX16(0.02);
    }
    void VIntHandler()
    {
        // Make sure HInt always starts with line 0
        lineDisplay = 0;

        // Reset first line we want to display
	lineGraphics = scroll;

        // Decrease scrolling offset, reset after 64 lines
	scroll = (scroll - FIX16(1)) % FIX16(64);

        // Reset scaling factor
	scale = FIX16(4.0);
 }
There are a couple of things that are important:
  • We need to count the scanlines HInt is in. This is done with lineDisplay, which counts from 0 to 223, and is reset in VInt.
  • lineGraphics specifies in each scanline which graphics line we want to display. If the image is not scaled, this is the same as lineDisplay. If the image size is doubled this would be lineDisplay / 2. If we want a perspective effect the scaling factor needs to be modified each line (scale variable).
  • VDP_setVerticalScroll() requires a relative value, so we have to supply lineGraphics - lineDisplay to show a specific line.
  • The scaling factor needs to be FIX16 so we can have values < 1 (scale = 0.5 doubles the image size).
  • To achieve scrolling, the start value of lineGraphics must be altered each frame. Here we just count down 63, ... 0.

Re: Raster Effect with Gendev ( SGDK)

Posted: Tue Feb 02, 2021 10:43 pm
by danibus
WoW! Nice explanation, many thanks.
Tomorrow morning I will try, still see these tricks like magic.