bool Base::Init() { if(SDL_Init(SDL_INIT_EVERYTHING) < 0) return false; glDisable(GL_DEPTH_TEST); /* Only drawing in 2d */ sdlWindow = SDL_CreateWindow("OpenGL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640,480, SDL_WINDOW_OPENGL); glContext = SDL_GL_CreateContext(sdlWindow); glViewPort(0,0, (GLsizei) 640,(GLsizei) 480); loadFile = new LoadFile(); return true; }
int main(void) { float x_angle = 0, y_angle = 0; float x_speed = 0, y_speed = 0; float distance = 1; powerON(POWER_ALL); irqInit(); irqEnable(IRQ_VBLANK); videoSetMode(MODE_0_3D); consoleDemoInit(); /* Set up a timer to count FPS */ TIMER3_DATA = TIMER_FREQ_1024(1); TIMER3_CR = TIMER_DIV_1024 | TIMER_IRQ_REQ; irqSet(IRQ_TIMER3, fps_timer_irq); irqEnable(IRQ_TIMER3); glViewPort(0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1); glClearColor(0, 0, 0); glClearDepth(GL_MAX_DEPTH); iprintf("Hello World!\n\n"); glReset(); gluPerspective(35, SCREEN_WIDTH / (float) SCREEN_HEIGHT, 0.1, 40.0); gluLookAt(0.0, 0.0, 1.0, /* Eye */ 0.0, 0.0, 0.0, /* Look at */ 0.0, 1.0, 0.0); /* Up */ 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)); glMaterialShinyness(); glColor(RGB15(31, 31, 31)); glLight(0, RGB15(20, 15, 15), floattov10(-0.9), floattov10( 0.9), floattov10( 0.2)); glLight(1, RGB15(15, 15, 20), floattov10( 0.4), floattov10( 0.9), floattov10( 0.2)); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0 | POLY_FORMAT_LIGHT1); while (1) { scanKeys(); if (keysHeld() & KEY_START) Loader_Exit9(); if (keysHeld() & KEY_UP) x_speed += 0.05; if (keysHeld() & KEY_DOWN) x_speed -= 0.05; if (keysHeld() & KEY_LEFT) y_speed += 0.05; if (keysHeld() & KEY_RIGHT) y_speed -= 0.05; if (keysHeld() & KEY_R) distance += 0.05; if (keysHeld() & KEY_L) distance -= 0.05; glPushMatrix(); glTranslate3f32(floattof32( 0.0), floattof32( 0.0), floattof32(-distance)); glRotateX(x_angle += x_speed); glRotateY(y_angle += y_speed); glCallList(display_list_bin); glPopMatrix(1); glFlush(); frames++; swiWaitForVBlank(); } return 0; }
void reshape(int w, int h){ glViewPort(0, 0, (GLsizei)w, 0.0, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h); }
int main() { struct timeval tv; powerON(POWER_ALL); //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); //Use console videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text vramSetBankC(VRAM_C_SUB_BG); SUB_BG0_CR = BG_MAP_BASE(31); BG_PALETTE_SUB[255] = RGB15(31,31,31); //by default font will be rendered with color 255 consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16); //iprintf("Starting up...\n"); // install the default exception handler defaultExceptionHandler(); //irqs are nice irqInit(); irqEnable(IRQ_VBLANK); // set the generic sound parameters setGenericSound( 11025, /* sample rate */ 127, /* volume */ 64, /* panning */ 1 ); /* sound format*/ glInit(); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); //this should work the same as the normal gl call glViewPort(0,0,255,191); glClearColor(0,0,0,0); glClearDepth(0x7FFF); vramSetBankA(VRAM_A_TEXTURE); vramSetBankB(VRAM_B_TEXTURE); logo(); glGenTextures(1, &textureID); glBindTexture(0, textureID); glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256 , TEXTURE_SIZE_256, 0, TEXGEN_TEXCOORD , (u8*)die_bmp_bin); glGenTextures(1, &textureID2); glBindTexture(0, textureID2); glTexImage2D(0, 0, GL_RGBA, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)mario_bmp_bin); gettimeofday(&tv, NULL); //iprintf("Seeding with %d\n", tv.tv_usec); srand(tv.tv_usec); while(1){ gameLoop(); } return 0; }//end main
int main() { struct touchPosition pos; float rotateX = 0.0; float rotateY = 0.0; powerON(POWER_ALL); consoleDemoInit(); //set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); //irqs are nice irqInit(); irqEnable(IRQ_VBLANK); // initialize gl glInit(); // 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); //this should work the same as the normal gl call glViewPort(0,0,255,191); //any floating point gl call is being converted to fixed prior to being implemented glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(35, 256.0 / 192.0, 0.1, 100); 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) { float px, py; pos = touchReadXY(); px = pos.px; py = pos.py; px = (px * 5) / 256; py = (py * 3) / 192; px -= 2.5; py -= 1.5; glPushMatrix(); //move it away from the camera glTranslate3f32(0, 0, floattof32(-1)); glRotateX(rotateX); glRotateY(rotateY); glMatrixMode(GL_MODELVIEW); //not a real gl function and will likely change glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); 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; //draw the obj glBegin(GL_TRIANGLE); glColor3b(255,0,0); glVertex3v16(inttov16(-1),inttov16(-1),0); glColor3b(0,255,0); glVertex3v16(inttov16(1), inttov16(-1), 0); glColor3b(0,0,255); glVertex3v16(inttov16(0), inttov16(1), 0); glEnd(); glLoadIdentity(); glTranslatef(px,-py,-3.0); glBegin(GL_TRIANGLE); glVertex3f( 0.0, 1.0, 0.0); glVertex3f(-1.0,-1.0, 0.0); glVertex3f( 1.0,-1.0, 0.0); glEnd(); glPopMatrix(1); glFlush(0); swiWaitForVBlank(); } return 0; }//end main
int main(void) { touchPosition touch; videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text vramSetBankC(VRAM_C_SUB_BG); SUB_BG0_CR = BG_MAP_BASE(31); BG_PALETTE_SUB[255] = RGB15(31,31,31); //by default font will be rendered with color 255 //consoleInit() is a lot more fluxible but this gets you up and running quick consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16); ///////////// powerON(POWER_ALL); // set mode 0, enable BG0 and set it to 3D videoSetMode(MODE_0_3D); vramSetBankA(VRAM_A_TEXTURE); // irqs are nice irqInit(); irqEnable(IRQ_VBLANK); // initialize gl glInit(); // setup the rear plane glClearColor(2, 4, 3, 16); glClearDepth(GL_MAX_DEPTH); // this should work the same as the normal gl call glViewPort(0,0, 255,191); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //~ glOrtho(0, 1, 192.0/256.0, 0, -10, 10); glOrthof32(0, 1<<12, (192<<12)/256, 0, -10<<12, 10<<12); REG_POWERCNT^= POWER_SWAP_LCDS; ///////////// flux_init(); create_frame_groups(); create_button_groups(); create_titleframe(); dmaCopy(fluxcolors, syscol_table, sizeof(fluxcolors)); dword rc1= create_rect(NOPARENT, 20,20, 128,96, 0x808080); dword rc= create_rect(NOPARENT, 10,10, 128,96, 0x404040|TRANSL_3); dword frm= clone_frame("titleframe", rc); clone_frame("titleframe", rc1); //~ clone_group("button", rc, 10,30, 30,14, ALIGN_LEFT|ALIGN_TOP); create_rect(rc, 10,10, 10,10, 0xFFFFFF|TRANSL_1); create_rect(rc, 20,10, 10,10, 0xFFFFFF|TRANSL_2); create_rect(rc, 30,10, 10,10, 0xFFFFFF|TRANSL_3); create_rect(rc, 10,15, 30,10, 0xFFFFFF|TRANSL_1); create_text(rc, 10,30, 40,40, "Text! Space!\nNewline!", 0xFFFFFF, FONT_DEFAULT); bool redraw_all= true; bool touch_wasdown= false; int lasttouch_x, lasttouch_y; while(1) { scanKeys(); u32 keysheld= keysHeld(); u32 keysdown= keysDown(); touch= touchReadXY(); if(keysdown&KEY_A) { redraw_all^= 1; iprintf("redraw each frame: %s\n", redraw_all? "on": "off"); } if(keysdown&KEY_B) { do_texalpha^= 1; iprintf("texture alpha: %s\n", do_texalpha? "on": "off"); } if(touch.x || touch.y) { flux_mouse_event(touch.px, touch.py, 1); lasttouch_x= touch.px, lasttouch_y= touch.py; touch_wasdown= true; } else { if(touch_wasdown) flux_mouse_event(lasttouch_x, lasttouch_y, 0); touch_wasdown= false; } flux_tick(); if(redraw_all) { redraw_rect(&viewport); update_rect(&viewport); } swiWaitForVBlank(); } return 0; }