GX_REPEAT

Post Reply
Eke
Posts: 64
Joined: Sat Mar 01, 2008 11:01 am

GX_REPEAT

Post by Eke » Mon Apr 06, 2009 5:13 pm

Hi

I would like to render a 16x16 textured tile over the whole framebuffer (640x480), mainly to use as background texture

I was thinking about using GX_REPEAT mode but it does not seems to work properly (the texture is still "stretched" instead of being "repeated")

Here's the code I'm using, the png_texture holds the size of the texture (16x16 in my case), the parameters of the function are the final position & size on screen (0,0,640,480 in my case)

Code: Select all

void DrawTextureRepeat(png_texture *texture, int x, int y, int w, int h)
{
  if (texture->data)
  {
    /* load texture object */
    GXTexObj texObj;
    GX_InitTexObj(&texObj, texture->data, texture->width, texture->height, GX_TF_RGBA8, GX_REPEAT, GX_REPEAT, GX_FALSE);
    GX_LoadTexObj(&texObj, GX_TEXMAP0);
    GX_InvalidateTexAll();

    /* adjust coordinate system */
    x -= (vmode->fbWidth/2);
    y -= (vmode->efbHeight/2);

    /* Draw textured quad */
    GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
    GX_Position2s16(x,y+h);
    GX_Color4u8(0xff,0xff,0xff,0xff);
    GX_TexCoord2f32(0.0, 1.0);
    GX_Position2s16(x+w,y+h);
    GX_Color4u8(0xff,0xff,0xff,0xff);
    GX_TexCoord2f32(1.0, 1.0);
    GX_Position2s16(x+w,y);
    GX_Color4u8(0xff,0xff,0xff,0xff);
    GX_TexCoord2f32(1.0, 0.0);
    GX_Position2s16(x,y);
    GX_Color4u8(0xff,0xff,0xff,0xff);
    GX_TexCoord2f32(0.0, 0.0);
    GX_End ();
    GX_DrawDone();
  }
}
Is there something wrong with this code ? Is there someting more required to use the "REPEAT" mode ?

Thanks

Eke
Posts: 64
Joined: Sat Mar 01, 2008 11:01 am

Re: GX_REPEAT

Post by Eke » Tue Apr 07, 2009 8:38 am

Seems like the following code did the job, not really sure why though, I tried this out of luck.
Still didn't get GX_REPEAT to work properly however.

Code: Select all

void DrawTextureRepeat(png_texture *texture, int x, int y, int w, int h)
{
  if (texture->data)
  {
    /* load texture object */
    GXTexObj texObj;
    GX_InitTexObj(&texObj, texture->data, texture->width, texture->height, GX_TF_RGBA8, GX_MIRROR, GX_MIRROR, GX_FALSE);
    GX_LoadTexObj(&texObj, GX_TEXMAP0);
    GX_InvalidateTexAll();

    /* vertex coordinate */
    x -= (vmode->fbWidth/2);
    y -= (vmode->efbHeight/2);

    /* texture coordinates */
    f32 s = (f32)vmode->fbWidth / (f32)texture->width;
    f32 t = (f32)vmode->efbHeight / (f32)texture->height;

    /* draw textured quad */
    GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
    GX_Position2s16(x,y+h);
    GX_Color4u8(0xff,0xff,0xff,0xff);
    GX_TexCoord2f32(0.0, t);
    GX_Position2s16(x+w,y+h);
    GX_Color4u8(0xff,0xff,0xff,0xff);
    GX_TexCoord2f32(s, t);
    GX_Position2s16(x+w,y);
    GX_Color4u8(0xff,0xff,0xff,0xff);
    GX_TexCoord2f32(s, 0.0);
    GX_Position2s16(x,y);
    GX_Color4u8(0xff,0xff,0xff,0xff);
    GX_TexCoord2f32(0.0, 0.0);
    GX_End ();
    GX_DrawDone();
  }
}

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests