コード例 #1
0
ファイル: main.cpp プロジェクト: Slko/MX
void show_system_info()
{
#ifdef USE_SDL
	Log << "System information:\n";
	const SDL_version *linked_version = SDL_Linked_Version();
	SDL_version compiled_version;
	SDL_VERSION(&compiled_version);
	Log << "Compiled with SDL version: " << (int)compiled_version.major << "." << (int)compiled_version.minor << "." << (int)compiled_version.patch << "\n";
	Log << "Running with SDL version: " << (int)linked_version->major << "." << (int)linked_version->minor << "." << (int)linked_version->patch << "\n";
	if((compiled_version.major != linked_version->major)||(compiled_version.minor != linked_version->minor)||(compiled_version.patch != linked_version->patch))
	{
		Log << "Warning: SDL version mismatch\n";
	}
	Log << "\n";
	const SDL_version *image_linked_version = IMG_Linked_Version();
	SDL_version image_compiled_version;
	SDL_IMAGE_VERSION(&image_compiled_version);
	Log << "Compiled with SDL_image version: " << (int)image_compiled_version.major << "." << (int)image_compiled_version.minor << "." << (int)image_compiled_version.patch << "\n";
	Log << "Running with SDL_image version: " << (int)image_linked_version->major << "." << (int)image_linked_version->minor << "." << (int)image_linked_version->patch << "\n";
	if((image_compiled_version.major != image_linked_version->major)||(image_compiled_version.minor != image_linked_version->minor)||(image_compiled_version.patch != image_linked_version->patch))
	{
		Log << "Warning: SDL_image version mismatch\n";
	}
	Log << "\n";
#endif
}
コード例 #2
0
ファイル: gfxSDL.cpp プロジェクト: Ronoh55/supermariowar
void GraphicsSDL::print_sdl_img_version()
{
    // show SDL_image version
    SDL_version ver_compiled;
    const SDL_version * ver_img_current = IMG_Linked_Version();
    SDL_IMAGE_VERSION(&ver_compiled);
    printf("[gfx] SDL_image %d.%d.%d loaded.\n",
           ver_img_current->major, ver_img_current->minor, ver_img_current->patch);
}
コード例 #3
0
ファイル: MainManager.cpp プロジェクト: julius/sdl2-gamedev
void MainManager::initSDLimg()
{
  log_.i("Initializing SDL_img");
  int imgFlags = IMG_INIT_PNG | IMG_INIT_JPG;
  int imgFlagsInit = IMG_Init(imgFlags);
  if ((imgFlagsInit & imgFlags) != imgFlags)
    throw log_.exception("Failed to initialize SDL_img", SDL_GetError);
  atexit(IMG_Quit);

  // Write version information to log
  SDL_version compiled;
  SDL_IMAGE_VERSION(&compiled);
  logSDLVersion("SDL_image", compiled, *IMG_Linked_Version());
}
コード例 #4
0
ファイル: ver.c プロジェクト: nomikomu/katame-no-supu
int SDL_imgver(){
	SDL_version compile_version;
	auto const SDL_version *link_version=IMG_Linked_Version();
	SDL_IMAGE_VERSION(&compile_version);

	printf("compiled with SDL_image version: %d.%d.%d\n",
			compile_version.major,                                                        
			compile_version.minor,                                                        
			compile_version.patch);

	printf("running with SDL_image version: %d.%d.%d\n",
			link_version->major,
			link_version->minor, 
			link_version->patch);
}
コード例 #5
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;
}
コード例 #6
0
ファイル: SDLWrapper.cpp プロジェクト: Alke-Games/Dauphine
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);
}
コード例 #7
0
ファイル: Game.cpp プロジェクト: shiffu/age
	void Game::init(Window* window) {

        m_window = window;

        //TODO: use a proper logging lib
		std::cout << "Initializing game " + m_gameName << "\n";

        // Initialize SDL sub systems
        SDL_Init(SDL_INIT_EVERYTHING);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

        m_window->init();
        // Do not do any openGl call before the OpenGL Context
        // is created (in the window.init() method)
        Utils::logGlErrors("SDL Init failed");
        
        // TODO: configure the image format accepted (enum)
        int flags = IMG_INIT_JPG | IMG_INIT_PNG;
        int initializedFlags = IMG_Init(flags);
        if((initializedFlags & flags) != flags) {
            std::cerr << "IMG_Init: Failed to init required jpg and png support!\n";
            std::cerr << "IMG_Init: " << IMG_GetError() << std::endl;
        }
        Utils::logGlErrors("SDL_Image Init failed");
        
        SDL_version compile_version;
        const SDL_version *link_version = IMG_Linked_Version();
        SDL_IMAGE_VERSION(&compile_version);
        
        printf("Compiled with SDL_image version: %d.%d.%d\n",
               compile_version.major,
               compile_version.minor,
               compile_version.patch);
        
        printf("Running with SDL_image version: %d.%d.%d\n",
               link_version->major,
               link_version->minor,
               link_version->patch);

#ifndef __APPLE__
		glewExperimental = true;
		GLenum err = glewInit();
		if (err != GLEW_OK) {
			fatalError("GLEW init failed!");
		}
#endif
		//Utils::logGlErrors("GLEW Init failed");

        glm::vec4 backgroundColor = m_backgroundColor.toVec4();
		glClearColor(backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a);

		// OpenGL Context - Set VSYNC: 0 => FALSE, 1 => TRUE
		SDL_GL_SetSwapInterval(0);

        std::cout << "OpenGL information: \n";
        std::cout << "================== \n";

        std::string unknown("Unknown");
        const GLubyte* glVendor = glGetString(GL_VENDOR) ? glGetString(GL_VENDOR) : (const GLubyte*)unknown.c_str();
        std::cout << " + Vendor: "     <<  glVendor << "\n";
        
        const GLubyte* glRenderer = glGetString(GL_RENDERER) ? glGetString(GL_RENDERER) : (const GLubyte*)unknown.c_str();
		std::cout << " + Renderer: "   << glRenderer << "\n";
        
        const GLubyte* glVersion = glGetString(GL_VERSION) ? glGetString(GL_VERSION) : (const GLubyte*)unknown.c_str();
		std::cout << " + GL Version: " << glVersion << "\n";
        
        const GLubyte* glGLSL = glGetString(GL_SHADING_LANGUAGE_VERSION)
                                    ? glGetString(GL_SHADING_LANGUAGE_VERSION) : (const GLubyte*)unknown.c_str();
		std::cout << " + GLSL: "       << glGLSL << std::endl;

		onInit();
		m_isInitialized = true;
	}