Page 1 of 1

Better method for scrolling textures?

Posted: November 6th, 2019, 9:00 pm
by ArthCarvalho
I'm trying to create a code to animate scrolling textures.
One of the ways I came up with was to using the MoveImage() function.
But it has one problem: You can't properly scroll 4bit textures or 8bit textures properly in the X axis (works fine for the Y axis though).
Plus I have no idea of how it impacts performance.

This is the code I'm currently using:

Code: Select all

// Texture Scroller
RECT txa_copy[4];
short txa_src_x, txa_src_y;
short txa_dst_x, txa_dst_y;
unsigned char txa_w, txa_h;
unsigned char txa_ofs_x, txa_ofs_y;
char txa_spd_x;
char txa_spd_y;

void TexAnim_Setup(short sx, short sy, short dx, short dy, unsigned char w, unsigned char h, char spdx, char spdy) {
  txa_src_x = sx;
  txa_src_y = sy;
  txa_dst_x = dx;
  txa_dst_y = dy;
  txa_w = w;
  txa_h = h;
  txa_ofs_x = 0;
  txa_ofs_y = 0;
  txa_spd_x = spdx;
  txa_spd_y = spdy;
}

void TexAnim_Update() {
  
  txa_copy[0].x = txa_src_x;
  txa_copy[0].y = txa_src_y;
  txa_copy[0].w = txa_w - txa_ofs_x;
  txa_copy[0].h = txa_h - txa_ofs_y;
  
  txa_copy[1].x = txa_src_x + (txa_w - txa_ofs_x) % txa_w;
  txa_copy[1].y = txa_src_y + (txa_h - txa_ofs_y) % txa_w;
  txa_copy[1].w = txa_ofs_x;
  txa_copy[1].h = txa_ofs_y;
  
  txa_copy[2].x = txa_copy[0].x;
  txa_copy[2].w = txa_copy[0].w;
  
  txa_copy[2].y = txa_copy[1].y;
  txa_copy[2].h = txa_copy[1].h;
  
  txa_copy[3].x = txa_copy[0].x;
  txa_copy[3].w = txa_copy[0].w;
  
  txa_copy[3].y = txa_copy[0].y;
  txa_copy[3].h = txa_copy[0].h;
  
  MoveImage(&txa_copy[0], txa_dst_x+txa_ofs_x, txa_dst_y+txa_ofs_y);
  MoveImage(&txa_copy[1], txa_dst_x, txa_dst_y);
  MoveImage(&txa_copy[2], txa_dst_x, txa_dst_y);
  MoveImage(&txa_copy[3], txa_dst_x, txa_dst_y+txa_ofs_y);
  
  txa_ofs_x = (txa_ofs_x + txa_spd_x)%txa_w;
  txa_ofs_y = (txa_ofs_y + txa_spd_y)%txa_h;
}
The code is messy, mainly because I'm still figuring out how to do this.

I've heard that I could change the Draw Environment and render polygons to some texture page in order to achieve this, but I'm not sure exactly how to do it, or even, if it has better performance than this.

Re: Better method for scrolling textures?

Posted: November 8th, 2019, 11:51 am
by LameGuy64
You have to do texture scrolling by manipulating the UV coordinates of the sprite or textured polygon primitive. You will also need to use the DR_TWIN and SetTexWindow to place texture window primitives so you can set the texture window constraint to allow for textures smaller than 256x256 to be wrapped. Using MoveImage() to scroll textures is horribly inefficient and likely problematic.

I have an example that demonstrates scrolling textures and texture windows in the self-hosted SVN repo of PSn00bSDK inmy website, as well as direct render to texture using draw attribute primitives to change the drawing target on the fly.

Re: Better method for scrolling textures?

Posted: November 9th, 2019, 9:34 am
by ArthCarvalho
Is using a Texture Window a good option? I don't think I've seen any comercial games using Texture Windows to scroll, so I thought it was no good.

Which one of the examples in your SDK has those functions?

Re: Better method for scrolling textures?

Posted: November 12th, 2019, 11:44 am
by LameGuy64
Its not included in the github repository yet, but it is on my self hosted SVN. Its in the render2tex example.