int main() { sf2d_init(); sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); consoleInit(GFX_BOTTOM, NULL); printf("sftd sample\n"); // Font loading sftd_init(); sftd_font *font = sftd_load_font_mem(airstrike_ttf, airstrike_ttf_size); while (aptMainLoop()) { hidScanInput(); if (hidKeysDown() & KEY_START) break; sf2d_start_frame(GFX_TOP, GFX_LEFT); sftd_draw_text(font, 10, 10, RGBA8(255, 0, 0, 255), 20, "Font drawing on the top screen!"); sftd_draw_textf(font, 10, 40, RGBA8(0, 255, 0, 255), 20, "FPS %f", sf2d_get_fps()); sf2d_end_frame(); sf2d_swapbuffers(); } sftd_free_font(font); sftd_fini(); sf2d_fini(); return 0; }
int Graphic::startGraphicEnviroment() { if( !sf2d_init() ) return 0x211; if( !sftd_init() ) return 0x212; return 0; }
/** * \brief Inicializa os servicos disponiveis pela camada mult. */ void services_init(void){ CHAT_PORT = 5555; //inicializa o chat com uma porta default. que será alterada de acordo com a def do chat. global_chat_flag = 0; //chat começa desabilitado, só é habilitado pela cli. telnetd_init(); //telnet faz comunicação através da porta 23 httpd_init(); //http faz comunicação através da porta 80. chat_init(); //porta inicial, ela será alterada de acordo com o chat. //ftp_init(); //inicializa serviço de ftp sftd_init(); }
void load_gfx_lib(lua_State *L) { if (!isGfxInitialized) { sf2d_init(); sftd_init(); } isGfxInitialized = true; luaL_requiref(L, "ctr.gfx", luaopen_gfx_lib, 0); }
void init(void) { // Starting services sf2d_init(); sf2d_set_vblank_wait(0); sftd_init(); srvInit(); aptInit(); hidInit(); audio_init(); //romfsInit(); // Configuring the right font to use (8bitoperator), and its proprieties font = sftd_load_font_file("font/eightbit.ttf"); // Configuring graphics in general (images, textures, etc) sf2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF)); /* Load Frisk textures Loop over every element in tex_arr_friskWalk and load the PNG buffer. */ for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { tex_arr_friskWalk[i][j] = loadTexture(friskFilenames[i][j]); } } room_init(); // Reusing 'i' from above. // Load room textures. for (int i = 0; i < 3; ++i) fillTexture(&rooms[i].bg); // TODO: Add actual save loading logic. For now, just assume this room. player_pos = rooms[room].exits[0].entrance; // Play music home = sound_create(BGM); if (home != NULL) audio_load_ogg("sound/music/house1.ogg", home); else home->status = -1; timerStep(); }
int main(void) { Result ret = 0, error = 0; sf2d_init(); sftd_init(); romfsInit(); srand(osGetTime()); // consoleInit(GFX_TOP, NULL); // TODO: Comment it! // consoleInit(GFX_BOTTOM, NULL); // TODO: Comment it! printf("> Loading texture manager\n"); PHBanku::texture = new TextureManager(); ret = PHBanku::texture->load(); if (R_FAILED(ret)) { // Graphics error |= ERR_GRAPHICS; } printf("> Loading font manager\n"); PHBanku::font = new FontManager(); ret = PHBanku::font->load(); if (R_FAILED(ret)) { // Font error |= ERR_FONT; } printf("> Loading data manager\n"); PHBanku::data = new DataManager(); ret = PHBanku::data->load(); if (R_FAILED(ret)) { // Data error |= ERR_DATA; } #ifdef __cia printf("> Starting title selector\n"); while (!error && TS_Loop()) { // Draw the static loading screen again because of ts.h PHBanku::texture->drawStaticLoadingScreen(); printf("> Loading filesystem services\n"); ret = FSCIA_Init(titleEntry.titleid, titleEntry.mediatype); if (R_FAILED(ret)) { // Filesystem error |= ERR_FILESYSTEM; } #else // __3dsx printf("> Loading filesystem services\n"); ret = FS_Init(); if (R_FAILED(ret)) { // Filesystem error |= ERR_FILESYSTEM; } #endif printf("> Loading save manager\n"); PHBanku::save = new SaveManager(); ret = PHBanku::save->load(); if (R_FAILED(ret)) { // Save error |= ERR_SAVE; } if (!error) { printf("> Starting box viewer...\n"); Viewer* viewer = new BoxViewer(); ViewState state = Viewer::startMainLoop(viewer); if (state == ViewState::Saving) { // TODO Remove when better save display! consoleInit(GFX_TOP, NULL); printf("Saving...\n"); // ^ PHBanku::save->save(); } else { // TODO Remove when better exit display! consoleInit(GFX_TOP, NULL); printf("Exiting...\n"); // ^ } delete viewer; } delete PHBanku::save; #ifdef __cia FSCIA_Exit(); consoleExit(GFX_TOP, NULL); break; // TODO Remove! The app crash itself after the 2nd ts, unknown cause. } // while (TS_LOOP()) if (!error) { // TODO Remove when better exit display! consoleInit(GFX_BOTTOM, NULL); // ^ printf("\nThe app execution ended!\n"); printf("Thanks for being awesome!\n"); } #else FS_Exit(); #endif if (error) { // TODO Remove when better error display! consoleInit(GFX_TOP, NULL); // ^ printf("\nProblem happened: 0x%lx\n", error); if (error & ERR_SAVE) printf(" \a Save\n"); if (error & ERR_DATA) printf(" \a Data\n"); if (error & ERR_FONT) printf(" \a Font\n"); if (error & ERR_GRAPHICS) printf(" \a Graphics\n"); if (error & ERR_FILESYSTEM) printf(" \a Filesystem\n"); printf("PHBank version: %08x\n", VERSION); printf("Can't start the viewer.\n"); printf("Press any key to exit\n"); waitKey(KEY_ANY); } delete PHBanku::data; delete PHBanku::font; delete PHBanku::texture; romfsExit(); sftd_fini(); sf2d_fini(); return 0; }
int main() { touchPosition touch; sf2d_init(); sftd_init(); sftd_font *text = sftd_load_font_mem(Roboto_ttf, Roboto_ttf_size); sftd_font *title = sftd_load_font_mem(RobotoThin_ttf, RobotoThin_ttf_size); sf2d_texture *logo = sfil_load_PNG_buffer(logo_png, SF2D_PLACE_RAM); sf2d_texture *record = sfil_load_PNG_buffer(record_png, SF2D_PLACE_RAM); sf2d_texture *stop = sfil_load_PNG_buffer(stop_png, SF2D_PLACE_RAM); sf2d_set_clear_color(RGBA8(0xFA, 0xFA, 0xFA, 0xFF)); sharedmem = (u32*)memalign(0x1000, sharedmem_size); audiobuf = linearAlloc(audiobuf_size); MIC_Initialize(sharedmem, sharedmem_size, control, 0, 3, 1, 1);//See mic.h. // Threading stuff svcCreateEvent(&threadRequest,0); u32 *threadStack = memalign(32, STACKSIZE); svcCreateThread(&threadHandle, threadMic, 0, &threadStack[STACKSIZE/4], 0x3f, 0); while(aptMainLoop()) { hidScanInput(); hidTouchRead(&touch); u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_texture(logo, 60, 70); sftd_draw_text(title, 177, 80, RGBA8(0, 0, 0, 222), 40, "Audio"); sftd_draw_text(title, 175, 120, RGBA8(0, 0, 0, 222), 40, "Recorder"); sf2d_end_frame(); sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); sf2d_draw_texture(record, 85, 85); sf2d_draw_texture(stop, 165, 85); sf2d_end_frame(); svcSignalEvent(threadRequest); if(print == 1) { sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_texture(logo, 60, 70); sftd_draw_text(title, 177, 80, RGBA8(0, 0, 0, 222), 40, "Audio"); sftd_draw_text(title, 175, 120, RGBA8(0, 0, 0, 222), 40, "Recorder"); sftd_draw_text(text, 130, 209, RGBA8(0, 0, 0, 222), 16, "Recording audio..."); sf2d_end_frame(); } if(recording == 2) { sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_texture(logo, 60, 70); sftd_draw_text(title, 177, 80, RGBA8(0, 0, 0, 222), 40, "Audio"); sftd_draw_text(title, 175, 120, RGBA8(0, 0, 0, 222), 40, "Recorder"); sftd_draw_text(text, 130, 209, RGBA8(0, 0, 0, 222), 16, "Saving audio..."); sf2d_end_frame(); } sf2d_swapbuffers(); } MIC_Shutdown(); sftd_free_font(text); sftd_free_font(title); sf2d_free_texture(logo); sf2d_free_texture(record); sf2d_free_texture(stop); // tell thread to exit threadExit = true; // signal the thread svcSignalEvent(threadRequest); // give it time to exit svcSleepThread(10000000ULL); // close handles and free allocated stack svcCloseHandle(threadRequest); svcCloseHandle(threadHandle); free(threadStack); free(sharedmem); linearFree(audiobuf); linearFree(nomute_audiobuf); sf2d_fini(); sftd_fini(); return 0; }
int main() { char* names[] = { "nul/20", "item1", "second item", "the third one", "item4", "item5", "item6", "item7", "item8", "item9", "item10", "item11", "item12", "item13", "item14", "item15", "item16", "item17", "item18", "item19", "item20", "item21", "item22", "item23", "item24", "item25", "item26", "item27", "item28", "item29" }; int nbitems = 30; uint8_t owneditem[nbitems]; for (int i=0; i<nbitems; i++) owneditem[i] = 0; sf2d_init(); sf2d_set_clear_color(RGBA8(255, 255, 255, 255)); sf2d_set_vblank_wait(0); // Font loading sftd_init(); sftd_font* font = sftd_load_font_mem(FreeSans_ttf, FreeSans_ttf_size); int fontSize = 20; int row = 0; int nbrow = 10; int firstrow = 0; #define LONG_TIMEOUT 500 #define SHORT_TIMEOUT_MAX 100 #define SHORT_TIMEOUT_MIN 20 u64 oldTime = osGetTime(); u64 timer = 0; u64 timeout = LONG_TIMEOUT; while (aptMainLoop()) { hidScanInput(); if (hidKeysDown() & KEY_START) break; if ((hidKeysHeld() & KEY_UP) && timer == 0) row--; if (row == -1) { row++; firstrow--; if (firstrow == -1) { row = nbrow-1; firstrow = nbitems-nbrow; } } if ((hidKeysHeld() & KEY_DOWN) && timer == 0) row++; if (row == nbrow) { row--; firstrow++; if (firstrow+nbrow == nbitems+1) { firstrow = 0; row = 0; } } int index = firstrow+row; owneditem[index] += 100; if (hidKeysDown() & KEY_LEFT) owneditem[index]--; if (hidKeysDown() & KEY_RIGHT) owneditem[index]++; owneditem[index] %= 100; // use osGetTime to have key repetition u64 newTime = osGetTime(); u64 delay = newTime-oldTime; oldTime = newTime; if (hidKeysHeld()) { timer += delay; if (timer>timeout) { timer = 0; if (timeout == LONG_TIMEOUT) { timeout = SHORT_TIMEOUT_MAX; } else { timeout = umax(timeout-2, SHORT_TIMEOUT_MIN); } } } else { timer = 0; timeout = LONG_TIMEOUT; } sf2d_start_frame(GFX_TOP, GFX_LEFT); { for (int i=0; i<nbrow; i++) { unsigned int color = RGBA8(0, 0, 0, 255); if (i == row) { sf2d_draw_rectangle(0, i*fontSize, 400, fontSize, RGBA8(0, 0, 0, 255)); color = RGBA8(255, 255, 255, 255); } sftd_draw_textf(font, 010, i*fontSize, color, fontSize, names[firstrow+i]); sftd_draw_textf(font, 210, i*fontSize, color, fontSize, "%i", owneditem[firstrow+i]); } } sf2d_end_frame(); sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); { sftd_draw_textf(font, 0, 20, RGBA8(0, 255, 0, 255), 20, "Press START to exit"); sftd_draw_textf(font, 0, 40, RGBA8(0, 255, 0, 255), 20, "Timeout: %i", timeout); } sf2d_end_frame(); sf2d_swapbuffers(); } sftd_free_font(font); sftd_fini(); sf2d_fini(); return 0; }
int main() { L = luaL_newstate(); luaL_openlibs(L); luaL_requiref(L, "love", initLove, 1); sf2d_init(); // 2D Drawing lib. sftd_init(); // Text Drawing lib. cfguInit(); ptmuInit(); // consoleInit(GFX_BOTTOM, NULL); sf2d_set_clear_color(RGBA8(0x0, 0x0, 0x0, 0xFF)); // Reset background color. osSetSpeedupEnable(true); // Enables CPU speedup for a free performance boost. // Detect if we are running on a .cia, because if we are // we load from RomFS rather than the SD Card. // TODO: Load RomFS from .3dsx's aswell. Result rc = romfsInit(); romfsExists = (rc) ? false : true; // Change working directory if (romfsExists) { chdir("romfs:/"); } else { char cwd[256]; getcwd(cwd, 256); char newCwd[261]; strcat(newCwd, cwd); strcat(newCwd, "game"); chdir(newCwd); } luaL_dobuffer(L, boot_lua, boot_lua_size, "boot"); // Do some setup Lua side. // If main.lua exists, execute it. // If not then just load the nogame screen. if (fileExists("main.lua")) { if (luaL_dofile(L, "main.lua")) displayError(); } else { if (luaL_dobuffer(L, nogame_lua, nogame_lua_size, "nogame")) displayError(); } if (luaL_dostring(L, "love.timer.step()")) displayError(); if (luaL_dostring(L, "if love.load then love.load() end")) displayError(); while (aptMainLoop()) { if (shouldQuit) { if (forceQuit) break; bool shouldAbort = false; // lua_getfield(L, LUA_GLOBALSINDEX, "love"); // lua_getfield(L, -1, "quit"); // lua_remove(L, -2); // if (!lua_isnil(L, -1)) { // lua_call(L, 0, 1); // shouldAbort = lua_toboolean(L, 1); // lua_pop(L, 1); // }; TODO: Do this properly. if (luaL_dostring(L, "if love.quit then love.quit() end")) displayError(); if (!shouldAbort && !errorOccured) break; } // Quit event if (!errorOccured) { if (luaL_dostring(L, "love.keyboard.scan()\n" "love.timer.step()\n" "if love.update then love.update(love.timer.getDelta()) end")) { displayError(); } // Top screen // Left side sf2d_start_frame(GFX_TOP, GFX_LEFT); if (luaL_dostring(L, "if love.draw then love.draw() end")) displayError(); sf2d_end_frame(); // Right side if (is3D) { sf2d_start_frame(GFX_TOP, GFX_RIGHT); if (luaL_dostring(L, "if love.draw then love.draw() end")) displayError(); sf2d_end_frame(); } // Bot screen sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); if (luaL_dostring(L, "if love.draw then love.draw() end")) displayError(); sf2d_end_frame(); luaL_dostring(L, "love.graphics.present()"); } else { hidScanInput(); u32 kTempDown = hidKeysDown(); if (kTempDown & KEY_START) { forceQuit = true; shouldQuit = true; } char *errMsg = lua_tostring(L, -1); sf2d_start_frame(GFX_TOP, GFX_LEFT); lua_getfield(L, LUA_GLOBALSINDEX, "love"); lua_getfield(L, -1, "errhand"); lua_remove(L, -2); if (!lua_isnil(L, -1)) { lua_pushstring(L, errMsg); lua_call(L, 1, 0); } sf2d_end_frame(); sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); lua_getfield(L, LUA_GLOBALSINDEX, "love"); lua_getfield(L, -1, "errhand"); lua_remove(L, -2); if (!lua_isnil(L, -1)) { lua_pushstring(L, errMsg); lua_call(L, 1, 0); } sf2d_end_frame(); luaL_dostring(L, "love.graphics.present()"); } } luaL_dostring(L, "love.audio.stop()"); lua_close(L); sftd_fini(); sf2d_fini(); cfguExit(); ptmuExit(); if (soundEnabled) ndspExit(); if (romfsExists) romfsExit(); return 0; }