// SPDX-License-Identifier: CC0-1.0 // // SPDX-FileContributor: Antonio Niño Díaz, 2008-2011, 2019, 2022 // // This file is part of Nitro Engine #include #include #include #include #include #include #include NE_Camera *Camera; NE_Model *Model; NE_Animation *Animation; NE_Material *Material; void Draw3DScene(void) { NE_CameraUse(Camera); NE_PolyFormat(31, 0, NE_LIGHT_0, NE_CULL_NONE, 0); NE_ModelDraw(Model); } void WaitLoop(void) { while(1) swiWaitForVBlank(); } void LoadAndSetupGraphics3D(void) { // When using nflib for the 2D sub screen engine, banks C and H are used for // backgrounds and banks D and I are used for sprites. Nitro Engine only // uses bank E for palettes, so the only thing we need to do is to tell // Nitro Engine to only use banks A and B and leave C and D unused. NE_Init3D(); // libnds uses VRAM_C for the text console, reserve A and B only NE_TextureSystemReset(0, 0, NE_VRAM_AB); // Allocate space for objects... Model = NE_ModelCreate(NE_Animated); Camera = NE_CameraCreate(); Material = NE_MaterialCreate(); Animation = NE_AnimationCreate(); // Load assets form the filesystem if (NE_ModelLoadDSMFAT(Model, "chibi_kp.dsm") == 0) { consoleDemoInit(); printf("Couldn't load model..."); WaitLoop(); } if (NE_AnimationLoadFAT(Animation, "chibi_kp_idle.dsa") == 0) { consoleDemoInit(); printf("Couldn't load animation..."); WaitLoop(); } if (NE_MaterialTexLoadFAT(Material, NE_A1RGB5, 256, 256, NE_TEXGEN_TEXCOORD, "texture.img.bin") == 0) { consoleDemoInit(); printf("Couldn't load texture..."); WaitLoop(); } // Assign material to the model NE_ModelSetMaterial(Model, Material); // Assign animation to the model and start it NE_ModelSetAnimation(Model, Animation); NE_ModelAnimStart(Model, NE_ANIM_LOOP, floattof32(0.1)); // setup light NE_LightSet(0, NE_White, 0, -1, -1); // setup background color NE_ClearColorSet(RGB15(10, 0, 17), 31, 63); // Setup camera NE_CameraSet(Camera, 6, 1.5, -1, 0, 0, 0, 0, 0, -1); NE_SetFov(30); } void LoadAndSetupGraphics2D(void) { // Initialize sub 2D engine NF_Set2D(1, 0); // Initialize tiled backgrounds and text systems for the 2D sub engine // (using VRAM C & D) NF_InitTiledBgBuffers(); NF_InitTiledBgSys(1); NF_InitTextSys(1); // load assets from filesystem to RAM NF_LoadTiledBg("bg/badge_01", "capa_0", 2048, 256); NF_LoadTextFont("fnt/default", "normal", 256, 256, 0); // Create tiled background NF_CreateTiledBg(1, 1, "capa_0"); // Create text layer NF_CreateTextLayer(1, 0, 0, "normal"); } int main(void) { // Initialize nitrof before doing anything else NF_Set2D(0, 0); NF_Set2D(1, 0); consoleDemoInit(); printf("Starting nitroFS...\n"); if(!nitroFSInit(NULL)) { printf("Failed to start nitroFS\n"); printf("Press START to exit\n"); while (1) { swiWaitForVBlank(); scanKeys(); if (keysHeld() & KEY_START) return -1; } } swiWaitForVBlank(); // Set the root folder to the nitroFS filesystem NF_SetRootFolder("NITROFS"); //setup interrupt irqEnable(IRQ_HBLANK); irqSet(IRQ_VBLANK, NE_VBLFunc); irqSet(IRQ_HBLANK, NE_HBLFunc); // load and setup graphics LoadAndSetupGraphics3D(); LoadAndSetupGraphics2D(); // print instructions: //NF_WriteText(1, 0, 1, 1, "PAD: Rotate Model"); //NF_WriteText(1, 0, 1, 2, "START: Exit"); //NF_UpdateTextLayers(); while (1) { NE_WaitForVBL(NE_UPDATE_ANIMATIONS); //rotate model: NE_ModelRotate(Model, 0, 1, 0); scanKeys(); uint32_t keys = keysHeld(); if (keys & KEY_START) break; if (keys & KEY_RIGHT) NE_ModelRotate(Model, 0, 2, 0); if (keys & KEY_LEFT) NE_ModelRotate(Model, 0, -2, 0); if (keys & KEY_UP) NE_ModelRotate(Model, 0, 0, 2); if (keys & KEY_DOWN) NE_ModelRotate(Model, 0, 0, -2); // Draw scene... NE_Process(Draw3DScene); } return 0; }