int main()
{
touchPosition touch;
// Turn on everything
powerON(POWER_ALL);
// Setup the Main screen for 3D
videoSetMode(MODE_0_3D);
videoSetModeSub(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_2D_BMP_256);
SUB_BG2_CR = BG_BMP16_256x256;
SUB_BG2_XDX = 256;
SUB_BG2_XDY = 0;
SUB_BG2_YDX = 0;
SUB_BG2_YDY = 256;
SUB_BG2_CY = 0;
SUB_BG2_CX = 0;
vramSetMainBanks(VRAM_A_TEXTURE, VRAM_B_LCD, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE);
int y = 0;
int x = 0;
for (y = 0; y < SCREEN_HEIGHT; y++)
for (x = 0; x < SCREEN_WIDTH; x++)
{
BG_GFX_SUB[y * SCREEN_WIDTH + x] = RGB15(31, x % 32, y % 32) | BIT(15);
}
// IRQ basic setup
irqInit();
irqSet(IRQ_VBLANK, 0);
glViewPort(0,0,255,191);
// Specify the Clear Color and Depth
glClearColor(0,0,0);
glClearDepth(0x7FFF);
InitSprites();
int i = 0;
for (y = 0; y < 3; y++)
for (x = 0; x < 4; x++)
{
sprites[i].attribute[0] = ATTR0_BMP | ATTR0_SQUARE | (64 * y);
sprites[i].attribute[1] = ATTR1_SIZE_64 | (64 * x);
sprites[i].attribute[2] = ATTR2_ALPHA(1) | (8 * 32 * y) | (8 * x);
i++;
}
uint32 frameCount = 0;
dsScene * scene = new dsIntro;
scene->load(frameCount);
while (1)
{
// Check if our scene needs changed
if(scene->getState() == state_UNLOADED)
{
free(scene);
scene = new dsMenu;
}
// Reset the screen and setup the view
glReset();
scanKeys();
touch=touchReadXY();
scene->touch(touch);
glOrtho(0,1,0,1,-6,6);
glColor3f(1,1,1);
glLight(0, RGB15(31,31,31) , 0, floattov10(-1.0), 0);
glLight(1, RGB15(31,31,31) , 0, 0, floattov10(-1.0));
glLight(2, RGB15(31,31,31) , 0, 0, floattov10(1.0));
glPushMatrix();
glMatrixMode(GL_TEXTURE);
glIdentity();
glMatrixMode(GL_MODELVIEW);
//need to set up some material properties since DS does not have them set by default
glMaterialf(GL_AMBIENT, RGB15(16,16,16));
glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
glMaterialf(GL_EMISSION, RGB15(16,16,16));
//ds uses a table for shinyness..this generates a half-ass one
glMaterialShinyness();
if(!(keysHeld() & KEY_L))
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE | POLY_FORMAT_LIGHT0| POLY_FORMAT_LIGHT1| POLY_FORMAT_LIGHT2);
else
glPolyFmt(POLY_ALPHA(0) | POLY_CULL_NONE | POLY_FORMAT_LIGHT0| POLY_FORMAT_LIGHT1| POLY_FORMAT_LIGHT2);
// Set the current matrix to be the model matrix
glMatrixMode(GL_MODELVIEW);
//Push our original Matrix onto the stack (save state)
glPushMatrix();
// TODO: Remove reliance on two VRAM banks. It can be done with one, I think.
if (frameCount & 0x1)
{
vramSetBankC(VRAM_C_SUB_BG);
vramSetBankD(VRAM_D_LCD);
SetRegCapture(true, 0, 15, 3, 0, 3, 0, 0);
scene->draw_top(frameCount);
} else {
vramSetBankC(VRAM_C_LCD);
vramSetBankD(VRAM_D_SUB_SPRITE);
SetRegCapture(true, 0, 15, 2, 0, 3, 0, 0);
scene->draw_bottom(frameCount);
}
// Pop our Matrix from the stack (restore state)
glPopMatrix(1);
frameCount++;
// flush to screen
glFlush();
lcdSwap();
UpdateOAM();
}
return 0;
} |