You are not logged in.

#1 2008-06-24 03:26:27

grillo
Member

Tinted ImageDraw

I just modified the GRRLIB_DrawImg so it could accept a u32 format color instead of the u8 alpha to tint it. It's cool if you want to reuse images by painting them

Code:

inline void GRRLIB_DrawImgTint(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[], float degrees, float scaleX, f32 scaleY ,u32 tint){

   GXTexObj texObj;
   GXColor col = GRRLIB_Splitu32(tint);    //Added this

    GX_InitTexObj(&texObj, data, width,height, GX_TF_RGBA8,GX_CLAMP, GX_CLAMP,GX_FALSE);
    //GX_InitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1);
    GX_LoadTexObj(&texObj, GX_TEXMAP0);

    GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
      GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);

    Mtx m,m1,m2, mv;
    width *=.5;
    height*=.5;
    guMtxIdentity (m1);
    guMtxScaleApply(m1,m1,scaleX,scaleY,1.0);
    Vector axis =(Vector) {0 , 0, 1 };
    guMtxRotAxisDeg (m2, &axis, degrees);
    guMtxConcat(m2,m1,m);

    guMtxTransApply(m,m, xpos+width,ypos+height,0);
    guMtxConcat (GXmodelView2D, m, mv);
    GX_LoadPosMtxImm (mv, GX_PNMTX0);
    
    GX_Begin(GX_QUADS, GX_VTXFMT0,4);

      GX_Position3f32(-width, -height,  0);
    GX_Color4u8(col.r,col.g,col.b,col.a);    //Changed here
      GX_TexCoord2f32(0, 0);

        GX_Position3f32(width, -height,  0);
    GX_Color4u8(col.r,col.g,col.b,col.a);    //Changed here
      GX_TexCoord2f32(1, 0);

      GX_Position3f32(width, height,  0);
    GX_Color4u8(col.r,col.g,col.b,col.a);    //Changed here
      GX_TexCoord2f32(1, 1);

      GX_Position3f32(-width, height,  0);
    GX_Color4u8(col.r,col.g,col.b,col.a);    //Changed here
      GX_TexCoord2f32(0, 1);

    GX_End();

    GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0);

    GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR);
      GX_SetVtxDesc (GX_VA_TEX0, GX_NONE);

}

You should use light grey images to get the best result though ;D

Offline

 

Board footer

Powered by FluxBB