Untitled
unknown
plain_text
17 days ago
4.3 kB
13
Indexable
#include <nusys.h> #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 #define GLIST_LENGTH 1024 static Gfx glist[GLIST_LENGTH]; static Gfx* glistp; static float viewMatF[4][4]; //Viewport static Vp viewport = { SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2, G_MAXZ / 2, 0, SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2, G_MAXZ / 2, 0, }; //Cube vertices static Vtx cubeVerts[] = { {-10, -10, -10, 0, 0, 0, 255, 0, 0, 255}, { 10, -10, -10, 0, 0, 0, 0, 255, 0, 255}, { 10, 10, -10, 0, 0, 0, 0, 0, 255, 255}, {-10, 10, -10, 0, 0, 0, 255, 255, 0, 255}, {-10, -10, 10, 0, 0, 0, 255, 0, 255, 255}, { 10, -10, 10, 0, 0, 0, 0, 255, 255, 255}, { 10, 10, 10, 0, 0, 0, 255, 255, 255, 255}, {-10, 10, 10, 0, 0, 0, 0, 0, 0, 255}, }; //RSP initialization display list static Gfx rspinit_dl[] = { gsSPViewport(&viewport), gsSPClearGeometryMode(G_SHADE | G_SHADING_SMOOTH | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR | G_LOD), gsSPTexture(0, 0, 0, 0, G_OFF), gsSPEndDisplayList(), }; //RDP initialization display list static Gfx rdpinit_dl[] = { gsDPSetCycleType(G_CYC_1CYCLE), gsDPPipelineMode(G_PM_1PRIMITIVE), gsDPSetScissor(G_SC_NON_INTERLACE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), gsDPSetCombineMode(G_CC_PRIMITIVE, G_CC_PRIMITIVE), gsDPSetCombineKey(G_CK_NONE), gsDPSetAlphaCompare(G_AC_NONE), gsDPSetRenderMode(G_RM_NOOP, G_RM_NOOP2), gsDPSetColorDither(G_CD_DISABLE), gsDPSetAlphaDither(G_AD_DISABLE), gsDPSetTextureFilter(G_TF_POINT), gsDPSetTextureConvert(G_TC_FILT), gsDPSetTexturePersp(G_TP_NONE), gsDPPipeSync(), gsSPEndDisplayList(), }; void ClearBackground(u8 r, u8 g, u8 b) { gDPSetCycleType(glistp++, G_CYC_FILL); gDPSetColorImage(glistp++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, nuGfxCfb_ptr); gDPSetFillColor(glistp++, (GPACK_RGBA5551(r, g, b, 1) << 16 | GPACK_RGBA5551(r, g, b, 1))); gDPFillRectangle(glistp++, 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1); } void RenderCube(float xPos, float yPos, float zPos) { Mtx modelViewMat; float mat[4][4]; float temp[4][4]; gDPSetCycleType(glistp++, G_CYC_1CYCLE); gSPSetGeometryMode(glistp++, G_SHADE | G_SHADING_SMOOTH | G_CULL_BACK); gDPSetCombineMode(glistp++, G_CC_SHADE, G_CC_SHADE); gDPSetRenderMode(glistp++, G_RM_AA_OPA_SURF, G_RM_AA_OPA_SURF2); guTranslateF(mat, xPos, yPos, zPos); guMtxCatF(viewMatF, mat, temp); guMtxF2L(temp, &modelViewMat); osWritebackDCache(&modelViewMat, sizeof(modelViewMat)); //Write back to RAM from CPU cache so RSP has latest data. gSPMatrix(glistp++, &modelViewMat, G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH); gSPVertex(glistp++, cubeVerts, 8, 0); gSP2Triangles(glistp++, 4, 6, 7, 0, 4, 5, 6, 0); gSP2Triangles(glistp++, 6, 5, 2, 1, 2, 5, 1, 1); gSP2Triangles(glistp++, 1, 3, 2, 0, 0, 3, 1, 2); gSP2Triangles(glistp++, 3, 0, 7, 1, 0, 4, 7, 0); gSP2Triangles(glistp++, 2, 7, 6, 1, 2, 3, 7, 2); gSP2Triangles(glistp++, 0, 5, 4, 1, 0, 1, 5, 2); } void Render(void) { Mtx projectionMat; u16 perspNorm; //Start the display list. glistp = glist; gDPPipeSync(glistp++); gSPSegment(glistp++, 0, 0); gSPDisplayList(glistp++, rspinit_dl); gSPDisplayList(glistp++, rdpinit_dl); //Projection matrix. guPerspective(&projectionMat, &perspNorm, 45.f, (float)SCREEN_WIDTH / (float)SCREEN_HEIGHT, 10.f, 150.f, 1.f); gSPMatrix(glistp++, &projectionMat, G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH); gSPPerspNormalize(glistp++, &perspNorm); //View matrix. guLookAtF(viewMatF, 0.f, 0.f, 120.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f); ClearBackground(20, 20, 70); RenderCube(20, 0, 0); RenderCube(-20, 0, 0); gDPFullSync(glistp++); gSPEndDisplayList(glistp++); //Start the task. nuGfxTaskStart(glist, (s32)(glistp - glist) * sizeof(Gfx), NU_GFX_UCODE_F3DEX, NU_SC_SWAPBUFFER); }
Editor is loading...
Leave a Comment