Exemple #1
0
int
main(int argc, char *argv[])
{
    SDL_version compiled;
    SDL_version linked;

	/* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

#if SDL_VERSION_ATLEAST(2, 0, 0)
    SDL_Log("Compiled with SDL 2.0 or newer\n");
#else
    SDL_Log("Compiled with SDL older than 2.0\n");
#endif
    SDL_VERSION(&compiled);
    SDL_Log("Compiled version: %d.%d.%d.%d (%s)\n",
           compiled.major, compiled.minor, compiled.patch,
           SDL_REVISION_NUMBER, SDL_REVISION);
    SDL_GetVersion(&linked);
    SDL_Log("Linked version: %d.%d.%d.%d (%s)\n",
           linked.major, linked.minor, linked.patch,
           SDL_GetRevisionNumber(), SDL_GetRevision());
    SDL_Quit();
    return (0);
}
Exemple #2
0
/**
 * @brief Main entry point.
 */
int main( int argc, char *argv[] )
{
   int failed;
   int rev;
   SDL_version ver;

   /* Get options. */
   parse_options( argc, argv );

   /* Defaults. */
   failed = 0;

   /* Print some text if verbose. */
   SDL_GetVersion( &ver );
   rev = SDL_GetRevision();
   SDL_ATprintVerbose( 1, "Running tests with SDL %d.%d.%d revision %d\n",
         ver.major, ver.minor, ver.patch, rev );

   /* Automatic tests. */
   if (run_platform)
      failed += test_platform();
   if (run_rwops)
      failed += test_rwops();
   if (run_rect)
      failed += test_rect();
   if (run_surface)
      failed += test_surface();
   if (run_render)
      failed += test_render();
   if (run_audio)
      failed += test_audio();

   /* Manual tests. */
   if (run_manual) {
   }

   /* Display more information if failed. */
   if (failed > 0) {
      SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n",
            ver.major, ver.minor, ver.patch, rev );
      SDL_ATprintErr( "System is running %s and is %s endian\n",
            SDL_GetPlatform(),
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
            "little"
#else
            "big"
#endif
            );
   }

   return failed;
}
Exemple #3
0
jstring Java_org_libsdl_app_SDLActivity_stringFromJNI( JNIEnv* env, jobject thiz)
{
	SDL_version linked;
	unsigned ver = avutil_version();
	char buf[512] = "", *ptr = buf;
	ptr += sprintf(ptr, "avutil %d.%d.%d ", ver>>16, (ver>>8)&0xff, ver&0xff); 

	SDL_GetVersion(&linked);
    ptr += sprintf(ptr, "sdl: %d.%d.%d.%d (%s)",
           linked.major, linked.minor, linked.patch,
           SDL_GetRevisionNumber(), SDL_GetRevision());

    return (*env)->NewStringUTF(env, buf);
}
Exemple #4
0
void MainManager::initSDL()
{
  log_.i("Initializing SDL");
  if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
    throw log_.exception("Failed to initialize SDL", SDL_GetError);
  atexit(SDL_Quit);

  // Write version information to log
  SDL_version compiled;
  SDL_version linked;
  SDL_VERSION(&compiled);
  SDL_GetVersion(&linked);
  logSDLVersion("SDL", compiled, linked, SDL_GetRevision());
}
int
main(int argc, char *argv[])
{
    SDL_version compiled;
    SDL_version linked;

#if SDL_VERSION_ATLEAST(1, 3, 0)
    printf("Compiled with SDL 1.3 or newer\n");
#else
    printf("Compiled with SDL older than 1.3\n");
#endif
    SDL_VERSION(&compiled);
    printf("Compiled version: %d.%d.%d.%d (%s)\n",
           compiled.major, compiled.minor, compiled.patch,
           SDL_REVISION_NUMBER, SDL_REVISION);
    SDL_GetVersion(&linked);
    printf("Linked version: %d.%d.%d.%d (%s)\n",
           linked.major, linked.minor, linked.patch,
           SDL_GetRevisionNumber(), SDL_GetRevision());
    SDL_Quit();
    return (0);
}
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;
}
Exemple #7
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);
}
void KPSdl2UserInterface::OpenWindow(int /* argc */ , char ** /* argv */)
{
    auto flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
    SDL_version compiled;
    SDL_version linked;
    std::stringstream message;

    SDL_VERSION(&compiled);
    SDL_GetVersion(&linked);

    BLogger::Log("SDL UserInterface initialization");
    BLogger::Log("SDL linked version: ",
                 static_cast<unsigned int>(linked.major), '.',
                 static_cast<unsigned int>(linked.minor), '.',
                 static_cast<unsigned int>(linked.patch));
    BLogger::Log("SDL compiled version: ",
                 static_cast<unsigned int>(compiled.major), '.',
                 static_cast<unsigned int>(compiled.minor), '.',
                 static_cast<unsigned int>(compiled.patch));
    BLogger::Log("SDL Header version: ",
                 SDL_MAJOR_VERSION, '.', SDL_MINOR_VERSION, '.',
                 SDL_PATCHLEVEL);
    BLogger::Log("SDL Revision: ", SDL_GetRevision());
    auto pVersion = Mix_Linked_Version();
    BLogger::Log("SDL_mixer Linked version: ",
                 static_cast<unsigned int>(pVersion->major), '.',
                 static_cast<unsigned int>(pVersion->minor), '.',
                 static_cast<unsigned int>(pVersion->patch));
    BLogger::Log("SDL_mixer Header version: ",
                 MIX_MAJOR_VERSION, '.', MIX_MINOR_VERSION, '.',
                 MIX_PATCHLEVEL);

    // Set OpenGL's context to 2.1 subset functionality profile.
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);

    // Open OpenGL Window with SDL
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0)
    {
        message << "Error in SDL_Init: " << SDL_GetError();
        SDL_Quit();
        throw std::runtime_error(message.str());
    }

    if (config->FullScreen)
    {
        flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
    }

    if (!IsWindowResolutionSupported(config->ScreenXResolution,
                                     (config->ScreenXResolution * 3) / 4))
    {
        config->ScreenXResolution = 640;
    }

    window = SDL_CreateWindow(
                 GetWindowTitle().c_str(),
                 SDL_WINDOWPOS_UNDEFINED,
                 SDL_WINDOWPOS_UNDEFINED,
                 config->ScreenXResolution,
                 (config->ScreenXResolution * 3) / 4,
                 flags);

    if (window == nullptr)
    {
        message << "Error in SDL_CreateWindow: " << SDL_GetError();
        SDL_Quit();
        throw std::runtime_error(message.str());
    }

    // We intentionally do not use the SDL renderer. It only supports 2D
    // and on Windows would use DirectX and not the OpenGL backend.
    // Instead the OpenGL renderer is used together with ligGLEW.
    glContext = SDL_GL_CreateContext(window);

    if (glContext == nullptr)
    {
        message << "Error in SDL_GL_CreateContext: " << SDL_GetError();
        SDL_Quit();
        throw std::runtime_error(message.str());
    }

    // Do updates synchronized with VSync
    SDL_GL_SetSwapInterval(1);

    auto glewReturn = glewInit();

    if (glewReturn != GLEW_OK)
    {
        message << "Error in glewInit: " << glewGetErrorString(glewReturn);
        SDL_Quit();
        throw std::runtime_error(message.str());
    }

    BLogger::Log("GLEW version: ", glewGetString(GLEW_VERSION));

    SDL_DisplayMode mode;

    SDL_GetWindowDisplayMode(window, &mode);
    BLogger::Log("SDL pixel format: ", SDL_GetPixelFormatName(mode.format));
    BLogger::Log("SDL refresh rate: ", mode.refresh_rate, " Hz");

    DebugPrintOpenGLVersion();
    DebugPrintOpenGLContextVersion();
    InitializeAudio(config->TextureName);
    InitializeAfterOpen();
}
Exemple #9
0
int config_init ( int argc, char **argv )
{
	const char *config_name = DEFAULT_CONFIG_FILE;	// name of the used config file, can be overwritten via CLI
	const struct configOption_st *opt;
	const char *exe = argv[0];
	int default_config = 1;
	int testparsing = 0;
	argc--; argv++;
#ifdef __EMSCRIPTEN__
	exe = strdup("/files/emscripten-virtual-executable");
#endif
#ifdef _WIN32
	console_open_window();
#endif
	SDL_VERSION(&sdlver_compiled);
	SDL_GetVersion(&sdlver_linked);
	if (sdlver_linked.major < 2 || (sdlver_linked.minor == 0 && sdlver_linked.patch < 4)) {
		ERROR_WINDOW("Too old SDL library linked, at least version 2.0.4 is required.");
		return 1;
	}
	/* SDL info on paths */
	if (get_path_info())
		return 1;
	/* ugly hack: pre-parse comand line to find debug statement (to be worse, it does not handle single argument options too well ... */
#ifdef DISABLE_DEBUG
	printf("DEBUG: disabled at compilation time." NL);
#else
	while (testparsing < argc) {
		if (!strcmp(argv[testparsing], "-" DEBUGFILE_OPT) && testparsing != argc - 1 && strcmp(argv[testparsing + 1], "none")) {
			debug_fp = fopen(argv[testparsing + 1], "w");
			DEBUGPRINT("DEBUG: enable logging into file: %s" NL, argv[testparsing + 1]);
			if (debug_fp == NULL)
				fprintf(stderr, "Cannot open debug logging file: %s" NL, argv[testparsing + 1]);
			break;
		}
		testparsing++;
	}
	testparsing = 0;
#endif
	/* end of ugly hack */
	/* let's continue with the info block ... */
	DEBUGPRINT("%s %s v%s %s %s" NL
		"GIT %s compiled by (%s) at (%s) with (%s)-(%s)" NL
		"Platform: (%s) (%d-bit), video: (%s), audio: (%s), "
		"SDL version compiled: (%d.%d.%d) and linked: (%d.%d.%d) rev (%s)" NL NL,
		WINDOW_TITLE, DESCRIPTION, VERSION, COPYRIGHT, PROJECT_PAGE,
		XEMU_BUILDINFO_GIT, XEMU_BUILDINFO_ON, XEMU_BUILDINFO_AT, CC_TYPE, XEMU_BUILDINFO_CC,
		SDL_GetPlatform(), ARCH_BITS, SDL_GetCurrentVideoDriver(), SDL_GetCurrentAudioDriver(),
		sdlver_compiled.major, sdlver_compiled.minor, sdlver_compiled.patch,
		sdlver_linked.major, sdlver_linked.minor, sdlver_linked.patch, SDL_GetRevision()
	);
	DEBUGPRINT("PATH: executable: %s" NL, exe);
	/* SDL path info block printout */
	DEBUGPRINT("PATH: SDL base path: %s" NL, app_base_path);
	DEBUGPRINT("PATH: SDL pref path: %s" NL, app_pref_path);
#ifndef _WIN32
	DEBUGPRINT("PATH: data directory: %s/" NL, DATADIR);
#endif
	DEBUGPRINT("PATH: Current directory: %s" NL NL, current_directory);
	/* Look the very basic command line switches first */
	if (argc && is_help_request_option(argv[0])) {
		opt = configOptions;
		printf("USAGE:" NL NL
			"\t%s -optname optval -optname2 optval2 ..." NL NL "OPTIONS:" NL NL
			"-config" NL "\tUse config file (or do not use the default one, if \"none\" is specified). This must be the first option if used! [default: @config]" NL,
			exe
		);
		while (opt->name) {
			printf("-%s" NL "\t%s [default: %s]" NL, opt->name, opt->help, opt->defval ? opt->defval : "-");
			opt++;
		}
		printf(NL "%s" NL, disclaimer);
#ifdef _WIN32
		if (!console_is_open)
			ERROR_WINDOW("Could not dump help, since console couldn't be allocated.");
#endif
		XEMUEXIT(0);
	}
	DEBUGPRINT("%s" NL NL, disclaimer);
	if (argc && !strcasecmp(argv[0], "-testparsing")) {
		testparsing = 1;
		argc--; argv++;
	}
	if (argc & 1) {
		fprintf(stderr, "FATAL: Bad command line: should be even number of parameters (two for an option as key and its value)" NL);
		return 1;
	}
	if (argc > 1 && !strcmp(argv[0], "-config")) {
		default_config = 0;
		config_name = argv[1];
		argc -= 2;
		argv += 2;
	}
	/* Set default (built-in) values */
	opt = configOptions;
	while (opt->name) {
		if (opt->defval)
			config_set_internal(opt->name, -1, opt->defval);
		opt++;
	}
	config_set_internal("rom", 0, COMBINED_ROM_FN);	// set default "combined" ROM image set (from segment 0, starting with EXOS)
	/* Default values for the keyboard follows ... */
	keymap_preinit_config_internal();
	/* check if we have written sample config file, if there is not, let's create one */
	save_sample_config(DEFAULT_CONFIG_SAMPLE_FILE);
	/* now parse config file (not the sample one!) if there is any */
	if (strcasecmp(config_name, "none")) {
		char path[PATH_MAX + 1];
		FILE *f = open_emu_file(config_name, "r", path);
		DEBUGPRINT("CONFIG: config file: %s (%s)" NL, config_name, f ? path : "*** CANNOT OPEN, NOT USING CONFIG FILE ***");
		if (f) {
			if (load_config_file_stream(f, path)) {
				fclose(f);
				return 1;
			}
			fclose(f);
		} else if (!default_config) {
			fprintf(stderr, "FATAL: Cannot open requested config file: %s" NL, config_name);
			return 1;
		} else
			DEBUGPRINT("CONFIG: Skipping default config file (cannot open), using built-in defaults." NL);
	} else
		DEBUGPRINT("CONFIG: Using config file: DISABLED in command line" NL);
	/* parse command line ... */
	if (parse_command_line(argc, argv))
		return -1;
	/* open debug file, if it was not requested via command line at the beginning ... */
	if (!debug_fp && strcmp(config_getopt_str(DEBUGFILE_OPT), "none")) {
		debug_fp = fopen(config_getopt_str(DEBUGFILE_OPT), "w");
		DEBUGPRINT("DEBUG: enable logging into file: %s" NL, config_getopt_str(DEBUGFILE_OPT));
		if (!debug_fp)
                	ERROR_WINDOW("Cannot open debug messages log file requested: %s", config_getopt_str(DEBUGFILE_OPT));
	}
	if (debug_fp)
		INFO_WINDOW("DEBUG: Debug messages logging is active");
	else
		printf("DEBUG: No debug messages logging is active." NL);
	/* test parsing mode? */
	if (testparsing) {
		printf(NL "--- TEST DUMP OF *PARSED* CONFIGURATION (requested)" NL NL);
		dump_config(stdout);
		printf(NL "--- END OF TEST PARSING MODE (requested)" NL);
		XEMUEXIT(0);
	}
	DEBUG("CONFIG: End of configuration step." NL NL);
	/* Close console, unless user requested it with the -console option */
#ifdef _WIN32
	if (!config_getopt_int("console"))
		console_close_window();
#else
	if (config_getopt_int("console"))
		console_open_window();	// on non-windows, it only will mark console as open for monitor to be used ..
#endif
	return 0;
}
Exemple #10
0
VALUE sdl2r_get_revision(VALUE klass)
{
    const char *result = SDL_GetRevision();
    return SDL2R_TO_UTF8_STRING(result);
}