void kernel_PrintSDLVersions(void) { const SDL_version *v = NULL; SDL_version compiled_V; v = SDL_Linked_Version(); SDL_VERSION(&compiled_V); file_Log(ker_Log(), 1, "(Linked) SDL Version: %u.%u.%u\n", v->major, v->minor, v->patch); file_Log(ker_Log(), 1, "(Compiled) SDL Version: %u.%u.%u\n", compiled_V.major, compiled_V.minor, compiled_V.patch); v = TTF_Linked_Version(); SDL_TTF_VERSION(&compiled_V); file_Log(ker_Log(), 1, "(Linked) SDL TTF Version: %u.%u.%u\n", v->major, v->minor, v->patch); file_Log(ker_Log(), 1, "(Compiled) SDL TTF Version: %u.%u.%u\n", compiled_V.major, compiled_V.minor, compiled_V.patch); file_Log(ker_Log(), 1, "SDL_Init flags (%d) -\n", kernel_Main.SDL_Init_Flags); if(flag_Check(&kernel_Main.SDL_Init_Flags, SDL_INIT_VIDEO) == 1) file_Log(ker_Log(), 1, "\tSDL_INIT_VIDEO\n"); if(flag_Check(&kernel_Main.SDL_Init_Flags, SDL_INIT_AUDIO) == 1) file_Log(ker_Log(), 1, "\tSDL_INIT_AUDIO\n"); if(flag_Check(&kernel_Main.SDL_Init_Flags, SDL_INIT_JOYSTICK) == 1) file_Log(ker_Log(), 1, "\tSDL_INIT_JOYSTICK\n"); return; }
/* rcg06192001 get linked library's version. */ const SDL_version * TTF_Linked_Version(void) { static SDL_version linked_version; SDL_TTF_VERSION(&linked_version); return (&linked_version); }
void MainManager::initSDLttf() { log_.i("Initializing SDL_ttf"); if ( TTF_Init() != 0) throw log_.exception("Failed to initialize SDL_ttf", SDL_GetError); atexit(TTF_Quit); // Write version information to log SDL_version compiled; SDL_TTF_VERSION(&compiled); logSDLVersion("SDL_ttf", compiled, *TTF_Linked_Version()); }
void Renderer::PrintSDL_TTFVersion() { SDL_version compile_version; SDL_TTF_VERSION(&compile_version); const SDL_version *link_version = TTF_Linked_Version(); printf("Compiled with SDL_ttf version: %d.%d.%d\n", compile_version.major, compile_version.minor, compile_version.patch); printf("Running with SDL_ttf version: %d.%d.%d\n", link_version->major, link_version->minor, link_version->patch); }
/*fa MTR_TtfInit yes */ MTR_DCLSPC bool MTR_CALL MTR_TtfInit(uint32_t dmSize, uint32_t reservedCount) { SDL_version compiled; const SDL_version *linked; MTR_LogWrite("Initializing TTF font manager", 0, MTR_LMT_INFO); MTR_LogWrite("Reporting SDL_ttf compile-time version:", 1, MTR_LMT_INFO); SDL_TTF_VERSION(&compiled); MTR_LogWrite_i("Major:", 2, MTR_LMT_INFO, compiled.major); MTR_LogWrite_i("Minor:", 2, MTR_LMT_INFO, compiled.minor); MTR_LogWrite_i("Patch:", 2, MTR_LMT_INFO, compiled.patch); MTR_LogWrite("Reporting SDL_ttf linked version:", 1, MTR_LMT_INFO); linked = TTF_Linked_Version(); MTR_LogWrite_i("Major:", 2, MTR_LMT_INFO, linked->major); MTR_LogWrite_i("Minor:", 2, MTR_LMT_INFO, linked->minor); MTR_LogWrite_i("Patch:", 2, MTR_LMT_INFO, linked->patch); tempSurface = NULL; tempPixels = NULL; if(TTF_Init() != 0) { MTR_LogWrite("Unable to initialize SDL_ttf", 1, MTR_LMT_INFO); return false; } mtrTtfKeeper = (mtrIndexkeeper_t *)MTR_IndexkeeperCreate(dmSize, reservedCount, sizeof(mtrTtf_t)); if (mtrTtfKeeper == NULL) { MTR_Notify("Unable to initialize texture manager", 1, MTR_LMT_ERROR); TTF_Quit(); return false; } else MTR_LogWrite("TTF font manager initialized", 0, MTR_LMT_INFO); mtrTtfInited = true; return true; }
TTF_system::TTF_system() { SDL_version compiled; SDL_TTF_VERSION(&compiled); SDL_version const* linked = TTF_Linked_Version(); log_status(log_scope::ENGINE, log_line_seperator); log_status(log_scope::ENGINE, "Compiled against SDL_ttf version {}.{}.{}", (unsigned)compiled.major, (unsigned)compiled.minor, (unsigned)compiled.patch); log_status(log_scope::ENGINE, "Linked against SDL_ttf version {}.{}.{}", (unsigned)linked->major, (unsigned)linked->minor, (unsigned)linked->patch); log_status(log_scope::ENGINE, log_line_seperator); if(TTF_Init() != 0) { log_error(log_scope::ENGINE, "Error initializing SDL_ttf: {}", TTF_GetError()); SDL_ClearError(); throw fatal_construction_exception{}; } }
int main(int argc, char *argv[]) { (void) argc; (void) argv; if (SDL_Init(SDL_INIT_EVERYTHING) == -1) std::cout << "Failed to initialize SDL" << SDL_GetError() << std::endl; std::cout << "Hello SDL!" << std::endl; // Display SDL version information SDL_version compiled; SDL_version linked; SDL_VERSION(&compiled); SDL_GetVersion(&linked); logSDLVersion(std::cout, "SDL", compiled, linked, SDL_GetRevision()); // Initialize SDL_image and display version information int imgFlags = IMG_INIT_PNG | IMG_INIT_JPG; int imgFlagsInit = IMG_Init(imgFlags); if ((imgFlagsInit & imgFlags) != imgFlags) std::cout << "Failed to initialize SDL_image:" << IMG_GetError() << std::endl; std::cout << "Hello SDL_image!" << std::endl; SDL_IMAGE_VERSION(&compiled); logSDLVersion(std::cout, "SDL_image", compiled, *IMG_Linked_Version(), ""); // Initialize SDL_mixer and display version information int mixFlags = MIX_INIT_OGG; int mixFlagsInit = Mix_Init(mixFlags); if ((mixFlagsInit & mixFlags) != mixFlags) { std::cout << "Failed to initialize SDL_mixer" << Mix_GetError() << std::endl; } if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 1024) == -1) { std::cout << "Failed to acquire sound device" << Mix_GetError() << std::endl; } std::cout << "Hello SDL_mixer!" << std::endl; SDL_MIXER_VERSION(&compiled); logSDLVersion(std::cout, "SDL_mixer", compiled, *Mix_Linked_Version(), ""); logSDLMixerMediaInfo(std::cout); // Initialize SDL_mixer and display version information if (TTF_Init() != 0) std::cout << "Failed to initialize SDL_ttf:" << SDL_GetError() << std::endl; std::cout << "Hello SDL_ttf!" << std::endl; SDL_TTF_VERSION(&compiled); logSDLVersion(std::cout, "SDL_ttf", compiled, *TTF_Linked_Version(), ""); // Create a window and OpenGL glContext using SDL and GLEW SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_Window* window = SDL_CreateWindow("SDL Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); SDL_GLContext glContext = nullptr; const std::pair<int, int> glVersions[11] {{4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, {3, 3}, {3, 2}, {3, 1}, {3, 0}, {2, 1}, {2, 0} }; const std::string glName = "OpenGL"; for (auto& glVersion : glVersions) { std::cout << "Trying to create " << glName << " " << glVersion.first << "." << glVersion.second << " glContext" << std::endl; SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, glVersion.first); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, glVersion.second); glContext = SDL_GL_CreateContext(window); if (glContext != nullptr) break; } if (glContext == nullptr) std::cout << "Failed to create OpenGL Context " << std::endl; bool isOk = SDL_GL_MakeCurrent(window, glContext) <= 0; if (!isOk) std::cout << "Failed to set OpenGL context" << SDL_GetError() << std::endl; glewExperimental = true; if (glewInit() != GLEW_OK) std::cout << "Failed to initialize GLEW" << std::endl; logAcquiredGlVersion(std::cout, glName); logOpenGLContextInfo(std::cout); logGraphicsDriverInfo(std::cout); glClearColor(0.1f, 0.2f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SDL_GL_SwapWindow(window); // Wait for user event before closing bool isRunning = true; SDL_Event event; while (isRunning) { while (SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) isRunning = false; else if (event.type == SDL_QUIT) isRunning = false; } SDL_Delay(30); } // Cleanup SDL_DestroyWindow(window); SDL_GL_DeleteContext(glContext); IMG_Quit(); const int nOpenAudio = Mix_QuerySpec(nullptr, nullptr, nullptr); for (int i = 0 ; i < nOpenAudio ; ++i) Mix_CloseAudio(); while (Mix_Init(0)) Mix_Quit(); TTF_Quit(); SDL_Quit(); return 0; }
bool SDLWrapper::initialize(){ bool successSDL = false; bool successIMG = false; bool successMixer = false; bool successTTF = false; SDL_version compiled; Log(DEBUG) << "Initializing systems..."; // Initializing SDL_TTF. const int ttfInit = TTF_Init(); if(ttfInit == 0){ successTTF = true; SDL_TTF_VERSION(&compiled); SDLWrapper::logSDLVersion("SDL_TTF", compiled); } else{ Log(ERROR) << "Could not initialize TTF." << TTF_GetError(); } // Initializing SDL with initFlags. const Uint32 initFlags = SDL_INIT_EVERYTHING; const int sdlInit = SDL_Init(initFlags); if(sdlInit == 0){ successSDL = true; SDL_version linked; SDL_VERSION(&compiled); SDL_GetVersion(&linked); SDLWrapper::logSDLVersion("SDL", compiled, SDL_GetRevision()); } else{ Log(ERROR) << "Could not initialize SDL." << SDL_GetError(); } // Initializing SDL_image with imgFlags. const Uint32 imgFlags = IMG_INIT_PNG; if((IMG_Init(imgFlags) & imgFlags)){ successIMG = true; SDL_IMAGE_VERSION(&compiled); SDLWrapper::logSDLVersion("SDL_image", compiled); } else{ Log(ERROR) << "Could not initialize SDL_Image." << IMG_GetError(); } // Initializing SDL_mixer. const int frequency = 44100; const int channels = 2; const int chunksize = 4096; const int initialized = Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, channels, chunksize); if(initialized == 0){ successMixer = true; SDL_MIXER_VERSION(&compiled); SDLWrapper::logSDLVersion("SDL_mixer", compiled); } else{ Log(ERROR) << "Could not initialize SDL_Mixer" << Mix_GetError(); } // If even one system fails to initialize, returns false. return (successSDL && successIMG && successMixer && successTTF); }
bool App::Init( bool bFullScreen, unsigned int displayWidth, unsigned int displayHeight ) { if( SDL_Init( SDL_INIT_EVERYTHING ) != 0) { fprintf( stderr, "SDL failed to initialise: %s\n",SDL_GetError() ); return false; } printf( "SDL initialised\n" ); SDL_version compiledVersion; SDL_version linkedVersion; SDL_VERSION( &compiledVersion ); SDL_GetVersion( &linkedVersion ); print_SDL_version( "Compiled against SDL version", compiledVersion ); print_SDL_version( "Linking against SDL version", linkedVersion ); SDL_assert_release( (compiledVersion == linkedVersion) ); int numDisplays = SDL_GetNumVideoDisplays(); printf( "%d video displays\n", numDisplays ); for( int i = 0; i < numDisplays; ++i ) { SDL_DisplayMode displayMode; if( SDL_GetCurrentDisplayMode(i, &displayMode) != 0 ) { fprintf( stderr, "Failed to get display mode for video display %d: %s", i, SDL_GetError() ); continue; } printf( "Display %d: w=%d, h=%d refresh_rate=%d\n", i, displayMode.w, displayMode.h, displayMode.refresh_rate ); } #ifdef GL_ES_VERSION_2_0 SetGLAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SetGLAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SetGLAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); #endif const char* title = "SDL Window"; if( bFullScreen ) { HP_FATAL_ERROR("Just checking"); m_pWindow = SDL_CreateWindow( title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP ); } else { m_pWindow = SDL_CreateWindow( title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, displayWidth, displayHeight, SDL_WINDOW_SHOWN /*| SDL_WINDOW_OPENGL*/ ); } if( !m_pWindow ) { printf( "Failed to create SDL window: %s\n", SDL_GetError() ); return false; } #ifdef GL_ES_VERSION_2_0 // Let's see if we can use OpenGL ES 2 on Raspberry Pi SDL_GLContext gl_context = SDL_GL_CreateContext(m_pWindow); printf("GL_VERSION: "); PrintGLString(GL_VERSION); printf("GL_RENDERER: "); PrintGLString(GL_RENDERER); printf("GL_SHADING_LANGUAGE_VERSION: "); PrintGLString(GL_SHADING_LANGUAGE_VERSION); printf("GL_EXTENSIONS: "); PrintGLString(GL_EXTENSIONS); SDL_GL_DeleteContext(gl_context); #endif // SDL2_ttf if( TTF_Init() == -1 ) { fprintf( stderr, "Failed to initialise SDL2_ttf: %s\n", TTF_GetError() ); return false; } printf( "SDL_ttf initialised\n" ); SDL_TTF_VERSION( &compiledVersion ); const SDL_version *pLinkedVersion = TTF_Linked_Version(); print_SDL_version( "Compiled against SDL_ttf version", compiledVersion ); print_SDL_version( "Linking against SDL_ttf version", *pLinkedVersion ); unsigned int logicalWidth = 1280; unsigned int logicalHeight = 720; m_pRenderer = new Renderer( *m_pWindow, logicalWidth, logicalHeight ); m_pGame = new Game(); if( !m_pGame->Init() ) { fprintf( stderr, "ERROR - Game failed to initialise\n" ); return false; } return true; }
int main(int argc, const char *argv[]) { if(argc != 2) { printf("%s takes .ttf file as argument.\n", argv[0]); return 1; } SDL_version compile_version; const SDL_version *link_version=TTF_Linked_Version(); SDL_TTF_VERSION(&compile_version); printf("compiled with SDL_ttf version: %d.%d.%d\n", compile_version.major, compile_version.minor, compile_version.patch); printf("running with SDL_ttf version: %d.%d.%d\n", link_version->major, link_version->minor, link_version->patch); if(SDL_Init(SDL_INIT_EVERYTHING) != 0) { printf("Error with import!\n"); return 1; } SDL_Window *win = SDL_CreateWindow( "TTF Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN); SDL_Renderer *renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if(TTF_Init() == -1) { printf("Error loading TTF_Init()!\n%s\n", TTF_GetError()); SDL_Quit(); exit(2); } TTF_Font *font; /* MS Himalaya (himalaya.ttf): http://fontzone.net/font-details/microsoft-himalaya */ font = TTF_OpenFont(argv[1], 600); if(!font) { printf("%s\n", TTF_GetError()); return 1; } const char tibstring[] = { 0xe0, 0xbd, 0x96, 0xe0, 0xbd, 0xa6, 0xe0, 0xbe, 0x90, 0xe0, 0xbe, 0xb1, 0xe0, 0xbd, 0xbc, 0xe0, 0xbd, 0x84, 0xe0, 0xbd, 0xa6 }; SDL_Color colour = { 255, 255, 255, 255 }; SDL_Surface *surface = TTF_RenderUTF8_Solid(font, tibstring, colour); if(surface == NULL) { TTF_CloseFont(font); printf("Surface error!\n"); return 0; } SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface); SDL_Event event; int quit = 0; while (!quit) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) quit = 1; } SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); } TTF_CloseFont(font); SDL_Quit(); return 0; }
// Initialise SDL_ttf. void I_StartupTTF(UINT32 fontpointsize, Uint32 initflags, Uint32 vidmodeflags) { char *fontpath = NULL; INT32 fontstatus = -1; res.width = 320; res.height = 200; bitsperpixel = 8; // what's the point of trying to display an error? // SDL_ttf is not started, can't display anything to screen (presumably)... if (SDL_InitSubSystem(initflags) < 0) I_Error("Couldn't initialize SDL: %s\n", SDL_GetError()); TTFSurface = SDL_SetVideoMode(res.width, res.height, bitsperpixel, vidmodeflags); if (!TTFSurface) I_Error("Couldn't set SDL Video resolution: %s\n", SDL_GetError()); if (TTF_Init() < 0) I_Error("Couldn't start SDL_ttf: %s\n", TTF_GetError()); // look for default font in many directories #ifdef FONTSEARCHPATH1 fontpath = searchFont(FONTSEARCHPATH1); if (fontpath) fontstatus = I_TTFLoadFont(fontpath, fontpointsize); #endif #ifdef FONTSEARCHPATH2 if (fontstatus < 0) { fontpath = searchFont(FONTSEARCHPATH2); if (fontpath) fontstatus = I_TTFLoadFont(fontpath, fontpointsize); } #endif #ifdef FONTSEARCHPATH3 if (fontstatus < 0) { fontpath = searchFont(FONTSEARCHPATH3); if (fontpath) fontstatus = I_TTFLoadFont(fontpath, fontpointsize); } #endif #ifdef FONTSEARCHPATH4 if (fontstatus < 0) { fontpath = searchFont(FONTSEARCHPATH4); if (fontpath) fontstatus = I_TTFLoadFont(fontpath, fontpointsize); } #endif #ifdef FONTSEARCHPATH5 if (fontstatus < 0) { fontpath = searchFont(FONTSEARCHPATH5); if (fontpath) fontstatus = I_TTFLoadFont(fontpath, fontpointsize); } #endif #ifdef FONTSEARCHPATH6 if (fontstatus < 0) { fontpath = searchFont(FONTSEARCHPATH6); if (fontpath) fontstatus = I_TTFLoadFont(fontpath, fontpointsize); } #endif #ifdef FONTSEARCHPATH7 if (fontstatus < 0) { fontpath = searchFont(FONTSEARCHPATH7); if (fontpath) fontstatus = I_TTFLoadFont(fontpath, fontpointsize); } #endif // argh! no font file found! disable SDL_ttf code if (fontstatus < 0) { I_ShutdownTTF(); CONS_Printf("Unable to find default font files! Not loading SDL_ttf\n"); } else { // Get SDL_ttf compiled and linked version SDL_version TTFcompiled; const SDL_version *TTFlinked; SDL_TTF_VERSION(&TTFcompiled); TTFlinked = TTF_Linked_Version(); // Display it on screen CONS_Printf("Compiled for SDL_ttf version: %d.%d.%d\n", TTFcompiled.major, TTFcompiled.minor, TTFcompiled.patch); CONS_Printf("Linked with SDL_ttf version: %d.%d.%d\n", TTFlinked->major, TTFlinked->minor, TTFlinked->patch); } }