Files
Microtransactions64/s2d_draw.c

90 lines
2.2 KiB
C
Raw Normal View History

2020-12-11 21:47:11 -05:00
#include <ultra64.h>
#include "config.h"
#include "mtx.h"
int myScale = 1;
2020-12-12 15:33:14 -05:00
int myDegrees = 0;
2020-12-11 21:47:11 -05:00
uObjMtx final_mtx, rot_mtx;
int s2d_red = 255, s2d_green = 255, s2d_blue = 255, s2d_alpha = 255;
2020-12-12 15:33:14 -05:00
2020-12-11 21:47:11 -05:00
static Gfx s2d_init_dl[] = {
gsDPPipeSync(),
gsDPSetTexturePersp(G_TP_NONE),
gsDPSetTextureLOD(G_TL_TILE),
gsDPSetTextureLUT(G_TT_NONE),
gsDPSetTextureConvert(G_TC_FILT),
gsDPSetAlphaCompare(G_AC_THRESHOLD),
gsDPSetBlendColor(0, 0, 0, 0x01),
2020-12-12 19:45:53 -05:00
// IA8
gsDPSetCombineLERP(0, 0, 0, ENVIRONMENT,
0, 0, 0, TEXEL0,
0, 0, 0, ENVIRONMENT,
0, 0, 0, TEXEL0),
2020-12-11 21:47:11 -05:00
gsSPEndDisplayList(),
};
void setup_font(int idx) {
gDPPipeSync(gdl_head++);
gDPSetTextureFilter(gdl_head++, G_TF_POINT);
gSPDisplayList(gdl_head++, s2d_init_dl);
gDPSetEnvColor(gdl_head++, s2d_red, s2d_green, s2d_blue, s2d_alpha);
gDPSetCycleType(gdl_head++, G_CYC_1CYCLE);
gDPSetRenderMode(gdl_head++, G_RM_XLU_SPRITE, G_RM_XLU_SPRITE2);
gSPObjRenderMode(gdl_head++, G_OBJRM_XLU | G_OBJRM_BILERP);
gSPObjLoadTxtr(gdl_head++, &s2d_tex[idx]);
2020-12-12 15:33:14 -05:00
}
// Original Mtx Pipeline
// Distorts when rotating, but is faster
2020-12-11 21:47:11 -05:00
void mtx_pipeline(uObjMtx *m, int x, int y) {
2020-12-12 15:33:14 -05:00
// init
2020-12-11 21:47:11 -05:00
mat2_ident(m, 1);
mat2_ident(&rot_mtx, 1);
2020-12-12 15:33:14 -05:00
// create rot matrix
mat2_rotate(&rot_mtx, (myDegrees) * (M_PI / 180.0f));
// scale m
2020-12-11 21:47:11 -05:00
mat2_scale(m, myScale);
2020-12-12 15:33:14 -05:00
mat2_dst_mul(m,m, &rot_mtx);
2020-12-11 21:47:11 -05:00
mat2_translate(m, x, y);
2020-12-12 15:33:14 -05:00
gSPObjMatrix(gdl_head++, m);
2020-12-12 15:33:14 -05:00
}
// New matrix pipeline
// Works with both rotation and scale,
// but is slow due to more float operations being performed
2020-12-12 15:33:14 -05:00
void mtx_pipeline2(uObjMtx *m, int x, int y) {
// init
Mat4 tmp, rot, scal, translate;
guMtxIdentF(tmp);
guScaleF(scal, myScale, myScale, 0);
guRotateF(rot, (f32) myDegrees, 0, 0, 1.0f);
guTranslateF(translate, x, y, 0);
mtxf_mul(tmp, tmp, scal);
mtxf_mul(tmp, tmp, rot);
mtxf_mul(tmp, tmp, translate);
gu_to_gs2dex(m, tmp);
if (myDegrees != 0) {
mat2_translate_vec(m, -(myDegrees) * M_DTOR, myScale);
}
gSPObjMatrix(gdl_head++, m);
2020-12-11 21:47:11 -05:00
}
2020-12-11 22:51:58 -05:00
void draw_s2d_glyph(char c, int x, int y, uObjMtx *mt) {
2020-12-11 21:47:11 -05:00
setup_font(c);
2020-12-12 15:47:12 -05:00
// mtx_pipeline(mt, x, y);
mtx_pipeline2(mt, x, y);
gSPObjSprite(gdl_head++, &s2d_font);
2020-12-11 22:51:58 -05:00
}
2020-12-12 15:33:14 -05:00