int main() { //enable vram and map it to the right places vramSetMainBanks( VRAM_A_MAIN_SPRITE, //A and B maped consecutivly as sprite memory VRAM_B_MAIN_SPRITE, //this gives us 256KB which is the max VRAM_C_MAIN_BG_0x06000000, //map C to background memory VRAM_D_LCD //not using D ); //set the video mode videoSetMode( MODE_0_2D | DISPLAY_SPR_ACTIVE | //turn on sprites DISPLAY_BG0_ACTIVE | //turn on background 0 DISPLAY_SPR_1D | //this is used when in tile mode DISPLAY_SPR_1D_BMP //and this in bitmap mode ); consoleInit(0, 0,BgType_Text4bpp, BgSize_T_256x256, 31,0, true, true); //turn off the sprites initSprites(); // direct bitmap sprite // print at using ansi escape sequence \x1b[line;columnH iprintf("\x1b[1;1HDirect Bitmap:"); sprites[0].attribute[0] = ATTR0_BMP | ATTR0_ROTSCALE_DOUBLE | 10; sprites[0].attribute[1] = ATTR1_SIZE_32 | 20; sprites[0].attribute[2] = ATTR2_ALPHA(1)| 0; // red 32*32 square for 1d bitmap mode for(int i=0;i<32*32;i++) SPRITE_GFX[i]=RGB15(31,0,0)|(1<<15); //dont forget alpha bit // 256 color sprite // print at using ansi escape sequence \x1b[line;columnH iprintf("\x1b[9;1H256 color:"); sprites[1].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE_DOUBLE | 75; sprites[1].attribute[1] = ATTR1_SIZE_32 | 20; // size 64x64, x 10 sprites[1].attribute[2] = 64; // Blue for 256 color sprite SPRITE_PALETTE[1]=RGB15(0,0,31); // blue 64*64 square for 256 color mode (must write two pixles at time) for(int i=0;i<32*16;i++) SPRITE_GFX[i+64*16]=(1<<8)|1; // 16 color sprite // print at using ansi escape sequence \x1b[line;columnH iprintf("\x1b[16;1H16 color:"); sprites[2].attribute[0] = ATTR0_COLOR_16 | ATTR0_ROTSCALE_DOUBLE | 135; sprites[2].attribute[1] = ATTR1_SIZE_32 | 20; sprites[2].attribute[2] = ATTR2_PALETTE(1) | 96; //yellow for 16 color sprite (it is using palette 1 so colors 16-31) SPRITE_PALETTE[17]=RGB15(31,31,0); // yellow 32*32 square for 16 color mode (must write 4 pixels at a time) for(int i=0;i<32*8;i++) SPRITE_GFX[i+96*16]=(1<<12)|(1<<8)|(1<<4)|1; int angle=0; //we tied all our sprites to the same rotation attributes (0) spriteRotations[0].hdx=256; spriteRotations[0].hdy=0; spriteRotations[0].vdx=0; spriteRotations[0].vdy=256; while(1) { angle+=64; spriteRotations[0].hdx = cosLerp(angle) >> 4; spriteRotations[0].hdy = sinLerp(angle) >> 4; spriteRotations[0].vdx = -spriteRotations[0].hdy; spriteRotations[0].vdy = spriteRotations[0].hdx; swiWaitForVBlank(); u32 display_temp = 0; scanKeys(); if(keysDown()&KEY_A) { screenshotbmp("shot.bmp"); display_temp=REG_DISPCNT; REG_DISPCNT=MODE_FB1; } if(keysUp()&KEY_A) { videoSetMode( MODE_0_2D | DISPLAY_SPR_ACTIVE | //turn on sprites DISPLAY_BG0_ACTIVE | //turn on background 0 DISPLAY_SPR_1D | //this is used when in tile mode DISPLAY_SPR_1D_BMP | //and this in bitmap mode DCAP_OFFSET(1)); } updateOAM(); } }
int main() { int textureID; int i; float rotateX = 0.0; float rotateY = 0.0; //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); // initialize gl glInit(); //enable textures glEnable(GL_TEXTURE_2D); //this should work the same as the normal gl call glViewport(0,0,255,191); // enable antialiasing glEnable(GL_ANTIALIAS); // setup the rear plane glClearColor(0,0,0,31); // BG must be opaque for AA to work glClearPolyID(63); // BG must have a unique polygon ID for AA to work glClearDepth(0x7FFF); vramSetBankB(VRAM_B_LCD); REG_DISPCAPCNT = DCAP_MODE(DCAP_MODE_BLEND) //blend source A and source B //| DCAP_SRC_ADDR //this is not used since we are setting the display to render from VRAM | DCAP_SRC_B(DCAP_SRC_B_VRAM) | DCAP_SRC_A(DCAP_SRC_A_3DONLY) | DCAP_SIZE(DCAP_SIZE_256x192) | DCAP_OFFSET(0) //where to write the captured data within our chosen VRAM bank | DCAP_BANK(DCAP_BANK_VRAM_B) | DCAP_B(12) //blend mostly from B to make a very dramatic effect | DCAP_A(4) //and blend only a little bit from the new scene ; //but, dramatic effects tend to leave some garbage on the screen since the precision of the math is low, //and we're not putting a lot of dampening on the effect. //a more realistic value might be 8 and 8, but perhaps in a more complex 3d scene the garbage isn't such a bad thing //since the scene is changing constantly DisplayEnableMotionBlur(); bool displayBlurred = true; vramSetBankA(VRAM_A_TEXTURE); glGenTextures(1, &textureID); glBindTexture(0, textureID); glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_bin); //any floating point gl call is being converted to fixed prior to being implemented glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 40); gluLookAt( 0.0, 0.0, 1.0, //camera possition 0.0, 0.0, 0.0, //look at 0.0, 1.0, 0.0); //up while(1) { glLight(0, RGB15(31,31,31) , 0, floattov10(-1.0), 0); glLight(1, RGB15(31,0,31), 0, floattov10(1) - 1, 0); glLight(2, RGB15(0,31,0) , floattov10(-1.0), 0, 0); glLight(3, RGB15(0,0,31) , floattov10(1.0) - 1, 0, 0); glPushMatrix(); //move it away from the camera glTranslatef32(0, 0, floattof32(-1)); glRotateX(rotateX); glRotateY(rotateY); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glMaterialf(GL_AMBIENT, RGB15(8,8,8)); glMaterialf(GL_DIFFUSE, RGB15(16,16,16)); glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8)); glMaterialf(GL_EMISSION, RGB15(5,5,5)); //ds uses a table for shinyness..this generates a half-ass one glMaterialShinyness(); //not a real gl function and will likely change glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1 | POLY_FORMAT_LIGHT2 | POLY_FORMAT_LIGHT3 ) ; scanKeys(); u16 keys = keysHeld(); if((keys & KEY_UP)) rotateX += 3; if((keys & KEY_DOWN)) rotateX -= 3; if((keys & KEY_LEFT)) rotateY += 3; if((keys & KEY_RIGHT)) rotateY -= 3; if(keysDown() & KEY_A) { displayBlurred = !displayBlurred; if(displayBlurred) DisplayEnableMotionBlur(); else DisplayEnableNormal(); } glBindTexture(0, textureID); //draw the obj glBegin(GL_QUAD); for(i = 0; i < 6; i++) drawQuad(i); glEnd(); glPopMatrix(1); glFlush(0); swiWaitForVBlank(); if(keys & KEY_START) break; //the display capture enable bit must be set again each frame if you want to continue capturing. REG_DISPCAPCNT |= DCAP_ENABLE; } return 0; }//end main