#include <nds.h>
void renderCube(int angle){
glPushMatrix();
glTranslatef(0, 0, -4);
glRotatef32i(degreesToAngle(angle), inttof32(1), inttof32(1), inttof32(1));
glBegin(GL_QUADS);
glColor3b(255,0,0); glVertex3f(-1.0f, 1.0f, 1.0f);
glColor3b(0,255,0); glVertex3f( 1.0f, 1.0f, 1.0f);
glColor3b(0,0,255); glVertex3f( 1.0f, -1.0f, 1.0f);
glColor3b(255,255,0); glVertex3f(-1.0f, -1.0f, 1.0f);
glColor3b(255,0,0); glVertex3f(-1.0f, 1.0f, -1.0f);
glColor3b(0,255,0); glVertex3f( 1.0f, 1.0f, -1.0f);
glColor3b(0,0,255); glVertex3f( 1.0f, -1.0f, -1.0f);
glColor3b(255,255,0); glVertex3f(-1.0f, -1.0f, -1.0f);
glColor3b(255,0,0); glVertex3f(-1.0f, 1.0f, 1.0f);
glColor3b(0,255,0); glVertex3f( 1.0f, 1.0f, 1.0f);
glColor3b(0,0,255); glVertex3f( 1.0f, 1.0f, -1.0f);
glColor3b(255,255,0); glVertex3f(-1.0f, 1.0f, -1.0f);
glColor3b(255,0,0); glVertex3f(-1.0f, -1.0f, 1.0f);
glColor3b(0,255,0); glVertex3f( 1.0f, -1.0f, 1.0f);
glColor3b(0,0,255); glVertex3f( 1.0f, -1.0f, -1.0f);
glColor3b(255,255,0); glVertex3f(-1.0f, -1.0f, -1.0f);
glColor3b(255,0,0); glVertex3f( 1.0f, 1.0f, -1.0f);
glColor3b(0,255,0); glVertex3f( 1.0f, 1.0f, 1.0f);
glColor3b(0,0,255); glVertex3f( 1.0f,-1.0f, 1.0f);
glColor3b(255,255,0); glVertex3f( 1.0f,-1.0f, -1.0f);
glColor3b(255,0,0); glVertex3f(-1.0f, 1.0f, -1.0f);
glColor3b(0,255,0); glVertex3f(-1.0f, 1.0f, 1.0f);
glColor3b(0,0,255); glVertex3f(-1.0f,-1.0f, 1.0f);
glColor3b(255,255,0); glVertex3f(-1.0f,-1.0f, -1.0f);
glEnd();
glPopMatrix(1);
}
void renderPyramid(int angle){
glPushMatrix();
glTranslatef(0, 0, -4);
glRotatef32i(degreesToAngle(angle), inttof32(1),inttof32(1),inttof32(1));
glBegin(GL_QUADS);
glColor3b(255,0,0); glVertex3f(-1.0f, -1.0f, 1.0f);
glColor3b(0,255,0); glVertex3f( 1.0f, -1.0f, 1.0f);
glColor3b(0,0,255); glVertex3f( 1.0f, -1.0f, -1.0f);
glColor3b(255,255,0); glVertex3f(-1.0f, -1.0f, -1.0f);
glEnd();
glBegin(GL_TRIANGLES);
glColor3b(255,0,0); glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3b(0,255,0); glVertex3f(-1.0f, -1.0f, 1.0f);
glColor3b(0,0,255); glVertex3f( 1.0f, -1.0f, 1.0f);
glColor3b(255,0,0); glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3b(0,255,0); glVertex3f(-1.0f, -1.0f, -1.0f);
glColor3b(0,0,255); glVertex3f( 1.0f, -1.0f, -1.0f);
glColor3b(255,0,0); glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3b(0,255,0); glVertex3f(-1.0f, -1.0f, 1.0f);
glColor3b(0,0,255); glVertex3f(-1.0f, -1.0f, -1.0f);
glColor3b(255,0,0); glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3b(0,255,0); glVertex3f( 1.0f, -1.0f, 1.0f);
glColor3b(0,0,255); glVertex3f( 1.0f, -1.0f, -1.0f);
glEnd();
glPopMatrix(1);
}
void renderScene(bool top){
static short angle = 0;
if(top)
renderCube(angle);
else
renderPyramid(angle);
angle++;
}
void initSubSprites(void){
oamInit(&oamSub, SpriteMapping_Bmp_2D_256, false);
int x = 0;
int y = 0;
for(y = 0; y < 3; y++)
for(x = 0; x < 4; x++)
{
u16 *offset = &SPRITE_GFX_SUB[(x * 64) + (y * 64 * 256)];
oamSet(&oamSub, x + y * 4, x * 64, y * 64, 0, 15, SpriteSize_64x64,
SpriteColorFormat_Bmp, offset, -1, false,false,false,false,false);
}
swiWaitForVBlank();
oamUpdate(&oamSub);
}
int main() {
videoSetMode(MODE_0_3D);
videoSetModeSub(MODE_5_2D);
glInit();
initSubSprites();
bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
glEnable(GL_ANTIALIAS);
glClearColor(0,0,0,31);
glClearPolyID(63);
glClearDepth(0x7FFF);
glViewport(0,0,255,191);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70, 256.0 / 192.0, 0.1, 100);
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
bool top = true;
while (true)
{
while(REG_DISPCAPCNT & DCAP_ENABLE);
top = !top;
if(top)
{
lcdMainOnBottom();
vramSetBankC(VRAM_C_LCD);
vramSetBankD(VRAM_D_SUB_SPRITE);
REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3);
}
else
{
lcdMainOnTop();
vramSetBankD(VRAM_D_LCD);
vramSetBankC(VRAM_C_SUB_BG);
REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3);
}
glMatrixMode(GL_MODELVIEW);
renderScene(top);
glFlush(0);
}
return 0;
}