/*---------------------------------------------------------------------------* Project: KPAD sample program File: graphic.c Programmer: Keizo Ohta Copyright 2005 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ #include #include #include "graphic.h" /*************************************************************** Variables ***************************************************************/ GXColor black_clr = { 0, 0, 0, 255 } ; GXColor smoke_clr = { 61, 61, 61, 255 } ; GXColor gray_clr = { 129,129,129, 255 } ; GXColor white_clr = { 255,255,255, 255 } ; GXColor silver_clr = { 193,193,193, 255 } ; GXColor red_clr = { 237, 28, 36, 255 } ; GXColor green_clr = { 0,166, 81, 255 } ; GXColor blue_clr = { 0, 84,166, 255 } ; GXColor yellow_clr = { 255,242, 0, 255 } ; GXColor cyan_clr = { 0,174,239, 255 } ; GXColor magenta_clr = { 236, 0,140, 255 } ; GXColor orange_clr = { 245,125, 32, 255 } ; GXColor violet_clr = { 102, 45,145, 255 } ; GXColor peagreen_clr = { 141,198, 63, 255 } ; /******************************************************************************* Initialize drawing of simple graphics fb_width :Horizontal resolution of frame buffer fb_height :Vertical resolution of frame buffer *******************************************************************************/ void init_draw_graphic( u16 fb_width, u16 fb_height ) { Mtx44 proj_mtx ; Mtx view_mtx ; f32 canvas_wd, canvas_ht ; //----- Virtual canvas size canvas_wd = fb_width * 0.91346f ; canvas_ht = fb_height ; //----- MTX MTXOrtho( proj_mtx, canvas_ht * -0.5f,canvas_ht * 0.5f, canvas_wd * -0.5f,canvas_wd * 0.5f, -10.0f,10.0f ) ; GXSetProjection( proj_mtx, GX_ORTHOGRAPHIC ) ; MTXIdentity( view_mtx ) ; GXLoadPosMtxImm( view_mtx, GX_PNMTX0 ) ; GXSetCurrentMtx( GX_PNMTX0 ) ; //----- VERTEX GXClearVtxDesc() ; GXSetVtxDesc( GX_VA_POS, GX_DIRECT ) ; GXSetVtxAttrFmt( GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0 ) ; //----- CHANNEL GXSetNumChans( 1 ) ; GXSetChanCtrl( GX_COLOR0A0, GX_DISABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE ) ; GXSetChanCtrl( GX_COLOR1A1, GX_DISABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE ) ; //----- TEXTURE GXSetNumTexGens( 0 ) ; //----- TEV GXSetNumTevStages( 1 ) ; GXSetTevOrder( GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL ) ; GXSetTevColorIn( GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C0 ) ; GXSetTevColorOp( GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV ) ; GXSetTevAlphaIn( GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_A0 ) ; GXSetTevAlphaOp( GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV ) ; GXSetAlphaCompare( GX_ALWAYS,0, GX_AOP_OR, GX_ALWAYS,0 ) ; //----- SCREEN GXSetBlendMode( GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_NOOP ) ; GXSetAlphaUpdate( GX_DISABLE ) ; GXSetZMode( GX_DISABLE, GX_ALWAYS, GX_DISABLE ) ; GXSetCullMode( GX_CULL_BACK ) ; } /******************************************************************************* Draw point *******************************************************************************/ void draw_point( f32 px, f32 py, GXColor clr, f32 size ) { GXSetTevColor( GX_TEVREG0, clr ) ; GXSetPointSize( (u8)(s32)(size * 6.0f + 0.5f), GX_TO_ZERO ) ; GXBegin( GX_POINTS, GX_VTXFMT0, 1 ) ; GXPosition2f32( px, py ) ; GXEnd() ; } /******************************************************************************* Draw line *******************************************************************************/ void draw_line( f32 x1, f32 y1, f32 x2, f32 y2, GXColor clr, f32 width ) { GXSetTevColor( GX_TEVREG0, clr ) ; GXSetLineWidth( (u8)(s32)(width * 6.0f + 0.5f), GX_TO_ZERO ) ; GXBegin( GX_LINES, GX_VTXFMT0, 2 ) ; GXPosition2f32( x1, y1 ) ; GXPosition2f32( x2, y2 ) ; GXEnd() ; } /******************************************************************************* Draw broken line *******************************************************************************/ void draw_dashed_line( f32 x1, f32 y1, f32 x2, f32 y2, GXColor clr, f32 width ) { const int DIV=5; int i=0; f32 dx = x2 - x1; f32 dy = y2 - y1; f32 length = (f32)sqrt(dx*dx + dy*dy); GXSetTevColor( GX_TEVREG0, clr ) ; GXSetLineWidth( (u8)(s32)(width * 6.0f + 0.5f), GX_TO_ZERO ) ; for(i=0; i