/** * * @return */ static bool initDrivers() { listOfSDLDrivers.clear(); int nbDriver=SDL_GetNumRenderDrivers(); for(int i=0;i<nbDriver;i++) { SDL_RendererInfo info; SDL_GetRenderDriverInfo(i,&info); sdlDriverInfo sdlInfo; sdlInfo.index=i; if(info.name) sdlInfo.driverName=std::string(info.name); else sdlInfo.driverName=std::string("Invalid driver"); sdlInfo.flags=info.flags; listOfSDLDrivers.push_back(sdlInfo); printf("[SDK]Found driver [%d] %s, with flags=%x\n",i,sdlInfo.driverName.c_str(),info.flags); if(info.flags & SDL_RENDERER_SOFTWARE) // by default we peek the software one sdlSoftwareDriverIndex=i; } sdlDriverIndex=sdlSoftwareDriverIndex; SDL_LogSetOutputFunction(SDL_Logger,NULL); return true; }
static SDL_VideoDevice *NDS_CreateDevice(int devindex) { SDL_VideoDevice *device; fatInitDefault(); /* Initialize all variables that we clean on shutdown */ device = SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { SDL_OutOfMemory(); return NULL; } device->driverdata = SDL_calloc(1, sizeof(SDL_VideoDevice)); if (!device) { SDL_free(device); SDL_OutOfMemory(); return NULL; } /* Set the function pointers */ device->VideoInit = NDS_VideoInit; device->VideoQuit = NDS_VideoQuit; device->GetDisplayModes = NDS_GetDisplayModes; device->SetDisplayMode = NDS_SetDisplayMode; device->CreateWindow = NDS_CreateWindow; #ifndef USE_HW_RENDERER device->CreateWindowFramebuffer = NDS_CreateWindowFramebuffer; device->UpdateWindowFramebuffer = NDS_UpdateWindowFramebuffer; device->DestroyWindowFramebuffer = NDS_DestroyWindowFramebuffer; #endif device->PumpEvents = NDS_PumpEvents; device->free = NDS_DeleteDevice; /* Set the debug output. Use only under an emulator. Will crash the DS. */ #if 0 SDL_LogSetOutputFunction(NDS_DebugOutput, NULL); #endif return device; }
// Static void SDL2Logger::initialize() { if( SDL2Logger::initialized() == false ) { // Mimic the default logging category priorities as per SDL2 logging // categories SDL2Logger::set_logging_priority( NOM_LOG_CATEGORY_APPLICATION, LogPriority::NOM_LOG_PRIORITY_INFO ); SDL2Logger::set_logging_priority( NOM_LOG_CATEGORY_ASSERT, LogPriority::NOM_LOG_PRIORITY_WARN ); SDL2Logger::set_logging_priority( NOM_LOG_CATEGORY_TEST, LogPriority::NOM_LOG_PRIORITY_VERBOSE ); #if defined( NOM_DEBUG ) SDL2Logger::set_logging_priority( NOM_LOG_CATEGORY_RENDER, LogPriority::NOM_LOG_PRIORITY_WARN ); #endif // Log all messages from the engine's default NOM category SDL2Logger::set_logging_priority( NOM, LogPriority::NOM_LOG_PRIORITY_VERBOSE ); // Register custom log output function for optional colored message support void ( *log_output_function )( void*, int, SDL_LogPriority, const char* ) = priv::log_message; SDL_LogSetOutputFunction( log_output_function, nullptr ); SDL2Logger::initialized_ = true; } }
void log_init(void) { #if _WIN32 SDL_LogSetOutputFunction(console_output, NULL); #endif }
bool CApp::OnInit() { if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { return false; } if (IMG_Init(IMG_INIT_PNG) == 0) { return false; } SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN); SDL_LogGetOutputFunction(&logfunc, NULL); SDL_LogSetOutputFunction(myLog, NULL); SDL_CreateWindowAndRenderer(SCREEN_W, SCREEN_H, 0, &Window, &Renderer); if (!Window || !Renderer) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "CreateWindowAndRenderer: %s", SDL_GetError()); return false; } SDL_SetWindowTitle(Window, TITLE); Surf_Display = SDL_CreateRGBSurface(0, SCREEN_W, SCREEN_H, BPP, RMASK, GMASK, BMASK, AMASK); if (!Surf_Display) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "CreateRGBSurface: %s", SDL_GetError()); return false; } SDL_FillRect(Surf_Display, NULL, 0); Texture = SDL_CreateTexture(Renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, SCREEN_W, SCREEN_H); if (!Texture) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "CreateTexture: %s", SDL_GetError()); return false; } CEventFilter::SetDefaults(); // or use your own filters CEventFilter::TurnFilterOn(&InputHappened); // PROGRAM SPECIFIC CODE HERE bg = SDL_CreateRGBSurface(0, SCREEN_W, SCREEN_H, BPP, RMASK, GMASK, BMASK, AMASK); if (!bg) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "CSurface::OnLoad: %s", SDL_GetError()); return false; } SDL_FillRect(bg, NULL, 0xfff0f0f0); VerticalSpriteSheet* dude = new VerticalSpriteSheet("gfx/char.png", 1, Surf_Display->format); ActionJackson.SetSpriteSheet(dude); ActionJackson.AnimState = 0; CEntity::EntityList.push_back(&ActionJackson); SDL_SetWindowIcon(Window, dude->sheet); tiles = new TiledSpriteSheet("gfx/tiles.png", 2, 2, Surf_Display->format); block = new VerticalSpriteSheet("gfx/block.png", 1, Surf_Display->format); if (!LoadMaps("maps/sokoban.map", tiles)) return false; std::ifstream fin("save"); if (fin) { fin >> CurrentMap; fin.ignore(1, '\n'); fin >> highestLevel; } fin.close(); ResetMap(CurrentMap); return true; }
int main(int argc, char *argv[]) { #ifdef MSVC_DEBUG_HEAP // Get current flag int tmpFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); tmpFlag |= _CRTDBG_ALLOC_MEM_DF; tmpFlag |= _CRTDBG_LEAK_CHECK_DF; // Set flag to the new value. _CrtSetDbgFlag(tmpFlag); #endif #ifdef WIN32 // When on windows, do some workarounds so our console window // behaves properly. // put the program name into argv[0] char filename[_MAX_PATH]; GetModuleFileNameA(NULL, filename, _MAX_PATH); argv[0] = filename; bool fromRuby = false; for (int i = 1; i < argc; i++) { if (!stricmp(argv[i], "ProcessID") && i + 1 < argc) { fromRuby = true; char *pEnd; long int pid = strtol (argv[i + 1], &pEnd, 10); LS::Process::rubyProcessId = pid; memmove(argv + i, argv + i + 2, (argc - i - 2)*sizeof(char*)); argc -= 2; i--; break; } } LS::Process::consoleAttached = false; if (!fromRuby && AttachConsole(ATTACH_PARENT_PROCESS)) { HANDLE consoleHandleOut = GetStdHandle(STD_OUTPUT_HANDLE); int fdOut = _open_osfhandle((intptr_t)consoleHandleOut, _O_TEXT); FILE *fpOut = _fdopen(fdOut, "w"); *stdout = *fpOut; setvbuf(stdout, NULL, _IONBF, 0); //redirect unbuffered STDERR to the console HANDLE consoleHandleError = GetStdHandle(STD_ERROR_HANDLE); int fdError = _open_osfhandle((intptr_t)consoleHandleError, _O_TEXT); FILE *fpError = _fdopen(fdError, "w"); *stderr = *fpError; setvbuf(stderr, NULL, _IONBF, 0); LS::Process::consoleAttached = true; } #endif // Initialize logging. loom_log_initialize(); LSLuaState::initCommandLine(argc, (const char**) argv); /* Enable standard application logging */ SDL_LogSetAllPriority(SDL_LOG_PRIORITY_INFO); SDL_LogSetOutputFunction(sdlLogOutput, NULL); SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS ); int ret; #if LOOM_RENDERER_OPENGLES2 ret = SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); lmAssert(ret == 0, "SDL Error: %s", SDL_GetError()); ret = SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); lmAssert(ret == 0, "SDL Error: %s", SDL_GetError()); #endif int stencilSize = 1; ret = SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencilSize); lmAssert(ret == 0, "SDL Error: %s", SDL_GetError()); // Set up SDL window. if ((gSDLWindow = SDL_CreateWindow( "Loom", 0, 0, 100, 100, SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN #if LOOM_PLATFORM == LOOM_PLATFORM_IOS | SDL_WINDOW_BORDERLESS #endif | SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI)) == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateWindow(): %s\n", SDL_GetError()); exit(0); } gContext = SDL_GL_CreateContext(gSDLWindow); if (!gContext) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); exit(2); } ret = SDL_GL_SetSwapInterval(-1); if (ret != 0) { lmLog(coreLogGroup, "Late swap tearing not supported, using vsync"); SDL_GL_SetSwapInterval(1); } // And show the window with proper settings. SDL_SetWindowPosition(gSDLWindow, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); SDL_StopTextInput(); // Initialize Loom! loom_appSetup(); supplyEmbeddedAssets(); /* Main render loop */ gLoomExecutionDone = 0; /* Display SDL version */ SDL_version compiled; SDL_version linked; SDL_VERSION(&compiled); SDL_GetVersion(&linked); lmLogDebug(coreLogGroup, "Compiled with SDL version %d.%d.%d and linking against SDL version %d.%d.%d ...", compiled.major, compiled.minor, compiled.patch, linked.major, linked.minor, linked.patch); /* Game Controller */ // Enable controller events SDL_GameControllerEventState(SDL_ENABLE); //Open all connected game controllers LoomGameController::openAll(); #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(loop, 0, 1); #else while (!gLoomExecutionDone) loop(); #endif //Close all opened game controllers before closing application LoomGameController::closeAll(); loom_appShutdown(); #ifdef WIN32 LS::Process::cleanupConsole(); #endif exit(0); return 0; /* to prevent compiler warning */ }
int initEverything( void ) { #ifndef _DEBUG logFile = SDL_RWFromFile( "log.txt", "w" ); if( logFile != NULL ) { SDL_LogSetOutputFunction( LogOutput, NULL ); } #endif // memory first, won't be used everywhere at first so lets keep the initial allocation low, 64 MB mem_Init( 64 * 1024 * 1024 ); /* then SDL */ SDL_SetMainReady( ); if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS ) != 0 ) { SDL_LogError( SDL_LOG_CATEGORY_APPLICATION, SDL_GetError( ) ); return -1; } SDL_LogInfo( SDL_LOG_CATEGORY_APPLICATION, "SDL successfully initialized" ); atexit( cleanUp ); // set up opengl // try opening and parsing the config file int majorVersion; int minorVersion; int redSize; int greenSize; int blueSize; int depthSize; void* oglCFGFile = cfg_OpenFile( "opengl.cfg" ); cfg_GetInt( oglCFGFile, "MAJOR", 3, &majorVersion ); cfg_GetInt( oglCFGFile, "MINOR", 3, &minorVersion ); cfg_GetInt( oglCFGFile, "RED_SIZE", 8, &redSize ); cfg_GetInt( oglCFGFile, "GREEN_SIZE", 8, &greenSize ); cfg_GetInt( oglCFGFile, "BLUE_SIZE", 8, &blueSize ); cfg_GetInt( oglCFGFile, "DEPTH_SIZE", 16, &depthSize ); cfg_CloseFile( oglCFGFile ); majorVersion = 2; minorVersion = 1; // want the core functionality SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, majorVersion ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, minorVersion ); // want 8 bits minimum per color SDL_GL_SetAttribute( SDL_GL_RED_SIZE, redSize ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, greenSize ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, blueSize ); // want 16 bit depth buffer SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, depthSize ); // want it to be double buffered SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); window = SDL_CreateWindow( windowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL ); if( window == NULL ) { SDL_LogError( SDL_LOG_CATEGORY_VIDEO, SDL_GetError( ) ); return -1; } SDL_LogInfo( SDL_LOG_CATEGORY_APPLICATION, "SDL OpenGL window successfully created" ); /* Load and create images */ if( gfx_Init( window ) < 0 ) { return -1; } SDL_LogInfo( SDL_LOG_CATEGORY_APPLICATION, "Rendering successfully initialized" ); /* Load and create sounds and music */ if( initMixer( ) < 0 ) { return -1; } SDL_LogInfo( SDL_LOG_CATEGORY_APPLICATION, "Mixer successfully initialized" ); cam_Init( ); cam_SetProjectionMatrices( window ); SDL_LogInfo( SDL_LOG_CATEGORY_APPLICATION, "Cameras successfully initialized" ); loadAllResources( ); return 0; }