Ejemplo n.º 1
0
static void init_vtx(GXRModeObj *mode)
{
   GX_SetViewport(0, 0, mode->fbWidth, mode->efbHeight, 0, 1);
   GX_SetDispCopyYScale(GX_GetYScaleFactor(mode->efbHeight, mode->xfbHeight));
   GX_SetScissor(0, 0, mode->fbWidth, mode->efbHeight);
   GX_SetDispCopySrc(0, 0, mode->fbWidth, mode->efbHeight);
   GX_SetDispCopyDst(mode->fbWidth, mode->xfbHeight);
   GX_SetCopyFilter(mode->aa, mode->sample_pattern, (mode->xfbMode == VI_XFBMODE_SF) ? GX_FALSE : GX_TRUE,
         mode->vfilter);
   GX_SetCopyClear((GXColor) { 0, 0, 0, 0xff }, GX_MAX_Z24);
   GX_SetFieldMode(mode->field_rendering, (mode->viHeight == 2 * mode->xfbHeight) ? GX_ENABLE : GX_DISABLE);

   GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
   GX_SetZMode(GX_ENABLE, GX_ALWAYS, GX_ENABLE);
   GX_SetColorUpdate(GX_TRUE);
   GX_SetAlphaUpdate(GX_FALSE);

   Mtx44 m;
   guOrtho(m, 1, -1, -1, 1, 0.4, 0.6);
   GX_LoadProjectionMtx(m, GX_ORTHOGRAPHIC);

   GX_ClearVtxDesc();
   GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
   GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);

   GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
   GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
   GX_SetArray(GX_VA_POS, verts, 3 * sizeof(float));
   GX_SetArray(GX_VA_TEX0, tex_coords, 2 * sizeof(float));

   GX_SetNumTexGens(1);
   GX_SetNumChans(0);
   GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
   GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLORNULL);
   GX_InvVtxCache();

   GX_Flush();
}
Ejemplo n.º 2
0
void
skybox_render (skybox_info *skybox)
{
  const u32 vtxfmt = GX_VTXFMT0;
  int face;

  GX_ClearVtxDesc ();
  GX_SetVtxDesc (GX_VA_POS, GX_INDEX8);
  GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT);
  
  GX_SetArray (GX_VA_POS, vertices, 3 * sizeof (f32));
  
  GX_SetVtxAttrFmt (vtxfmt, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
  GX_SetVtxAttrFmt (vtxfmt, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
  
  GX_SetCullMode (GX_CULL_BACK);
  
  for (face = 0; face < 6; face++)
    {
      shader_load (skybox->face_shader[face]);

      GX_Begin (GX_TRIANGLESTRIP, vtxfmt, 4);

      GX_Position1x8 (faces[face][0]);
      GX_TexCoord2f32 (0, 1);

      GX_Position1x8 (faces[face][1]);
      GX_TexCoord2f32 (0, 0);

      GX_Position1x8 (faces[face][2]);
      GX_TexCoord2f32 (1, 1);

      GX_Position1x8 (faces[face][3]);
      GX_TexCoord2f32 (1, 0);

      GX_End ();
    }
}
Ejemplo n.º 3
0
void BoxCover::Draw()
{
	u8 BoxAlpha = (int) (alpha+alphaDyn) & 0xFF;

	GX_LoadProjectionMtx(projection, GX_PERSPECTIVE);

	GX_ClearVtxDesc();
	GX_InvVtxCache();
	GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
	GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8);

	//! don't draw inside of the box
	GX_SetCullMode(GX_CULL_FRONT);

	Mtx	modelView;
	Mtx	modelView2;
	Mtx	modelView3;

	guVector cubeAxis = {0,0,1};
	guVector cubeAxis2 = {0,1,0};
	guVector cubeAxis3 = {1,0,0};
	guMtxIdentity(modelView);
	guMtxRotAxisDeg(modelView3, &cubeAxis3, RotX-Animation2);
	guMtxRotAxisDeg(modelView2, &cubeAxis2, RotY+Animation2+xoffsetDyn/2.0f);
	guMtxRotAxisDeg(modelView, &cubeAxis, RotZ-Animation);
	guMtxConcat(modelView3, modelView2, modelView2);
	guMtxConcat(modelView2, modelView, modelView);
	if(Settings.widescreen)
		guMtxScaleApply(modelView, modelView, Settings.WSFactor, 1.0f, 1.0f);
	guMtxTransApply(modelView, modelView, PosX+xoffsetDyn/680.0f+movePosX, PosY+yoffsetDyn/680.0f+movePosY, PosZ);
	guMtxConcat(view,modelView,modelView);

	GX_LoadPosMtxImm(modelView,	GX_PNMTX0);

	//! Border quads
	GX_LoadTexObj(&boxBorderTex, GX_TEXMAP0);
	GX_InvalidateTexAll();

	GX_SetArray(GX_VA_POS, (void *) &g_boxMeshQ[0].pos, sizeof(g_boxMeshQ[0]));
	GX_SetArray(GX_VA_TEX0, (void *) &g_boxMeshQ[0].texCoord, sizeof(g_boxMeshQ[0]));

	GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxMeshQSize);
	for (u32 j = 0; j < g_boxMeshQSize; ++j)
	{
		GX_Position1x8(j);
		GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
		GX_TexCoord1x8(j);
	}
	GX_End();

	//! Border triangles
	GX_SetArray(GX_VA_POS, (void *) &g_boxMeshT[0].pos, sizeof(g_boxMeshT[0]));
	GX_SetArray(GX_VA_TEX0, (void *) &g_boxMeshT[0].texCoord, sizeof(g_boxMeshT[0]));

	GX_Begin(GX_TRIANGLES, GX_VTXFMT0, g_boxMeshTSize);
	for (u32 j = 0; j < g_boxMeshTSize; ++j)
	{
		GX_Position1x8(j);
		GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
		GX_TexCoord1x8(j);
	}
	GX_End();

	//! Back Cover (Might be flat)
	GX_LoadTexObj(flatCover ? &defaultBoxTex : &coverTex, GX_TEXMAP0);
	GX_InvalidateTexAll();

	GX_SetArray(GX_VA_POS, (void *) &g_boxBackCoverMesh[0].pos, sizeof(g_boxBackCoverMesh[0]));
	GX_SetArray(GX_VA_TEX0, (void *) &g_boxBackCoverMesh[0].texCoord, sizeof(g_boxBackCoverMesh[0]));

	GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxBackCoverMeshSize);
	for (u32 j = 0; j < g_boxBackCoverMeshSize; ++j)
	{
		GX_Position1x8(j);
		if(flatCover)
			GX_Color4u8(boxColor.r, boxColor.g, boxColor.b, BoxAlpha);
		else
			GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
		GX_TexCoord1x8(j);
	}
	GX_End();

	if(flatCover)
	{
		//! Front Flat Cover
		GX_LoadTexObj(&coverTex, GX_TEXMAP0);
		GX_InvalidateTexAll();

		GX_SetArray(GX_VA_POS, (void *) &g_flatCoverMesh[0].pos, sizeof(g_flatCoverMesh[0]));
		GX_SetArray(GX_VA_TEX0, (void *) &g_flatCoverMesh[0].texCoord, sizeof(g_flatCoverMesh[0]));

		GX_Begin(GX_QUADS, GX_VTXFMT0, g_flatCoverMeshSize);
		for (u32 j = 0; j < g_flatCoverMeshSize; ++j)
		{
			GX_Position1x8(j);
			GX_Color4u8(0xff, 0xff, 0xff, 0xff);
			GX_TexCoord1x8(j);
		}
		GX_End();
	}
	else
	{
		//! Front Cover
		GX_SetArray(GX_VA_POS, (void *) &g_boxCoverMesh[0].pos, sizeof(g_boxCoverMesh[0]));
		GX_SetArray(GX_VA_TEX0, (void *) &g_boxCoverMesh[0].texCoord, sizeof(g_boxCoverMesh[0]));

		GX_Begin(GX_QUADS, GX_VTXFMT0, g_boxCoverMeshSize);
		for (u32 j = 0; j < g_boxCoverMeshSize; ++j)
		{
			GX_Position1x8(j);
			GX_Color4u8(0xff, 0xff, 0xff, BoxAlpha);
			GX_TexCoord1x8(j);
		}
		GX_End();
	}

	//! stop cull
	GX_SetCullMode(GX_CULL_NONE);

	UpdateEffects();
}
Ejemplo n.º 4
0
model_t* MODEL_setup(const u8* model_bmb) {
	binheader_t* header = (binheader_t*) model_bmb;

	const u32 posOffset = sizeof(binheader_t);
	const u32 nrmOffset = posOffset + (sizeof(f32)* header->vcount * 3);
	const u32 texOffset = nrmOffset + (sizeof(f32)* header->vcount * 3);
	const u32 indOffset = texOffset + (sizeof(f32)* header->vcount * 2);

	f32* positions = (f32*) (model_bmb + posOffset);
	f32* normals = (f32*) (model_bmb + nrmOffset);
	f32* texcoords = (f32*) (model_bmb + texOffset);
	u16* indices = (u16*) (model_bmb + indOffset);

	/* Calculate cost */
	const u32 indicesCount = header->fcount * 3;
	const u32 indicesSize = indicesCount * 3 * sizeof(u16); /* 3 indices per vertex index (p,n,t) that are u16 in size */
	const u32 callSize = 89; /* Size of setup var */
	/* Round up to nearest 32 multiplication */
	const u32 dispSize = (((indicesSize + callSize + 63) >> 5) + 1) << 5;

	/* Build display list */
	/* Allocate and clear */
	u32 i;
	void* modelList = memalign(32, dispSize);
	memset(modelList, 0, dispSize);

	/* Set buffer data */
	DCInvalidateRange(modelList, dispSize);
	GX_BeginDispList(modelList, dispSize);

	//GX_InvVtxCache();
	GX_ClearVtxDesc();
	GX_SetVtxDesc(GX_VA_POS, GX_INDEX16);
	GX_SetVtxDesc(GX_VA_NRM, GX_INDEX16);
	GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);

	GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
	GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
	GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);

	GX_SetArray(GX_VA_POS, (void*) positions, 3 * sizeof(f32));
	GX_SetArray(GX_VA_NRM, (void*) normals, 3 * sizeof(f32));
	GX_SetArray(GX_VA_TEX0, (void*) texcoords, 2 * sizeof(f32));

	/* Fill the list with indices */
	GX_Begin(GX_TRIANGLES, GX_VTXFMT0, indicesCount);
	for (i = 0; i < indicesCount; i++) {
		GX_Position1x16(indices[i]);
		GX_Normal1x16(indices[i]);
		GX_TexCoord1x16(indices[i]);
	}
	GX_End();

	/* Close display list */
	u32 modelListSize = GX_EndDispList();
	if (modelListSize == 0) {
		printf("Error: Display list not big enough [%u]\n", dispSize);
		return NULL;
	}

	/* Return model info */
	model_t* model = malloc(sizeof(model_t));
	model->modelList = modelList;
	model->modelListSize = modelListSize;

	model->modelFaceCount = header->fcount;
	model->modelPositions = positions;
	model->modelNormals = normals;
	model->modelTexcoords = texcoords;
	model->modelIndices = indices;

	return model;
}
Ejemplo n.º 5
0
void gdl::Font::DrawText(const char *text, short x, short y, float scale, u_int col) {

    float	tx;
    GXColor textCol;
    Mtx		tempMatrix;


    if (vList == NULL)
        return;

    if (tList == NULL)
        return;


    if ((x == gdl::Centered) || (x == gdl::PCentered)) {
        tx = gdl::ScreenCenterX-((gdl::Font::CalcStrLen(text)*scale)/2)+(scale/2);
    } else {
        tx = x;
    }


    textCol.r = RED(col);
    textCol.g = GREEN(col);
    textCol.b = BLUE(col);
    textCol.a = ALPHA(col);

    GX_LoadTexObj(gdl::Font::charSheet.TexObj(), GX_TEXMAP0);
    GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);

    GX_ClearVtxDesc();
    GX_SetVtxDesc(GX_VA_POS, GX_INDEX16);
    GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);

    GX_SetArray(GX_VA_POS, gdl::Font::vList, 2*sizeof(s16));
    GX_SetArray(GX_VA_TEX0, gdl::Font::tList, 2*sizeof(f32));

    GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_REG, 0, GX_DF_NONE, GX_AF_NONE);
    GX_SetChanMatColor(GX_COLOR0A0, textCol);


    guMtxCopy(gdl::wii::ModelMtx, tempMatrix);
    guMtxApplyTrans(tempMatrix, tempMatrix, tx, y, 0);
    guMtxApplyScale(tempMatrix, tempMatrix, scale, scale, 0);
    GX_LoadPosMtxImm(tempMatrix, GX_PNMTX0);


    for(int i=0; text[i]!=0x00; i++) {

        int tc=4*((u_char)text[i]);

        GX_Begin(GX_QUADS, GX_VTXFMT0, 4);

        GX_Position1x16(tc);
        GX_TexCoord1x16(tc);

        GX_Position1x16(tc+1);
        GX_TexCoord1x16(tc+1);

        GX_Position1x16(tc+2);
        GX_TexCoord1x16(tc+2);

        GX_Position1x16(tc+3);
        GX_TexCoord1x16(tc+3);

        GX_End();

        guMtxApplyTrans(tempMatrix, tempMatrix, gdl::Font::charWidth[(u_char)text[i]], 0, 0);
        GX_LoadPosMtxImm(tempMatrix, GX_PNMTX0);

    }

    GX_LoadPosMtxImm(gdl::wii::ModelMtx, GX_PNMTX0);
    GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_VTX, 0, GX_DF_NONE, GX_AF_NONE);

}
Ejemplo n.º 6
0
void gdl::FFont::DrawText(const char *text, short x, short y, float scale, u32 col) {

    // Draws text using the current font set by gdl_SetCurrentFont()

    float	tx;
    int		c,tc;
    Mtx		TempMatrix;
    GXColor	TempCol;


    if (vList == NULL)
        return;


    if ((x == gdl::Centered) || (x == gdl::PCentered)) {
        tx = gdl::ScreenCenterX - ((((cw+1)*strlen(text))*scale)/2)+(scale/2);
    } else {
        tx = x;
    }

    TempCol.r = RED(col);
    TempCol.g = GREEN(col);
    TempCol.b = BLUE(col);
    TempCol.a = ALPHA(col);


    GX_LoadTexObj(charTexObj, GX_TEXMAP0);
    GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);

    GX_ClearVtxDesc();
    GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
    GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);

    GX_SetArray(GX_VA_POS, vList, 2*sizeof(s16));
    GX_SetArray(GX_VA_TEX0, tList, 2*sizeof(f32));


    guMtxCopy(gdl::wii::ModelMtx, TempMatrix);
    guMtxApplyTrans(TempMatrix, TempMatrix, tx, y, 0);
    guMtxApplyScale(TempMatrix, TempMatrix, scale, scale, 0);
    GX_LoadPosMtxImm(TempMatrix, GX_PNMTX0);

    GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_REG, 0, GX_DF_NONE, GX_AF_NONE);
    GX_SetChanMatColor(GX_COLOR0A0, TempCol);

    for(c=0; text[c] != 0x00; c++) {

        tc = 4*((u_char*)text)[c];

        GX_Begin(GX_QUADS, GX_VTXFMT0, 4);

        GX_Position1x8(0);
        GX_TexCoord1x16(tc);

        GX_Position1x8(1);
        GX_TexCoord1x16(tc+1);

        GX_Position1x8(2);
        GX_TexCoord1x16(tc+2);

        GX_Position1x8(3);
        GX_TexCoord1x16(tc+3);

        GX_End();

        guMtxApplyTrans(TempMatrix, TempMatrix, cw+1, 0, 0);
        GX_LoadPosMtxImm(TempMatrix, GX_PNMTX0);

    }

    GX_LoadPosMtxImm(gdl::wii::ModelMtx, GX_PNMTX0);
    GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_VTX, 0, GX_DF_NONE, GX_AF_NONE);

}