void GuiCross::Draw() { GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); f32 x1 = GetLeft(); f32 x2 = x1 + width; f32 y1 = GetTop(); f32 y2 = y1 + height; int alpha = GetAlpha(); GX_Begin(GX_LINES, GX_VTXFMT0, 4); GX_Position3f32(x1, y1, 0.0f); GX_Color4u8(color.r, color.g, color.b, alpha); GX_Position3f32(x2, y2, 0.0f); GX_Color4u8(color.r, color.g, color.b, alpha); GX_Position3f32(x2, y1, 0.0f); GX_Color4u8(color.r, color.g, color.b, alpha); GX_Position3f32(x1, y2, 0.0f); GX_Color4u8(color.r, color.g, color.b, alpha); GX_End(); GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); }
static void render_texture (greets_data *gdata, float zpos, float scroll) { world_info *world = gdata->world; Mtx mvtmp; extern Mtx tube_rotmtx; guMtxIdentity (mvtmp); guMtxConcat (mvtmp, tube_rotmtx, mvtmp); object_set_matrices (&world->scene, &gdata->greets_loc, world->scene.camera, mvtmp, NULL, world->projection, world->projection_type); GX_ClearVtxDesc (); GX_SetVtxDesc (GX_VA_POS, GX_DIRECT); GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT); 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_SetCullMode (GX_CULL_NONE); scroll = scroll * 8.0f; scroll = scroll - floorf (scroll); scroll = scroll * 1./8; GX_Begin (GX_TRIANGLESTRIP, GX_VTXFMT0, 4); GX_Position3f32 (-40, 8, 0); GX_TexCoord2f32 (scroll, 0); GX_Position3f32 (40, 8, 0); GX_TexCoord2f32 (4 + scroll, 0); GX_Position3f32 (-40, -8, 0); GX_TexCoord2f32 (scroll, 0.5); GX_Position3f32 (40, -8, 0); GX_TexCoord2f32 (4 + scroll, 0.5); GX_End (); GX_Begin (GX_TRIANGLESTRIP, GX_VTXFMT0, 4); GX_Position3f32 (-40, 0, 8); GX_TexCoord2f32 (scroll, 0); GX_Position3f32 (40, 0, 8); GX_TexCoord2f32 (4 + scroll, 0); GX_Position3f32 (-40, 0, -8); GX_TexCoord2f32 (scroll, 0.5); GX_Position3f32 (40, 0, -8); GX_TexCoord2f32 (4 + scroll, 0.5); GX_End (); }
/**************************************************************************** * Menu_DrawImg * * Draws the specified image on screen using GX ***************************************************************************/ void Menu_DrawImg(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[], f32 degrees, f32 scaleX, f32 scaleY, u8 alpha) { if(data == NULL) return; GXTexObj texObj; GX_InitTexObj(&texObj, data, width, height, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_LoadTexObj(&texObj, GX_TEXMAP0); GX_InvalidateTexAll(); GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE); GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT); Mtx m,m1,m2, mv; width >>= 1; height >>= 1; guMtxIdentity (m1); guMtxScaleApply(m1,m1,scaleX,scaleY,1.0); guVector axis = (guVector) {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(0xFF,0xFF,0xFF,alpha); GX_TexCoord2f32(0, 0); GX_Position3f32(width, -height, 0); GX_Color4u8(0xFF,0xFF,0xFF,alpha); GX_TexCoord2f32(1, 0); GX_Position3f32(width, height, 0); GX_Color4u8(0xFF,0xFF,0xFF,alpha); GX_TexCoord2f32(1, 1); GX_Position3f32(-width, height, 0); GX_Color4u8(0xFF,0xFF,0xFF,alpha); GX_TexCoord2f32(0, 1); GX_End(); GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0); GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR); GX_SetVtxDesc (GX_VA_TEX0, GX_NONE); }
/**************************************************************************** * Menu_DrawImg * * Draws the specified image on screen using GX ***************************************************************************/ void Menu_DrawImg(f32 xpos, f32 ypos, f32 zpos, f32 width, f32 height, u8 data[], f32 degrees, f32 scaleX, f32 scaleY, u8 alpha, int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4) { if (data == NULL) return; GX_LoadProjectionMtx(FSProjection2D, GX_ORTHOGRAPHIC); GXTexObj texObj; GX_InitTexObj(&texObj, data, width, height, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_LoadTexObj(&texObj, GX_TEXMAP0); GX_ClearVtxDesc(); GX_InvVtxCache(); GX_InvalidateTexAll(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); Mtx m, m1, m2, mv; width *= 0.5f; height *= 0.5f; guMtxIdentity(m1); guMtxScaleApply(m1, m1, scaleX, scaleY, 1.0f); guVector axis = (guVector) {0 , 0, 1}; guMtxRotAxisDeg (m2, &axis, degrees); guMtxConcat(m1, m2, m); guMtxTransApply(m, m, xpos + width + 0.5f, ypos + height + 0.5f, zpos); guMtxConcat(FSModelView2D, m, mv); GX_LoadPosMtxImm(mv, GX_PNMTX0); GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position3f32(-width + XX1, -height + YY1, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); GX_TexCoord2f32(0, 0); GX_Position3f32(width + XX2, -height + YY2, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); GX_TexCoord2f32(1, 0); GX_Position3f32(width + XX3, height + YY3, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); GX_TexCoord2f32(1, 1); GX_Position3f32(-width + XX4, height + YY4, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); GX_TexCoord2f32(0, 1); GX_End(); }
void drawInit() { Mtx44 GXprojection2D; Mtx GXmodelView2D; // Reset various parameters from gfx plugin GX_SetCoPlanar(GX_DISABLE); GX_SetClipMode(GX_CLIP_ENABLE); // GX_SetScissor(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetAlphaCompare(GX_ALWAYS,0,GX_AOP_AND,GX_ALWAYS,0); guMtxIdentity(GXmodelView2D); GX_LoadTexMtxImm(GXmodelView2D,GX_TEXMTX0,GX_MTX2x4); GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0); guOrtho(GXprojection2D, 0, 479, 0, 639, 0, 700); GX_LoadProjectionMtx(GXprojection2D, GX_ORTHOGRAPHIC); // GX_SetViewport (0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1); GX_SetZMode(GX_DISABLE,GX_ALWAYS,GX_TRUE); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_PTNMTXIDX, GX_PNMTX0); GX_SetVtxDesc(GX_VA_TEX0MTXIDX, GX_TEXMTX0); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); //set vertex attribute formats here 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_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); //enable textures GX_SetNumChans (1); GX_SetNumTexGens (1); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_SetNumTevStages (1); GX_SetTevOrder (GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR); //set blend mode GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); //Fix src alpha GX_SetColorUpdate(GX_ENABLE); // GX_SetAlphaUpdate(GX_ENABLE); // GX_SetDstAlpha(GX_DISABLE, 0xFF); //set cull mode GX_SetCullMode (GX_CULL_NONE); }
void QuadPane::Draw(const BannerResources& resources, u8 render_alpha, const float ws_scale, Mtx &modelview, u16 material_index, u8 texture_flip) const { if(!header) return; if (material_index < resources.materials.size()) { bool modulate_color = IsModulateColor(header->vertex_colors, render_alpha); resources.materials[material_index]->Apply(resources, render_alpha, modulate_color); } Mtx m, mv; guMtxIdentity (m); guMtxTransApply(m,m, -0.5f * GetOriginX(), -0.5f * GetOriginY(), 0.f); guMtxScaleApply(m,m, GetWidth(), GetHeight(), 1.f); guMtxConcat (modelview, m, mv); GX_LoadPosMtxImm (mv, GX_PNMTX0); GX_ClearVtxDesc(); GX_InvVtxCache(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); for(u32 i = 0; i < header->tex_coord_count; i++) GX_SetVtxDesc(GX_VA_TEX0+i, GX_DIRECT); GX_Begin(GX_QUADS, GX_VTXFMT0, 4); if(texture_flip) { SetVertex(0, 0.f, 0.f, render_alpha); SetVertex(1, 1.f, 0.f, render_alpha); SetVertex(3, 1.f, 1.f, render_alpha); SetVertex(2, 0.f, 1.f, render_alpha); } else { SetVertex(2, 0.f, 0.f, render_alpha); SetVertex(3, 1.f, 0.f, render_alpha); SetVertex(1, 1.f, 1.f, render_alpha); SetVertex(0, 0.f, 1.f, render_alpha); } GX_End(); }
/** * Sets the TEV operation and VTX descriptor values after texture rendering it complete. * * This function calls the GX_SetTevOp and GX_SetVtxDesc functions with the compatibility parameters specified * in setCompatibilityMode. */ void FreeTypeGX::setDefaultMode() { if(this->compatibilityMode) { switch(this->compatibilityMode & 0x00FF) { case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_MODULATE: GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); break; case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_DECAL: GX_SetTevOp(GX_TEVSTAGE0, GX_DECAL); break; case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_BLEND: GX_SetTevOp(GX_TEVSTAGE0, GX_BLEND); break; case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_REPLACE: GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE); break; case FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR: GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); break; default: break; } switch(this->compatibilityMode & 0xFF00) { case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE: GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); break; case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_DIRECT: GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); break; case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX8: GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX8); break; case FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_INDEX16: GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16); break; default: break; } } }
/**************************************************************************** * Menu_DrawRectangle * * Draws a rectangle at the specified coordinates using GX ***************************************************************************/ void Menu_DrawRectangle(f32 x, f32 y, f32 width, f32 height, GXColor color, u8 filled) { GX_LoadProjectionMtx(FSProjection2D, GX_ORTHOGRAPHIC); GX_LoadPosMtxImm(FSModelView2D, GX_PNMTX0); GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); GX_ClearVtxDesc(); GX_InvVtxCache(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); u8 fmt; long n; int i; f32 x2 = x + width; f32 y2 = y + height; guVector v[] = { { x, y, 0.0f }, { x2, y, 0.0f }, { x2, y2, 0.0f }, { x, y2, 0.0f }, { x, y, 0.0f } }; if (!filled) { fmt = GX_LINESTRIP; n = 5; } else { fmt = GX_TRIANGLEFAN; n = 4; } GX_Begin(fmt, GX_VTXFMT0, n); for (i = 0; i < n; i++) { GX_Position3f32(v[i].x, v[i].y, v[i].z); GX_Color4u8(color.r, color.g, color.b, color.a); } GX_End(); GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); }
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(); }
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 (); } }
void draw_sun( f32 x, f32 y, f32 r, f32 ang, u8 *col ) { int i; Mtx m, mv; circle( x, y, r, col, 1, 100, 0.0f ); guMtxIdentity( m ); guMtxRotAxisRad( m, &rotax, ang ); guMtxTransApply( m, m, x, y, 0 ); guMtxConcat( GXmodelView2D, m, mv ); GX_LoadPosMtxImm( mv, GX_PNMTX0 ); GX_Begin( GX_QUADS, GX_VTXFMT0, NUMRAYS*4 ); for( i=0; i<NUMRAYS; i++ ) { GX_Position3f32( sunrays[i*4 ].x , sunrays[i*4 ].y , 0.0f ); GX_Color4u8( col[0], col[1], col[2], 0xff ); GX_Position3f32( sunrays[i*4+1].x , sunrays[i*4+1].y , 0.0f ); GX_Color4u8( col[0], col[1], col[2], 0xff ); GX_Position3f32( sunrays[i*4+2].x*0.9f, sunrays[i*4+2].y*0.9f, 0.0f ); GX_Color4u8( col[0], col[1], col[2], 0xff ); GX_Position3f32( sunrays[i*4+3].x*0.9f, sunrays[i*4+3].y*0.9f, 0.0f ); GX_Color4u8( col[0], col[1], col[2], 0xff ); } GX_End(); for( i=0; i<NUMRAYS; i++ ) { GX_Begin( GX_LINESTRIP, GX_VTXFMT0, 4 ); GX_Position3f32( sunrays[i*4+3].x, sunrays[i*4+3].y, 0.0f ); GX_Color4u8( 0, 0, 0, 0xff ); GX_Position3f32( sunrays[i*4 ].x, sunrays[i*4 ].y, 0.0f ); GX_Color4u8( 0, 0, 0, 0xff ); GX_Position3f32( sunrays[i*4+1].x, sunrays[i*4+1].y, 0.0f ); GX_Color4u8( 0, 0, 0, 0xff ); GX_Position3f32( sunrays[i*4+2].x, sunrays[i*4+2].y, 0.0f ); GX_Color4u8( 0, 0, 0, 0xff ); GX_End(); } GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0); GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR); GX_SetVtxDesc (GX_VA_TEX0, GX_NONE); }
void draw_star( f32 scale, f32 angle, f32 x, f32 y, u8 *col, u8 alpha ) { int i, j; Mtx m,m1,m2,mv; guMtxIdentity(m1); guMtxScaleApply( m1, m1, scale, scale, 1.0f ); guMtxRotAxisRad( m2, &rotax, angle ); guMtxConcat( m2, m1, m); guMtxTransApply( m, m, x, y, 0 ); guMtxConcat( GXmodelView2D, m, mv ); GX_LoadPosMtxImm( mv, GX_PNMTX0 ); GX_Begin( GX_TRIANGLES, GX_VTXFMT0, 3*NUM_STAR_POLYS ); for( i=0; i<NUM_STAR_POLYS*3; i++ ) { j = star_polys[i]*2; GX_Position3f32( star_pts[j], star_pts[j+1], 0.0f ); GX_Color4u8( col[0], col[1], col[2], alpha ); } GX_End(); GX_Begin( GX_LINESTRIP, GX_VTXFMT0, NUM_STAR_EDGES ); for( i=0; i<NUM_STAR_EDGES; i++ ) { j = star_edges[i]*2; GX_Position3f32( star_pts[j], star_pts[j+1], 0.0f ); GX_Color4u8( 0, 0, 0, alpha ); } GX_End(); GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0); GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR); GX_SetVtxDesc (GX_VA_TEX0, GX_NONE); }
//--------------------------------------------------------------------------------- int main( int argc, char **argv ){ //--------------------------------------------------------------------------------- u32 fb; // initial framebuffer index u32 first_frame; f32 yscale; u32 xfbHeight; Mtx44 perspective; Mtx GXmodelView2D; void *gp_fifo = NULL; GXColor background = {0, 0, 0, 0xff}; int i; VIDEO_Init(); rmode = VIDEO_GetPreferredMode(NULL); fb = 0; first_frame = 1; // allocate 2 framebuffers for double buffering frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); fb ^= 1; // setup the fifo and then init the flipper gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gp_fifo,0,DEFAULT_FIFO_SIZE); GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer GX_SetCopyClear(background, 0x00ffffff); // other gx setup GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (rmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetCullMode(GX_CULL_NONE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); // setup the vertex descriptor // tells the flipper to expect direct data GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetNumChans(1); GX_SetNumTexGens(1); GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_InvalidateTexAll(); TPLFile spriteTPL; TPL_OpenTPLFromMemory(&spriteTPL, (void *)textures_tpl,textures_tpl_size); TPL_GetTexture(&spriteTPL,ballsprites,&texObj); GX_LoadTexObj(&texObj, GX_TEXMAP0); guOrtho(perspective,0,479,0,639,0,300); GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC); PAD_Init(); srand(time(NULL)); for(i = 0; i < NUM_SPRITES; i++) { //random place and speed sprites[i].x = (rand() % (640 - 32 )) << 8; sprites[i].y = (rand() % (480 - 32 )) << 8 ; sprites[i].dx = (rand() & 0xFF) + 0x100; sprites[i].dy = (rand() & 0xFF) + 0x100; sprites[i].image = rand() & 3; if(rand() & 1) sprites[i].dx = -sprites[i].dx; if(rand() & 1) sprites[i].dy = -sprites[i].dy; } GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); guMtxIdentity(GXmodelView2D); guMtxTransApply (GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -5.0F); GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetAlphaUpdate(GX_TRUE); GX_SetColorUpdate(GX_TRUE); while(1) { PAD_ScanPads(); if (PAD_ButtonsDown(0) & PAD_BUTTON_START) exit(0); GX_InvVtxCache(); GX_InvalidateTexAll(); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); for(i = 0; i < NUM_SPRITES; i++) { sprites[i].x += sprites[i].dx; sprites[i].y += sprites[i].dy; //check for collision with the screen boundaries if(sprites[i].x < (1<<8) || sprites[i].x > ((640-32) << 8)) sprites[i].dx = -sprites[i].dx; if(sprites[i].y < (1<<8) || sprites[i].y > ((480-32) << 8)) sprites[i].dy = -sprites[i].dy; drawSpriteTex( sprites[i].x >> 8, sprites[i].y >> 8, 32, 32, sprites[i].image); } GX_DrawDone(); GX_CopyDisp(frameBuffer[fb],GX_TRUE); VIDEO_SetNextFramebuffer(frameBuffer[fb]); if(first_frame) { VIDEO_SetBlack(FALSE); first_frame = 0; } VIDEO_Flush(); VIDEO_WaitVSync(); fb ^= 1; // flip framebuffer } return 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; }
void GuiFrameImage::CreateDrawList() { GX_BeginDispList(DrawList, DrawListSize+64); GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR); GX_SetVtxDesc (GX_VA_TEX0, GX_NONE); oldWidth = GetWidth(); oldHeight = GetHeight(); oldX = GetLeft(); oldY = GetTop(); oldZ = 0; oldAlpha = GetAlpha(); f32 alpha = oldAlpha; f32 z = oldZ; f32 x1 = oldX; f32 y1 = oldY; f32 x2 = x1+oldWidth; f32 y2 = y1+oldHeight; //! Upper QUAD GX_Begin(GX_QUADS, GX_VTXFMT0,4); GX_Position3f32(x1+Margin, y1, z); GX_Color4u8(UpperQuadUpper.r,UpperQuadUpper.g,UpperQuadUpper.b,alpha); GX_Position3f32(x2-Margin, y1, z); GX_Color4u8(UpperQuadUpper.r,UpperQuadUpper.g,UpperQuadUpper.b,alpha); GX_Position3f32(x2-Margin, y1+Margin, z); GX_Color4u8(MainQuadUpper.r,MainQuadUpper.g,MainQuadUpper.b,alpha); GX_Position3f32(x1+Margin, y1+Margin, z); GX_Color4u8(MainQuadUpper.r,MainQuadUpper.g,MainQuadUpper.b,alpha); GX_End(); //! Upper/Left Corner Circle GX_Begin(GX_TRIANGLEFAN, GX_VTXFMT0, Precision+1); { f32 deg; int r = SideQuadUpper.r; int g = SideQuadUpper.g; int b = SideQuadUpper.b; f32 r_p = (float) (UpperQuadUpper.r - r)/(float) (Precision-1); f32 g_p = (float) (UpperQuadUpper.g - g)/(float) (Precision-1); f32 b_p = (float) (UpperQuadUpper.b - b)/(float) (Precision-1); GX_Position3f32(x1+Margin, y1+Margin, z); GX_Color4u8(MainQuadUpper.r,MainQuadUpper.g,MainQuadUpper.b,alpha); for(int i = 0; i < Precision; ++i) { deg = DegToRad(180+i*90/(f32)(Precision-1)); GX_Position3f32(x1+Margin+Margin*cos(deg), y1+Margin+Margin*sin(deg), z); GX_Color4u8(r+r_p*i, g+g_p*i, b+b_p*i,alpha); } } GX_End(); //! Left QUAD GX_Begin(GX_QUADS, GX_VTXFMT0,4); GX_Position3f32(x1, y1+Margin, z); GX_Color4u8(SideQuadUpper.r,SideQuadUpper.g,SideQuadUpper.b,alpha); GX_Position3f32(x1+Margin, y1+Margin, z); GX_Color4u8(MainQuadUpper.r,MainQuadUpper.g,MainQuadUpper.b,alpha); GX_Position3f32(x1+Margin, y2-Margin, z); GX_Color4u8(MainQuadLower.r,MainQuadLower.g,MainQuadLower.b,alpha); GX_Position3f32(x1, y2-Margin, z); GX_Color4u8(SideQuadLower.r,SideQuadLower.g,SideQuadLower.b,alpha); GX_End(); //! Lower Left Corner Circle GX_Begin(GX_TRIANGLEFAN, GX_VTXFMT0, Precision*2+2); { //! Transparent shadow f32 deg; int r = ShadowLower.r; int g = ShadowLower.g; int b = ShadowLower.b; f32 a = 0.1f*alpha; f32 r_p = (float) (SideQuadLower.r - r)/(float) (Precision-1); f32 g_p = (float) (SideQuadLower.g - g)/(float) (Precision-1); f32 b_p = (float) (SideQuadLower.b - b)/(float) (Precision-1); f32 a_p = (float) (alpha - a)/(float) (Precision-1); GX_Position3f32(x1+Margin, y2-Margin, z); GX_Color4u8(MainQuadLower.r,MainQuadLower.g,MainQuadLower.b,alpha); for(int i = 0; i < Precision; ++i) { deg = DegToRad(90+i*90/(f32)(Precision-1)); GX_Position3f32(x1+Margin+Margin*cos(deg), y2-Margin+Margin*sin(deg), z); GX_Color4u8(r+r_p*i, g+g_p*i, b+b_p*i, a+a_p*i); } //! Opaque r = ShadowUpper.r; g = ShadowUpper.g; b = ShadowUpper.b; r_p = (float) (SideQuadLower.r - r)/(float) (Precision-1); g_p = (float) (SideQuadLower.g - g)/(float) (Precision-1); b_p = (float) (SideQuadLower.b - b)/(float) (Precision-1); GX_Position3f32(x1+Margin, y2-Margin, z); GX_Color4u8(MainQuadLower.r,MainQuadLower.g,MainQuadLower.b,alpha); for(int i = 0; i < Precision; ++i) { deg = DegToRad(90+i*90/(f32)(Precision-1)); GX_Position3f32(x1+Margin+Margin*cos(deg), y2-Margin+(Margin-ShadowWidth)*sin(deg), z); GX_Color4u8(r+r_p*i, g+g_p*i, b+b_p*i, alpha); } } GX_End(); //! Lower QUAD GX_Begin(GX_QUADS, GX_VTXFMT0,8); //! Transparent shadow quad GX_Position3f32(x1+Margin, y2-Margin, z); GX_Color4u8(ShadowUpper.r,ShadowUpper.g,ShadowUpper.b,alpha); GX_Position3f32(x2-Margin, y2-Margin, z); GX_Color4u8(ShadowUpper.r,ShadowUpper.g,ShadowUpper.b,alpha); GX_Position3f32(x2-Margin, y2, z); GX_Color4u8(ShadowLower.r,ShadowLower.g,ShadowLower.b,0.1f*alpha); GX_Position3f32(x1+Margin, y2, z); GX_Color4u8(ShadowLower.r,ShadowLower.g,ShadowLower.b,0.1f*alpha); //! Opaque quad GX_Position3f32(x1+Margin, y2-Margin, z); GX_Color4u8(MainQuadLower.r,MainQuadLower.g,MainQuadLower.b,alpha); GX_Position3f32(x2-Margin, y2-Margin, z); GX_Color4u8(MainQuadLower.r,MainQuadLower.g,MainQuadLower.b,alpha); GX_Position3f32(x2-Margin, y2-ShadowWidth, z); GX_Color4u8(ShadowUpper.r,ShadowUpper.g,ShadowUpper.b,alpha); GX_Position3f32(x1+Margin, y2-ShadowWidth, z); GX_Color4u8(ShadowUpper.r,ShadowUpper.g,ShadowUpper.b,alpha); GX_End(); //! Lower Right Corner Circle GX_Begin(GX_TRIANGLEFAN, GX_VTXFMT0, Precision*2+2); { f32 deg; int r = SideQuadLower.r; int g = SideQuadLower.g; int b = SideQuadLower.b; f32 a = alpha; f32 r_p = (float) (ShadowLower.r - r)/(float) (Precision-1); f32 g_p = (float) (ShadowLower.g - g)/(float) (Precision-1); f32 b_p = (float) (ShadowLower.b - b)/(float) (Precision-1); f32 a_p = (float) (0.1f*alpha - a)/(float) (Precision-1); GX_Position3f32(x2-Margin, y2-Margin, z); GX_Color4u8(MainQuadLower.r,MainQuadLower.g,MainQuadLower.b,alpha); for(int i = 0; i < Precision; ++i) { deg = DegToRad(i*90/(f32)(Precision-1)); GX_Position3f32(x2-Margin+Margin*cos(deg), y2-Margin+Margin*sin(deg), z); GX_Color4u8(r+r_p*i, g+g_p*i, b+b_p*i, a+a_p*i); } r_p = (float) (ShadowUpper.r - r)/(float) (Precision-1); g_p = (float) (ShadowUpper.g - g)/(float) (Precision-1); b_p = (float) (ShadowUpper.b - b)/(float) (Precision-1); GX_Position3f32(x2-Margin, y2-Margin, z); GX_Color4u8(MainQuadLower.r,MainQuadLower.g,MainQuadLower.b,alpha); for(int i = 0; i < Precision; ++i) { deg = DegToRad(i*90/(f32)(Precision-1)); GX_Position3f32(x2-Margin+Margin*cos(deg), y2-Margin+(Margin-ShadowWidth)*sin(deg), z); GX_Color4u8(r+r_p*i, g+g_p*i, b+b_p*i, alpha); } } GX_End(); //! Right QUAD GX_Begin(GX_QUADS, GX_VTXFMT0,4); GX_Position3f32(x2-Margin, y1+Margin, z); GX_Color4u8(MainQuadUpper.r,MainQuadUpper.g,MainQuadUpper.b,alpha); GX_Position3f32(x2, y1+Margin, z); GX_Color4u8(SideQuadUpper.r,SideQuadUpper.g,SideQuadUpper.b,alpha); GX_Position3f32(x2, y2-Margin, z); GX_Color4u8(SideQuadLower.r,SideQuadLower.g,SideQuadLower.b,alpha); GX_Position3f32(x2-Margin, y2-Margin, z); GX_Color4u8(MainQuadLower.r,MainQuadLower.g,MainQuadLower.b,alpha); GX_End(); //! Upper/Left Corner Circle GX_Begin(GX_TRIANGLEFAN, GX_VTXFMT0, Precision+1); { f32 deg; int r = UpperQuadUpper.r; int g = UpperQuadUpper.g; int b = UpperQuadUpper.b; f32 r_p = (float) (SideQuadUpper.r - r)/(float) (Precision-1); f32 g_p = (float) (SideQuadUpper.g - g)/(float) (Precision-1); f32 b_p = (float) (SideQuadUpper.b - b)/(float) (Precision-1); GX_Position3f32(x2-Margin, y1+Margin, z); GX_Color4u8(MainQuadUpper.r,MainQuadUpper.g,MainQuadUpper.b,alpha); for(int i = 0; i < Precision; ++i) { deg = DegToRad(270+i*90/(f32)(Precision-1)); GX_Position3f32(x2-Margin+Margin*cos(deg), y1+Margin+Margin*sin(deg), z); GX_Color4u8(r+r_p*i, g+g_p*i, b+b_p*i,alpha); } } GX_End(); //! Main QUAD GX_Begin(GX_QUADS, GX_VTXFMT0,4); GX_Position3f32(x1+Margin, y1+Margin, z); GX_Color4u8(MainQuadUpper.r,MainQuadUpper.g,MainQuadUpper.b,alpha); GX_Position3f32(x2-Margin, y1+Margin, z); GX_Color4u8(MainQuadUpper.r,MainQuadUpper.g,MainQuadUpper.b,alpha); GX_Position3f32(x2-Margin, y2-Margin, z); GX_Color4u8(MainQuadLower.r,MainQuadLower.g,MainQuadLower.b,alpha); GX_Position3f32(x1+Margin, y2-Margin, z); GX_Color4u8(MainQuadLower.r,MainQuadLower.g,MainQuadLower.b,alpha); GX_End(); GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE); DrawListSize = GX_EndDispList(); }
void Textbox::SetupGX(const BannerResources& resources) const { GX_ClearVtxDesc(); GX_InvVtxCache(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); // channel control GX_SetNumChans(1); GX_SetChanCtrl(GX_COLOR0A0,GX_DISABLE,GX_SRC_REG,GX_SRC_VTX,GX_LIGHTNULL,GX_DF_NONE,GX_AF_NONE); // texture gen. GX_SetNumTexGens(1); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); // texture environment GX_SetNumTevStages(1); GX_SetNumIndStages(0); GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP0); GX_SetTevKColorSel(GX_TEVSTAGE0, GX_TEV_KCSEL_1_4); GX_SetTevKAlphaSel(GX_TEVSTAGE0, GX_TEV_KASEL_1); GX_SetTevDirect(GX_TEVSTAGE0); // swap table GX_SetTevSwapModeTable(GX_TEV_SWAP0, GX_CH_RED, GX_CH_GREEN, GX_CH_BLUE, GX_CH_ALPHA); GX_SetTevSwapModeTable(GX_TEV_SWAP1, GX_CH_RED, GX_CH_RED, GX_CH_RED, GX_CH_ALPHA); GX_SetTevSwapModeTable(GX_TEV_SWAP2, GX_CH_GREEN, GX_CH_GREEN, GX_CH_GREEN, GX_CH_ALPHA); GX_SetTevSwapModeTable(GX_TEV_SWAP3, GX_CH_BLUE, GX_CH_BLUE, GX_CH_BLUE, GX_CH_ALPHA); // alpha compare and blend mode GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET); if(header->material_index < resources.materials.size()) { const Material::Header *matHead = resources.materials[header->material_index]->GetHeader(); if(!matHead) return; //GX_SetFog(0, 0.0f, 0.0f, 0.0f, 0.0f, (GXColor){0xff, 0xff, 0xff, 0xff}); GX_SetTevSwapModeTable(0, 0, 1, 2, 3); //GX_SetZTexture(0, 0x11, 0); GX_SetNumChans(1 ); GX_SetChanCtrl(4, 0, 0, 1, 0, 0, 2); GX_SetChanCtrl(5, 0, 0, 0, 0, 0, 2); GX_SetNumTexGens(1); GX_SetTexCoordGen2(0, 1, 4, 0x3c, 0, 0x7D); GX_SetNumIndStages(0); GX_SetBlendMode(1, 4, 5, 0xf); GX_SetNumTevStages(2); GX_SetTevDirect(0); GX_SetTevDirect(1); GX_SetTevSwapMode(0, 0, 0); GX_SetTevSwapMode(1, 0, 0); GX_SetTevOrder(0, 0, 0, 0xff); for( int i = 0; i < 2; i++ ) { // Devkitppc_r27 internal compiler error //GX_SetTevColor(i + 1, (GXColor){ LIMIT(matHead->color_regs[i].r, 0, 0xFF), // LIMIT(matHead->color_regs[i].g, 0, 0xFF), // LIMIT(matHead->color_regs[i].b, 0, 0xFF), // LIMIT(matHead->color_regs[i].a, 0, 0xFF) }); u8 r = (u8) LIMIT(matHead->color_regs[i].r, 0, 0xFF); u8 g = (u8) LIMIT(matHead->color_regs[i].g, 0, 0xFF); u8 b = (u8) LIMIT(matHead->color_regs[i].b, 0, 0xFF); u8 a = (u8) LIMIT(matHead->color_regs[i].a, 0, 0xFF); GX_SetTevColor((u8) (i + 1), (GXColor){r,g,b,a}); } GX_SetTevColorIn(0, 2, 4, 8, 0xf); GX_SetTevAlphaIn(0, 1, 2, 4, 7); GX_SetTevColorOp(0, 0, 0, 0, 1, 0); GX_SetTevAlphaOp(0, 0, 0, 0, 1, 0); GX_SetTevOrder(1, 0xff, 0xff, 4); GX_SetTevColorIn(1, 0xf, 0, 0xa, 0xf); GX_SetTevAlphaIn(1, 7, 0, 5, 7); GX_SetTevColorOp(1, 0, 0, 0, 1, 0); GX_SetTevAlphaOp(1, 0, 0, 0, 1, 0); } }
/* * GX render callback */ void wii_render_callback() { GX_SetVtxDesc( GX_VA_POS, GX_DIRECT ); GX_SetVtxDesc( GX_VA_CLR0, GX_DIRECT ); GX_SetVtxDesc( GX_VA_TEX0, GX_NONE ); Mtx m; // model matrix. Mtx mv; // modelview matrix. guMtxIdentity( m ); guMtxTransApply( m, m, 0, 0, -100 ); guMtxConcat( gx_view, m, mv ); GX_LoadPosMtxImm( mv, GX_PNMTX0 ); // Diff switches wii_atari_display_diff_switches(); // // Debug // static int dbg_count = 0; if( wii_debug && !wii_testframe ) { static char text[256] = ""; static char text2[256] = ""; dbg_count++; if( dbg_count % 60 == 0 ) { /* a: %d, %d, c: 0x%x,0x%x,0x%x*/ /* wii_sound_length, wii_convert_length, memory_ram[CTLSWB], riot_drb, memory_ram[SWCHB] */ sprintf( text, "v: %.2f, hs: %d, %d, timer: %d, wsync: %s, %d, stl: %s, mar: %d, cpu: %d, ext: %d, rnd: %d, hb: %d", wii_fps_counter, high_score_set, hs_sram_write_count, ( riot_timer_count % 1000 ), ( dbg_wsync ? "1" : "0" ), dbg_wsync_count, ( dbg_cycle_stealing ? "1" : "0" ), dbg_maria_cycles, dbg_p6502_cycles, dbg_saved_cycles, RANDOM, cartridge_hblank ); } //sprintf( text, "video: %.2f", wii_fps_counter ); wii_gx_drawtext( -310, 210, 14, text, ftgxWhite, 0 ); if( lightgun_enabled ) { //ir_t ir; //WPAD_IR(WPAD_CHAN_0, &ir); sprintf( text2, "lightgun: %d, %d, %d, %.2f, %d, [%d, %d]", /*"lightgun: %d, %d, %d, %.2f, %d, [%d, %d] %d, %d, %d, %d", */ cartridge_crosshair_x, cartridge_crosshair_y, lightgun_scanline, lightgun_cycle, wii_dbg_scanlines, wii_ir_x, wii_ir_y /*, ir.vres[0], ir.vres[1], ir.offset[0], ir.offset[1]*/ ); wii_gx_drawtext( -310, -210, 14, text2, ftgxWhite, 0 ); } } }
//--------------------------------------------------------------------------------- int main( int argc, char **argv ){ //--------------------------------------------------------------------------------- f32 yscale; u32 xfbHeight; // various matrices for things like view Mtx view,mv,mr; Mtx44 perspective; // the texure we're going to paint GXTexObj texture; TPLFile mudTPL; u32 fb = 0; // initial framebuffer index GXColor background = {0, 0, 0, 0xff}; // init the vi. VIDEO_Init(); rmode = VIDEO_GetPreferredMode(NULL); WPAD_Init(); // allocate 2 framebuffers for double buffering frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); // configure video and wait for the screen to blank VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); // setup the fifo... void *gp_fifo = NULL; gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gp_fifo,0,DEFAULT_FIFO_SIZE); // ...then init the flipper GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer GX_SetCopyClear(background, 0x00ffffff); // other gx setup GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (rmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetCullMode(GX_CULL_NONE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); // setup the vertex attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. GX_InvVtxCache(); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); 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); // setup texture coordinate generation // args: texcoord slot 0-7, matrix type, source to generate texture coordinates from, matrix to use GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_TEX0, GX_IDENTITY); f32 w = rmode->viWidth; f32 h = rmode->viHeight; guLightPerspective(mv,45, (f32)w/h, 1.05F, 1.0F, 0.0F, 0.0F); guMtxTrans(mr, 0.0F, 0.0F, -1.0F); guMtxConcat(mv, mr, mv); GX_LoadTexMtxImm(mv, GX_TEXMTX0, GX_MTX3x4); GX_InvalidateTexAll(); TPL_OpenTPLFromMemory(&mudTPL, (void *)mud_tpl,mud_tpl_size); TPL_GetTexture(&mudTPL,mud,&texture); // setup our camera at the origin // looking down the -z axis with y up guVector cam = {0.0F, 0.0F, 0.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, -1.0F}; guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); // get the room ready to render SetupWorld(); while(1) { WPAD_ScanPads(); s8 tpad = PAD_StickX(0); // Rotate left or right. if ((tpad < -8) || (tpad > 8)) yrot -= (float)tpad / 50.f; // NOTE: walkbiasangle = head bob tpad = PAD_StickY(0); // Go forward. if(tpad > 50) { xpos -= (float)sin(DegToRad(yrot)) * 0.05f; // Move on the x-plane based on player direction zpos -= (float)cos(DegToRad(yrot)) * 0.05f; // Move on the z-plane based on player direction if (walkbiasangle >= 359.0f) walkbiasangle = 0.0f; // Bring walkbiasangle back around else walkbiasangle += 10; // if walkbiasangle < 359 increase it by 10 walkbias = (float)sin(DegToRad(walkbiasangle))/20.0f; } // Go backward if(tpad < -50) { xpos += (float)sin(DegToRad(yrot)) * 0.05f; zpos += (float)cos(DegToRad(yrot)) * 0.05f; if (walkbiasangle <= 1.0f) walkbiasangle = 359.0f; else walkbiasangle -= 10; walkbias = (float)sin(DegToRad(walkbiasangle))/20.0f; } tpad = PAD_SubStickY(0); // Tilt up/down if (((tpad > 8) || (tpad < -8)) && ((90 >= lookupdown) && (lookupdown >= -90))) { zdepth -= ((f32)tpad * 0.01f); lookupdown -= ((f32)tpad * 0.01f); if (lookupdown > 90) lookupdown = 90.0F; if (lookupdown < -90) lookupdown = -90.0F; } if ( PAD_ButtonsDown(0) & PAD_BUTTON_START) { exit(0); } // do this before drawing GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); //set number of textures to generate GX_SetNumTexGens(1); // Draw things DrawScene(view,texture); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); // do this stuff after drawing GX_DrawDone(); fb ^= 1; // flip framebuffer VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); } return 0; }
static int drawgx_window_create(sdl_window_info *window, int width, int height) { sdl_info *sdl = window->dxdata; u32 xfbHeight; f32 yscale; Mtx44 perspective; Mtx GXmodelView2D; GXColor background = {0, 0, 0, 0xff}; currfb = 0; // allocate memory for our structures sdl = malloc(sizeof(*sdl)); memset(sdl, 0, sizeof(*sdl)); window->dxdata = sdl; sdl->scale_mode = &scale_modes[window->scale_mode]; sdl->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); sdl->extra_flags |= sdl->scale_mode->extra_flags; /*sdl->sdlsurf = SDL_SetVideoMode(width, height, 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags);*/ //sdl->sdlsurf = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF); //if (!sdl->sdlsurf) // return 1; window->width = gx_screenWidth();//sdl->sdlsurf->w; window->height = 480;//sdl->sdlsurf->h; sdl->safe_hofs = (window->width - window->width * options_get_float(mame_options(), SDLOPTVAL_SAFEAREA)) / 2; sdl->safe_vofs = (window->height - window->height * options_get_float(mame_options(), SDLOPTVAL_SAFEAREA)) / 2; /*if (sdl->scale_mode->is_yuv) yuv_overlay_init(window);*/ sdl->yuv_lookup = NULL; sdl->blittimer = 0; //if (is_inited) return 0; //is_inited = 1; //drawgx_yuv_init(sdl); //SDL_QuitSubSystem(SDL_INIT_VIDEO); if (is_inited) return 0; is_inited = 1; VIDEO_Init(); VIDEO_SetBlack(true); vmode = VIDEO_GetPreferredMode(NULL); switch (vmode->viTVMode >> 2) { case VI_PAL: vmode = &TVPal574IntDfScale; vmode->xfbHeight = 480; vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - 480)/2; vmode->viHeight = 480; break; case VI_NTSC: break; default: break; } VIDEO_Configure(vmode); xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode)); xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode)); VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK); VIDEO_SetNextFramebuffer(xfb[currfb]); VIDEO_Flush(); VIDEO_WaitVSync(); if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); else while (VIDEO_GetNextField()) VIDEO_WaitVSync(); gp_fifo = memalign(32, DEFAULT_FIFO_SIZE); memset(gp_fifo, 0, DEFAULT_FIFO_SIZE); GX_Init(gp_fifo, DEFAULT_FIFO_SIZE); atexit(drawgx_shutdown); GX_SetCopyClear(background, 0x00ffffff); // other gx setup GX_SetViewport(0,0,vmode->fbWidth,vmode->efbHeight,0,1); yscale = GX_GetYScaleFactor(vmode->efbHeight,vmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetDispCopySrc(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetDispCopyDst(vmode->fbWidth,xfbHeight); GX_SetCopyFilter(vmode->aa,vmode->sample_pattern,GX_TRUE,vmode->vfilter); GX_SetFieldMode(vmode->field_rendering,((vmode->viHeight==2*vmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (vmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetCullMode(GX_CULL_NONE); GX_CopyDisp(xfb[currfb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); GX_SetNumChans(1); GX_SetNumTexGens(1); GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetAlphaUpdate(GX_TRUE); GX_SetColorUpdate(GX_TRUE); guOrtho(perspective,0,479,0,gx_screenWidth()-1,0,300); GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC); guMtxIdentity(GXmodelView2D); guMtxTransApply (GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -5.0F); GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0); GX_SetViewport(0,0,vmode->fbWidth,vmode->efbHeight,0,1); GX_InvVtxCache(); GX_ClearVtxDesc(); GX_InvalidateTexAll(); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); VIDEO_SetBlack(false); GX_InitTexObj(&blankTex, blanktex, 1, 1, GX_TF_RGB5A3, GX_CLAMP, GX_CLAMP, GX_FALSE); return 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(); }
void Particle_Render(Mtx M_view, ParticleSystem* psystem, Camera* camera) { // setup TEV GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); // load model-view matrix Mtx M_modelView; guMtxIdentity(M_modelView); GX_LoadPosMtxImm(M_modelView, GX_PNMTX0); // setup tev GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetAlphaUpdate(GX_TRUE); GX_SetNumChans(1); GX_SetTevColorIn( GX_TEVSTAGE0, GX_CC_TEXC, // a GX_CC_RASC, // b GX_CC_TEXA, // c GX_CC_ZERO); // d GX_SetTevColorOp( GX_TEVSTAGE0, // stage GX_TEV_ADD, // op GX_TB_ZERO, // bias GX_CS_SCALE_2, // scale GX_ENABLE, // clamp 0-255 GX_TEVPREV); // output reg GX_SetTevAlphaIn( GX_TEVSTAGE0, GX_CA_ZERO, // a GX_CA_TEXA, // b GX_CA_RASA, // c GX_CA_ZERO); // d GX_SetTevAlphaOp( GX_TEVSTAGE0, // stage GX_TEV_ADD, // op GX_TB_ZERO, // bias GX_CS_SCALE_1, // scale GX_ENABLE, // clamp 0-255 GX_TEVPREV); // output reg GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetNumTexGens(1); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_LoadTexObj(&psystem->texture, GX_TEXMAP0); int n = psystem->n_particles; f32 texCoords[] = { 0, 0, 0, 1, 1, 1, 1, 0 }; GX_InvVtxCache(); Vec3 camPos = camera->position(); Mtx axisMtx; System::LogClear(); Particle_Sort(M_view, psystem); GX_Begin(GX_QUADS, GX_VTXFMT6, n*4); for (int k = 0; k < n; k++) { int i = psystem->binsAllocations[k].particleIdx; //System::Log(L"p%d", i); Vec3& p = psystem->positions[i]; f32 lifetime = psystem->lifetimes[i]; f32 age = psystem->ages[i]; f32 ratio = age/lifetime; Vec3 forward = Math3D::normalized(camPos - p); Vec3 worldUp = Vec3(0, 1, 0); Vec3 right = Math3D::normalized(Math3D::cross(worldUp, forward)); Vec3 up = Math3D::cross(forward, right); Mtx pm; guMtxCopy(M_view, pm); guMtxTranspose(pm, pm); pm[0][3] = p.x; pm[1][3] = p.y; pm[2][3] = p.z; guMtxConcat(M_view, pm, pm); f32 rotation = psystem->rotations[i]; if (psystem->rotationInterpolator) rotation = psystem->rotationInterpolator->getValue(rotation, ratio); f32 size = psystem->sizes[i]; if (psystem->sizeInterpolator) size = psystem->sizeInterpolator->getValue(size, ratio); if (psystem->colorInterpolator) psystem->colors[i] = psystem->colorInterpolator->getValue(ratio); Matrix34 M_rot = Math3D::matrixRotationZ(rotation); f32 hs = size*0.5f; Vec3 p0(-hs, +hs, 0); Vec3 p1(-hs, -hs, 0); Vec3 p2(+hs, -hs, 0); Vec3 p3(+hs, +hs, 0); Vec3 vs[4] = {p0, p1, p2, p3}; for (int i = 0; i < 4; i++) { vs[i] = M_rot * vs[i]; vs[i] = Math3D::matrixVecMul(pm, vs[i]); } for (int i = 0; i < 4; i++) { f32* coords = &texCoords[2*i]; SendVertex(vs[i], psystem->colors[i], coords[0], coords[1]); } } GX_End(); return; }
void WiiPointer::Draw(GuiTrigger *t) { if(t && pointerImg) { if(t->wpad.ir.valid) { lastActivity = 0; posX = t->wpad.ir.x; posY = t->wpad.ir.y; angle = t->wpad.ir.angle; } else { angle = 0.0f; // GC PAD // x-axis if(t->pad.stickX < -PADCAL) { posX += (t->pad.stickX + PADCAL) * Settings.PointerSpeed; lastActivity = 0; } else if(t->pad.stickX > PADCAL) { posX += (t->pad.stickX - PADCAL) * Settings.PointerSpeed; lastActivity = 0; } // y-axis if(t->pad.stickY < -PADCAL) { posY -= (t->pad.stickY + PADCAL) * Settings.PointerSpeed; lastActivity = 0; } else if(t->pad.stickY > PADCAL) { posY -= (t->pad.stickY - PADCAL) * Settings.PointerSpeed; lastActivity = 0; } //Wii u pro x-axis if(t->wupcdata.stickX < -WUPCCAL) { posX += (t->wupcdata.stickX + WUPCCAL) * Settings.PointerSpeed/8; lastActivity = 0; } else if(t->wupcdata.stickX > WUPCCAL) { posX += (t->wupcdata.stickX - WUPCCAL) * Settings.PointerSpeed/8; lastActivity = 0; } //Wii u pro y-axis if(t->wupcdata.stickY < -WUPCCAL) { posY -= (t->wupcdata.stickY + WUPCCAL) * Settings.PointerSpeed/8; lastActivity = 0; } else if(t->wupcdata.stickY > WUPCCAL) { posY -= (t->wupcdata.stickY - WUPCCAL) * Settings.PointerSpeed/8; lastActivity = 0; } int wpadX = t->WPAD_Stick(0, 0); int wpadY = t->WPAD_Stick(0, 1); // Wii Extensions // x-axis if(wpadX < -PADCAL) { posX += (wpadX + PADCAL) * Settings.PointerSpeed; lastActivity = 0; } else if(wpadX > PADCAL) { posX += (wpadX - PADCAL) * Settings.PointerSpeed; lastActivity = 0; } // y-axis if(wpadY < -PADCAL) { posY -= (wpadY + PADCAL) * Settings.PointerSpeed; lastActivity = 0; } else if(wpadY > PADCAL) { posY -= (wpadY - PADCAL) * Settings.PointerSpeed; lastActivity = 0; } if(t->pad.btns_h || t->wpad.btns_h || t->wupcdata.btns_h) lastActivity = 0; posX = LIMIT(posX, -50.0f, screenwidth+50.0f); posY = LIMIT(posY, -50.0f, screenheight+50.0f); if(lastActivity < 2) { // (3s on 60Hz and 3.6s on 50Hz) t->wpad.ir.valid = 1; t->wpad.ir.x = posX; t->wpad.ir.y = posY; } } if(t->wpad.ir.valid) { GXTexObj texObj; GX_InitTexObj(&texObj, pointerImg->GetImage(), pointerImg->GetWidth(), pointerImg->GetHeight(), GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_LoadTexObj(&texObj, GX_TEXMAP0); GX_ClearVtxDesc(); GX_InvVtxCache(); GX_InvalidateTexAll(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); Mtx mv; guMtxIdentity(mv); guMtxRotDeg (mv, 'z', angle); guMtxTransApply(mv, mv, posX, posY, 9900.f); guMtxConcat(FSModelView2D, mv, mv); GX_LoadProjectionMtx(projection, GX_ORTHOGRAPHIC); GX_LoadPosMtxImm(mv, GX_PNMTX0); // pointer is pointing to center of the texture f32 width = 0.5f * pointerImg->GetWidth(); f32 height = 0.5f * pointerImg->GetHeight(); GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position3f32(-width, -height, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, 0xFF); GX_TexCoord2f32(0, 0); GX_Position3f32(width, -height, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, 0xFF); GX_TexCoord2f32(1, 0); GX_Position3f32(width, height, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, 0xFF); GX_TexCoord2f32(1, 1); GX_Position3f32(-width, height, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, 0xFF); GX_TexCoord2f32(0, 1); GX_End(); } } ++lastActivity; }
int main(int argc,char **argv) { f32 yscale; u32 xfbHeight; u32 fb = 0; u32 first_frame = 1; GXTexObj texture; Mtx view; // view and perspective matrices Mtx44 perspective; void *gpfifo = NULL; GXColor background = {0x00, 0x00, 0x00, 0xFF}; guVector cam = {0.0F, 0.0F, 0.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, -1.0F}; TPLFile cubeTPL; VIDEO_Init(); PAD_Init(); rmode = VIDEO_GetPreferredMode(NULL); // allocate the fifo buffer gpfifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gpfifo,0,DEFAULT_FIFO_SIZE); // allocate 2 framebuffers for double buffering frameBuffer[0] = SYS_AllocateFramebuffer(rmode); frameBuffer[1] = SYS_AllocateFramebuffer(rmode); // configure video VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); fb ^= 1; // init the flipper GX_Init(gpfifo,DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer GX_SetCopyClear(background,0x00FFFFFF); // other gx setup GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (rmode->aa) { GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); } else { GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); } GX_SetCullMode(GX_CULL_NONE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); // setup the vertex attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); 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_CLR0, GX_CLR_RGB, GX_RGB8, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); // set number of rasterized color channels GX_SetNumChans(1); //set number of textures to generate GX_SetNumTexGens(1); GX_InvVtxCache(); GX_InvalidateTexAll(); TPL_OpenTPLFromMemory(&cubeTPL, (void *)Cube_tpl,Cube_tpl_size); TPL_GetTexture(&cubeTPL,cube,&texture); // setup our camera at the origin // looking down the -z axis with y up guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution f32 w = rmode->viWidth; f32 h = rmode->viHeight; guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); if (BuildLists(texture)) { // Build the display lists exit(1); // Exit if failed. } while(1) { PAD_ScanPads(); if ( PAD_ButtonsDown(0) & PAD_BUTTON_START) { exit(0); } u16 directions = PAD_ButtonsHeld(0); if ( directions & PAD_BUTTON_LEFT ) yrot += 0.5f; if ( directions & PAD_BUTTON_RIGHT ) yrot -= 0.5f; if ( yrot > 360.f ) yrot -= 360.f; if ( yrot < 0 ) yrot += 360.f; if ( directions & PAD_BUTTON_UP ) xrot -= 0.5f; if ( directions & PAD_BUTTON_DOWN ) xrot += 0.5f; if ( xrot > 360.f ) xrot -= 360.f; if ( xrot < 0 ) xrot += 360.f; if(first_frame) { first_frame = 0; VIDEO_SetBlack(FALSE); } // draw things DrawScene(view); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_DrawDone(); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); fb ^= 1; } }
/** * Taken from the devkitPPC template... */ void WiiEnvironment::setup() { // Mtx view; Mtx model, modelview; GXColor background = {0, 0, 0, 0xff}; // init the vi. VIDEO_Init(); WPAD_Init(); WPAD_SetDataFormat( WPAD_CHAN_0, WPAD_FMT_BTNS_ACC ); rmode = VIDEO_GetPreferredMode(NULL); // Attempt to initiate the fat filesystem... if ( !fatInitDefault() ) { // TODO: Logging somehow? exit( 1 ); } // allocate 2 framebuffers for double buffering frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); // setup the fifo and then init the flipper void *gp_fifo = NULL; gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gp_fifo,0,DEFAULT_FIFO_SIZE); GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer GX_SetCopyClear(background, 0x00ffffff); // other gx setup GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); GX_SetCullMode(GX_CULL_NONE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); // setup the vertex descriptor // tells the flipper to expect direct data GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); // setup the vertex attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGB8, 0); GX_SetNumChans(1); GX_SetNumTexGens(0); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); // setup our camera at the origin // looking down the -z axis with y up guVector cam = {0.0F, 0.0F, -100.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, 0.0F}; guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution f32 w = rmode->viWidth; f32 h = rmode->viHeight; guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); }
/**************************************************************************** * ResetVideo_Menu * * Reset the video/rendering mode for the menu ****************************************************************************/ void ResetVideo_Menu() { Mtx44 p; f32 yscale; u32 xfbHeight; VIDEO_Configure (vmode); VIDEO_Flush(); VIDEO_WaitVSync(); if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); else while (VIDEO_GetNextField()) VIDEO_WaitVSync(); // clears the bg to color and clears the z buffer GXColor background = {0, 0, 0, 255}; GX_SetCopyClear (background, 0x00ffffff); yscale = GX_GetYScaleFactor(vmode->efbHeight,vmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetDispCopySrc(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetDispCopyDst(vmode->fbWidth,xfbHeight); GX_SetCopyFilter(vmode->aa,vmode->sample_pattern,GX_TRUE,vmode->vfilter); GX_SetFieldMode(vmode->field_rendering,((vmode->viHeight==2*vmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (vmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); // setup the vertex descriptor // tells the flipper to expect direct data GX_ClearVtxDesc(); GX_InvVtxCache (); GX_InvalidateTexAll(); GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc (GX_VA_CLR0, GX_DIRECT); GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetZMode (GX_FALSE, GX_LEQUAL, GX_TRUE); GX_SetNumChans(1); GX_SetNumTexGens(1); GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); guMtxIdentity(GXmodelView2D); guMtxTransApply (GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -200.0F); GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0); guOrtho(p,0,479,0,639,0,300); GX_LoadProjectionMtx(p, GX_ORTHOGRAPHIC); GX_SetViewport(0,0,vmode->fbWidth,vmode->efbHeight,0,1); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetAlphaUpdate(GX_TRUE); }
void Menu_DrawDiskCover(f32 xpos, f32 ypos, f32 zpos, u16 width, u16 height, u16 distance, u8 data[], f32 deg_alpha, f32 deg_beta, f32 scaleX, f32 scaleY, u8 alpha, bool shadow) { if (data == NULL) return; GX_LoadProjectionMtx(FSProjection2D, GX_ORTHOGRAPHIC); GXTexObj texObj; GX_InitTexObj(&texObj, data, width, height, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_LoadTexObj(&texObj, GX_TEXMAP0); GX_ClearVtxDesc(); GX_InvVtxCache(); GX_InvalidateTexAll(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); f32 cos_beta = cos(DegToRad( deg_beta )); f32 s_offset_y = (zpos + (cos_beta * distance)) * tan(DegToRad( 5 )); f32 s_offset_x = (cos_beta < 0 ? -cos_beta : cos_beta) * s_offset_y; f32 s_offset_z = (s_offset_y < 0 ? 0 : s_offset_y) * 2; Mtx m, m1, m2, m3, m4, mv; width *= .5; height *= .5; guMtxIdentity(m4); guMtxTransApply(m4, m4, 0, 0, distance); guMtxIdentity(m1); guMtxScaleApply(m1, m1, scaleX, scaleY, 1.0); guVector axis2 = (guVector) {0 , 1, 0}; guMtxRotAxisDeg ( m2, &axis2, deg_beta ); guVector axis = (guVector) {0 , 0, 1}; guMtxRotAxisDeg ( m3, &axis, deg_alpha ); guMtxConcat(m3, m4, m3); // move distance then rotate z-axis guMtxConcat(m2, m3, m2); // rotate y-axis guMtxConcat(m1, m2, m); // scale if (shadow) guMtxTransApply(m, m, xpos + width + 0.5 + s_offset_x, ypos + height + 0.5 + s_offset_y, zpos - s_offset_z); else guMtxTransApply(m, m, xpos + width + 0.5, ypos + height + 0.5, zpos); guMtxConcat(FSModelView2D, m, mv); GX_LoadPosMtxImm(mv, GX_PNMTX0); GX_Begin(GX_QUADS, GX_VTXFMT0, 4); if (shadow) { GX_Position3f32(-width, -height, 0); GX_Color4u8(0, 0, 0, alpha); GX_TexCoord2f32(0, 0); GX_Position3f32(width, -height, 0); GX_Color4u8(0, 0, 0, alpha); GX_TexCoord2f32(1, 0); GX_Position3f32(width, height, 0); GX_Color4u8(0, 0, 0, alpha); GX_TexCoord2f32(1, 1); GX_Position3f32(-width, height, 0); GX_Color4u8(0, 0, 0, alpha); GX_TexCoord2f32(0, 1); } else { GX_Position3f32(-width, -height, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); GX_TexCoord2f32(0, 0); GX_Position3f32(width, -height, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); GX_TexCoord2f32(1, 0); GX_Position3f32(width, height, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); GX_TexCoord2f32(1, 1); GX_Position3f32(-width, height, 0); GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); GX_TexCoord2f32(0, 1); } GX_End(); }
void reduce_cubemap (cubemap_info *cubemap, int subdiv) { int x, y, face; const u32 vtxfmt = GX_VTXFMT0; Mtx mvtmp; Mtx44 ortho; object_loc rect_loc; scene_info rect_scene; int half_subdiv = subdiv / 2; float scale_factor = 1.0 / ((float) half_subdiv - 0.5); /* Using an even number of subdivisions and spreading evenly from -1...1 ensures we don't try to evaluate the singularity point at the back of the sphere. */ assert ((subdiv & 1) == 0); scene_set_pos (&rect_scene, (guVector) { 0, 0, -5 }); scene_set_lookat (&rect_scene, (guVector) { 0, 0, 0 }); scene_set_up (&rect_scene, (guVector) { 0, 1, 0 }); scene_update_camera (&rect_scene); guOrtho (ortho, -1, 1, -1, 1, 1, 15); object_loc_initialise (&rect_loc, GX_PNMTX0); guMtxIdentity (mvtmp); object_set_matrices (&rect_scene, &rect_loc, rect_scene.camera, mvtmp, NULL, ortho, GX_ORTHOGRAPHIC); GX_ClearVtxDesc (); GX_SetVtxDesc (GX_VA_POS, GX_DIRECT); GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT); 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); rendertarget_texture (cubemap->sphsize, cubemap->sphsize, cubemap->sphfmt, GX_FALSE, GX_PF_RGB8_Z24, GX_ZC_LINEAR); for (face = 0; face < 6; face++) { shader_load (cubemap->face_shader[face]); for (x = -half_subdiv; x < half_subdiv - 1; x++) { float a = ((float) x + 0.5) * scale_factor; float a1 = ((float) x + 1.5) * scale_factor; GX_Begin (GX_TRIANGLESTRIP, vtxfmt, subdiv * 2); for (y = -half_subdiv; y < half_subdiv; y++) { float b = ((float) y + 0.5) * scale_factor; guVector tmp; face_to_sphere (&tmp, face, a, b); GX_Position3f32 (tmp.x, tmp.y, tmp.z); GX_TexCoord2f32 ((a + 1.0) / 2.0, (b + 1.0) / 2.0); face_to_sphere (&tmp, face, a1, b); GX_Position3f32 (tmp.x, tmp.y, tmp.z); GX_TexCoord2f32 ((a1 + 1.0) / 2.0, (b + 1.0) / 2.0); } GX_End (); } } GX_CopyTex (cubemap->sphtexels, GX_TRUE); GX_PixModeSync (); }
void DrawAABB(MtxP M_model, Mtx M_view, AABB& box, u32 color) { GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxAttrFmt(GX_VTXFMT5, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT5, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); // build and load model-view matrix Mtx M_modelView; guMtxIdentity(M_modelView); guMtxConcat(M_view, M_model, M_modelView); GX_LoadPosMtxImm(M_modelView, GX_PNMTX0); GX_SetNumChans(1); // default, color = vertex color //GX_SetNumTexGens(0); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); u8 indices[8] = {0, 1, 0, 2, 1, 3, 2, 3}; guVector& m = box.min; f32* d = box.d; guVector v_bottom[4]; v_bottom[0] = _vec(m.x, m.y, m.z); v_bottom[1] = _vec(m.x + d[0], m.y, m.z); v_bottom[2] = _vec(m.x, m.y, m.z + d[2]); v_bottom[3] = _vec(m.x + d[0], m.y, m.z + d[2]); guVector v_top[4]; for (int i = 0; i < 4; i++) v_top[i] = _vec(v_bottom[i].x, v_bottom[i].y + d[1], v_bottom[i].z); GX_Begin(GX_LINES, GX_VTXFMT5, 24); // draw bottom for (u8 i = 0; i < 8; i += 2) { guVector& v0 = v_bottom[indices[i]]; guVector& v1 = v_bottom[indices[i+1]]; SendVertex(v0, color); SendVertex(v1, color); } // draw top for (u8 i = 0; i < 8; i += 2) { guVector& v0 = v_top[indices[i]]; guVector& v1 = v_top[indices[i+1]]; SendVertex(v0, color); SendVertex(v1, color); } // connect bottom vertices with the top ones for (u8 i = 0; i < 4; i++) { guVector& v0 = v_bottom[i]; guVector& v1 = v_top[i]; SendVertex(v0, color); SendVertex(v1, color); } GX_End(); }
int main(int argc,char **argv) { f32 yscale,zt = 0; u32 xfbHeight; u32 fb = 0; f32 rquad = 0.0f; u32 first_frame = 1; GXTexObj texture; Mtx view; // view and perspective matrices Mtx model, modelview; Mtx44 perspective; void *gpfifo = NULL; GXColor background = {0, 0, 0, 0xff}; guVector cam = {0.0F, 0.0F, 0.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, -1.0F}; TPLFile crateTPL; VIDEO_Init(); WPAD_Init(); rmode = VIDEO_GetPreferredMode(NULL); // allocate the fifo buffer gpfifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gpfifo,0,DEFAULT_FIFO_SIZE); // allocate 2 framebuffers for double buffering frameBuffer[0] = SYS_AllocateFramebuffer(rmode); frameBuffer[1] = SYS_AllocateFramebuffer(rmode); // configure video VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); fb ^= 1; // init the flipper GX_Init(gpfifo,DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer GX_SetCopyClear(background, 0x00ffffff); // other gx setup GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (rmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetCullMode(GX_CULL_NONE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); // setup the vertex attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); 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_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGB8, 0); GX_InvVtxCache(); GX_InvalidateTexAll(); TPL_OpenTPLFromMemory(&crateTPL, (void *)crate_tpl,crate_tpl_size); TPL_GetTexture(&crateTPL,crate,&texture); // setup our camera at the origin // looking down the -z axis with y up guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution f32 w = rmode->viWidth; f32 h = rmode->viHeight; guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); guVector cubeAxis = {1,1,1}; while(1) { WPAD_ScanPads(); if(WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) exit(0); else if (WPAD_ButtonsHeld(0)&WPAD_BUTTON_UP) zt -= 0.25f; else if (WPAD_ButtonsHeld(0)&WPAD_BUTTON_DOWN) zt += 0.25f; // set number of rasterized color channels GX_SetNumChans(1); //set number of textures to generate GX_SetNumTexGens(1); // setup texture coordinate generation // args: texcoord slot 0-7, matrix type, source to generate texture coordinates from, matrix to use GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_SetTevOp(GX_TEVSTAGE0,GX_REPLACE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_LoadTexObj(&texture, GX_TEXMAP0); guMtxIdentity(model); guMtxRotAxisDeg(model, &cubeAxis, rquad); guMtxTransApply(model, model, 0.0f,0.0f,zt-7.0f); guMtxConcat(view,model,modelview); // load the modelview matrix into matrix memory GX_LoadPosMtxImm(modelview, GX_PNMTX3); GX_SetCurrentMtx(GX_PNMTX3); GX_Begin(GX_QUADS, GX_VTXFMT0, 24); // Draw a Cube GX_Position3f32(-1.0f, 1.0f, -1.0f); // Top Left of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(-1.0f, 1.0f, 1.0f); // Top Right of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(-1.0f, -1.0f, 1.0f); // Bottom Right of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32(- 1.0f, -1.0f, -1.0f); // Bottom Left of the quad (top) GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( 1.0f,1.0f, -1.0f); // Top Left of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(1.0f,-1.0f, -1.0f); // Top Right of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(1.0f,-1.0f,1.0f); // Bottom Right of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( 1.0f,1.0f,1.0f); // Bottom Left of the quad (bottom) GX_Color3f32(1.0f,0.5f,0.0f); // Set The Color To Orange GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( -1.0f, -1.0f, 1.0f); // Top Right Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(1.0f, -1.0f, 1.0f); // Top Left Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(1.0f,-1.0f, -1.0f); // Bottom Left Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( -1.0f,-1.0f, -1.0f); // Bottom Right Of The Quad (Front) GX_Color3f32(1.0f,0.0f,0.0f); // Set The Color To Red GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( -1.0f,1.0f,1.0f); // Bottom Left Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(-1.0f,1.0f,-1.0f); // Bottom Right Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( 1.0f, 1.0f,1.0f); // Top Left Of The Quad (Back) GX_Color3f32(1.0f,1.0f,0.0f); // Set The Color To Yellow GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32(1.0f, -1.0f, -1.0f); // Top Right Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32(1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32(-1.0f,1.0f,-1.0f); // Bottom Left Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32(-1.0f,-1.0f, -1.0f); // Bottom Right Of The Quad (Left) GX_Color3f32(0.0f,0.0f,1.0f); // Set The Color To Blue GX_TexCoord2f32(0.0f,1.0f); GX_Position3f32( 1.0f, -1.0f,1.0f); // Top Right Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(0.0f,0.0f); GX_Position3f32( -1.0f, -1.0f, 1.0f); // Top Left Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(1.0f,0.0f); GX_Position3f32( -1.0f,1.0f, 1.0f); // Bottom Left Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(1.0f,1.0f); GX_Position3f32( 1.0f,1.0f,1.0f); // Bottom Right Of The Quad (Right) GX_Color3f32(1.0f,0.0f,1.0f); // Set The Color To Violet GX_TexCoord2f32(0.0f,1.0f); GX_End(); // Done Drawing The Quad GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_DrawDone(); VIDEO_SetNextFramebuffer(frameBuffer[fb]); if(first_frame) { first_frame = 0; VIDEO_SetBlack(FALSE); } VIDEO_Flush(); VIDEO_WaitVSync(); fb ^= 1; rquad -= 0.15f; // Decrease The Rotation Variable For The Quad ( NEW ) } }
void DrawOBB(Mtx M_view, OBB& box, u32 color, bool drawAxes) { //for (int i = 0; i < 3; i++) //SYS_LOG(L"u%i={%.3f, %.3f, %.3f}", i, box.u[i].x, box.u[i].y, box.u[i].z); //SYS_LOG(L"color=%x", color); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxAttrFmt(GX_VTXFMT5, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT5, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); // build and load model-view matrix Mtx M_modelView; guMtxIdentity(M_modelView); // rotation M_modelView[0][0] = box.u[0].x; M_modelView[0][1] = box.u[0].y; M_modelView[0][2] = box.u[0].z; M_modelView[1][0] = box.u[1].x; M_modelView[1][1] = box.u[1].y; M_modelView[1][2] = box.u[1].z; M_modelView[2][0] = box.u[2].x; M_modelView[2][1] = box.u[2].y; M_modelView[2][2] = box.u[2].z; // translation M_modelView[0][3] = box.c.x; M_modelView[1][3] = box.c.y; M_modelView[2][3] = box.c.z; guMtxConcat(M_view, M_modelView, M_modelView); GX_LoadPosMtxImm(M_modelView, GX_PNMTX0); GX_SetNumChans(1); // default, color = vertex color //GX_SetNumTexGens(0); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); u8 indices[8] = {0, 1, 0, 2, 1, 3, 2, 3}; f32* e = box.e; guVector v_bottom[4]; v_bottom[0] = _vec(-e[0], -e[1], +e[2]); v_bottom[1] = _vec(+e[0], -e[1], +e[2]); v_bottom[2] = _vec(-e[0], -e[1], -e[2]); v_bottom[3] = _vec(+e[0], -e[1], -e[2]); guVector v_top[4]; for (int i = 0; i < 4; i++) v_top[i] = _vec(v_bottom[i].x, e[1], v_bottom[i].z); GX_Begin(GX_LINES, GX_VTXFMT5, 24); // draw bottom for (u8 i = 0; i < 8; i += 2) { guVector& v0 = v_bottom[indices[i]]; guVector& v1 = v_bottom[indices[i+1]]; SendVertex(v0, color); SendVertex(v1, color); } // draw top for (u8 i = 0; i < 8; i += 2) { guVector& v0 = v_top[indices[i]]; guVector& v1 = v_top[indices[i+1]]; SendVertex(v0, color); SendVertex(v1, color); } // connect bottom vertices with the top ones for (u8 i = 0; i < 4; i++) { guVector& v0 = v_bottom[i]; guVector& v1 = v_top[i]; SendVertex(v0, color); SendVertex(v1, color); } GX_End(); if (!drawAxes) return; // axes const f32 len = 150; GX_Begin(GX_LINES, GX_VTXFMT5, 6); guVector zero = {0, 0, 0}; guVector x_unit = {len, 0, 0}; guVector y_unit = {0, len, 0}; guVector z_unit = {0, 0, len}; color = 0xFF0000FF; SendVertex(zero, color); SendVertex(x_unit, color); color = 0x00FF00FF; SendVertex(zero, color); SendVertex(y_unit, color); color = 0x0000FFFF; SendVertex(zero, color); SendVertex(z_unit, color); GX_End(); }