/*---------------------------------------------------------------------------* Project: Dolphin/Revolution gx demo File: smp-texexample.c Copyright 1998-2006 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 #define BALL64_TEX_ID 8 /*---------------------------------------------------------------------------* Model Data *---------------------------------------------------------------------------*/ static s8 Vert_s8[] ATTRIBUTE_ALIGN(32) = { -100, 100, 0, // 0 100, 100, 0, // 1 -100, -100, 0 // 2 }; static u32 Colors_u32[] ATTRIBUTE_ALIGN(32) = { // r g b a 0xff0000ff, // 0 0x00ff00ff, // 1 0x0000ffff // 2 }; // Array of texture coordinates static u8 TexCoords_u8[] ATTRIBUTE_ALIGN(32) = { 0x00, 0x00, // 0 // s t fixed point format is unsigned 8.0 0x01, 0x00, // 1 0x00, 0x01 // 2 }; /*---------------------------------------------------------------------------* Forward references *---------------------------------------------------------------------------*/ static void CameraInit( Mtx v ); /*---------------------------------------------------------------------------* Application main loop *---------------------------------------------------------------------------*/ void main ( void ) { PADStatus pad[4]; // game pad state GXTexObj texObj; // texture object Mtx v; // view matrix u8 i; // loop variable TPLPalettePtr tpl = 0; // texture palette pad[0].button = 0; DEMOInit(NULL); // Init os, pad, gx, vi CameraInit(v); GXLoadPosMtxImm(v, GX_PNMTX0); GXSetNumChans(1); // Enable light channel; by default = vertex color GXClearVtxDesc(); GXSetVtxDesc(GX_VA_POS, GX_INDEX8); GXSetVtxDesc(GX_VA_CLR0, GX_INDEX8); // Add an indexed texture coordinate to the vertex description GXSetVtxDesc(GX_VA_TEX0, GX_INDEX8); GXSetArray(GX_VA_POS, Vert_s8, 3*sizeof(s8)); GXSetArray(GX_VA_CLR0, Colors_u32, 1*sizeof(u32)); GXSetArray(GX_VA_TEX0, TexCoords_u8, 2*sizeof(u8)); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S8, 0); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); // Describe the texture coordinate format // fixed point format is unsigned 8.0 GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U8, 0); // Load the texture palette TPLGetPalette(&tpl, "gxTextrs.tpl"); // Initialize a texture object to contain the correct texture TPLGetGXTexObjFromPalette(tpl, &texObj, BALL64_TEX_ID); // Load the texture object; tex0 is used in stage 0 GXLoadTexObj(&texObj, GX_TEXMAP0); // Set the Texture Environment (Tev) Mode for stage 0 // GXInit sets default of 1 TexCoordGen // Default TexCoordGen is texcoord(n) from tex(n) with 2x4 identity mtx // Default number of tev stages is 1 // Default stage0 uses texcoord0, texmap0, color0a0 // Only need to change the tevop GXSetTevOp(GX_TEVSTAGE0, GX_DECAL); OSReport("\n\n********************************\n"); OSReport("to quit:\n"); OSReport(" hit the start button\n"); OSReport("********************************\n"); while(!(pad[0].button & PAD_BUTTON_MENU)) { DEMOBeforeRender(); // Draw a triangle GXBegin(GX_TRIANGLES, GX_VTXFMT0, 3); for (i = 0; i < 3; i++) { GXPosition1x8(i); GXColor1x8(i); // Add texture coordinate GXTexCoord1x8(i); } GXEnd(); DEMODoneRender(); PADRead(pad); } OSHalt("End of demo"); } /*---------------------------------------------------------------------------* Functions *---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------* Name: CameraInit Description: Initialize the projection matrix and load into hardware. Initialize the view matrix Arguments: v view matrix Returns: none *---------------------------------------------------------------------------*/ static void CameraInit ( Mtx v ) { Mtx44 p; Vec camPt = {0.0F, 0.0F, 800.0F}; Vec at = {0.0F, 0.0F, -100.0F}; Vec up = {0.0F, 1.0F, 0.0F}; MTXFrustum(p, 240.0F,-240.0F,-320.0F, 320.0F, 500, 2000); GXSetProjection(p, GX_PERSPECTIVE); MTXLookAt(v, &camPt, &up, &at); }