Пример #1
0
bool init() {
	bool success = true;
	if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0) {
		printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
		success = false;
	}
	else
	{
		if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
		{
			printf( "Warning: Linear texture filtering not enabled!" );
		}
		gWindow = SDL_CreateWindow( "Mahjong", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
		if( gWindow == NULL )
		{
			printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
			success = false;
		}
		else
		{
			gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
			if( gRenderer == NULL )
			{
				printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
				success = false;
			}
			else
			{
				SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
				int imgFlags = IMG_INIT_PNG;
				if( !( IMG_Init( imgFlags ) & imgFlags ) )
				{
					printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
					success = false;
				}
				if( TTF_Init() == -1 )
				{
					printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
					success = false;
				}
				if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
				{
					printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
					success = false;
				}
			}
		}
	}
	return success;
}
Пример #2
0
// Create window and renderer.
//Return -1 if it fails.
int Renderer::SDLinit(){
    sdlwindow = NULL;

    screensurface = NULL;

    int window_width = 1280;
    int window_height = 720;

    //Initialize SDL
    if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
        return -1;
    } else {
        //Create window
        sdlwindow = SDL_CreateWindow( "SDL Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, window_width, window_height, SDL_WINDOW_SHOWN );

        if( sdlwindow == NULL )
        {
            printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
            return -1;
        } else {
            //Get window surface
            screensurface = SDL_GetWindowSurface( sdlwindow );

            //Create renderer for window
            gRenderer = SDL_CreateRenderer( sdlwindow, -1, SDL_RENDERER_ACCELERATED );
            if( gRenderer == NULL )
            {
                printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
                return -1;
            } else {
                //Initialize renderer color
                SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );

                //Initialize PNG loading
                int imgFlags = IMG_INIT_PNG;
                if( !( IMG_Init( imgFlags ) & imgFlags ) )
                {
                    printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
                    return -1;
                }
            }
        }
    }

    return 0;

}
Пример #3
0
int
init_sdl(void)
{
	int flags;

	/* initialize SDL */
	if (SDL_Init(SDL_INIT_VIDEO) == -1) {
		fprintf(stderr, "SDL could not initialize! SDL Error: %s\n",
			SDL_GetError());
		return -1;
	}

	/* set texture filtering to linear */
	if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"))
		fprintf(stderr,
			"Warning: Linear texture filtering not enabled!\n");

	/* create window */
	gWindow = SDL_CreateWindow("SDL Tutorial",
			SDL_WINDOWPOS_UNDEFINED,
			SDL_WINDOWPOS_UNDEFINED,
			SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
	if (gWindow == NULL) {
		fprintf(stderr, "window could not be created! SDL Error: %s\n",
			SDL_GetError());
		return -1;
	}

	/* create renderer for window */
	gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
	if (gRenderer == NULL) {
		fprintf(stderr, "Renderer could not be created! "
			"SDL Error: %s\n", SDL_GetError());
		return -1;
	} else {
		/* initialize renderer color */
		SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);

		/* initialize PNG loading */
		flags = IMG_INIT_PNG;
		if ((IMG_Init(flags) & flags) == 0) {
			fprintf(stderr, "SDL_image could not initialize! "
				"SDL_image Error: %s\n", IMG_GetError());
			return -1;
		}
	}

	return 0;
}
Пример #4
0
void init(){
    SDL_Init(SDL_INIT_VIDEO);
    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
    
    gWindow = SDL_CreateWindow("batman 1", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
    
    gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    
    batman = new Batman(gRenderer);
    
    SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
    
    IMG_Init(IMG_INIT_PNG);
    
}
Пример #5
0
void GraphicsSDL::init_sdl_img()
{
    // init SDL_image
    int img_flags = IMG_INIT_JPG | IMG_INIT_PNG;
    if ((IMG_Init(img_flags) & img_flags) != img_flags) {
        printf("[gfx] SDL_image error: %s\n", IMG_GetError());
        throw E_INIT_SDL_IMG;
    }

    // TODO: Remove guards when IMG gets properly supported by Emscripten
#ifndef __EMSCRIPTEN__
    atexit(IMG_Quit);
    print_sdl_img_version();
#endif
}
bool ModuleTextures::init() {
	LOG("init Image library");
	bool ret = true;

	// load support for the PNG image format
	int flags = IMG_INIT_PNG;
	int init = IMG_Init(flags);

	if ((init & flags) != flags) {
		LOG("Could not initialize Image lib. IMG_init: %s", IMG_GetError());
		ret = false;
	}

	return ret;
}
Пример #7
0
//create SDL window and allow for png loading
void Game::Start()
{
    assert( SDL_Init( SDL_INIT_EVERYTHING ) >= 0 );
    mWindow = SDL_CreateWindow( "Shmup", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
				SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
    assert( mWindow );

    mRenderer = SDL_CreateRenderer( mWindow, -1, SDL_RENDERER_ACCELERATED );
    assert( mRenderer );

    int imgFlags = IMG_INIT_PNG;
    assert( IMG_Init( imgFlags ) & imgFlags );

    SDL_SetRenderDrawColor( mRenderer, 0x00, 0x00, 0x00, 0xFF );
}
Пример #8
0
void Init() {
	bool success = true;

	SDL_Init(SDL_INIT_VIDEO);
	window = SDL_CreateWindow("Tamagochi", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
		SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
	//Initialize PNG loading
	int imgFlags = IMG_INIT_PNG;
	if (!(IMG_Init(imgFlags) & imgFlags))
	{
		printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
		success = false;
	}
}
Пример #9
0
GraphicsSystem::GraphicsSystem(EntityManager *em, int window_width, int window_height)
{
	_window = SDL_CreateWindow("Objectless", SDL_WINDOWPOS_UNDEFINED,
		SDL_WINDOWPOS_UNDEFINED, window_width, window_height, SDL_WINDOW_SHOWN);
	_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED |
		SDL_RENDERER_PRESENTVSYNC);

	_entitymanager = em;

	// Initialize the flags for image lib
	if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)) {
		assert2(false, "IMG_Init failed!! %s", SDL_GetError());
		exit(0);
	}
}
Пример #10
0
void CResourceManager::StartUp(void)
{
	//SDL_Image
	if ( !IMG_Init(IMG_INIT_PNG) )
	{
		CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_RESOURCES,"Starting Up! (FAILED LOADING SDL_Image)");
	}
	else
	{
		CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_RESOURCES,"Starting Up! SDL_Image Loaded!");
	}

	LoadTextures();
	LoadAudio();
}
Пример #11
0
int Saloon::init(const char* title, int width, int height, bool windowed, int x, int y) {
	if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
		logSDLError(std::cout, "SDL_Init");
		return 1;
	}

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	// Slight optimization to prepare the PNG loader prior to loading any images
	if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG){
		logSDLError(std::cout, "IMG_Init");
		return 1;
	}

	if (TTF_Init() != 0){
		logSDLError(std::cout, "TTF_Init");
		return 1;
	}

	if(windowed) {
		_window = SDL_CreateWindow(title, x, y, width, height,
				SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
	}
	else {
		_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
				width, height,
				SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);
	}

	if (_window == nullptr){
		logSDLError(std::cout, "CreateWindow");
		return 2;
	}

	_displayWidth = width;
	_displayHeight = height;

	_halfDisplayWidth = width/2.0f;
	_halfDisplayHeight = height/2.0f;

	return 0;
}
Пример #12
0
bool 
BackBuffer::Initialise(int width, int height)
{
	m_width = width;
	m_height = height;

	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
	{
		LogSDLError();
		return (false);
	}
	else
	{
		m_pWindow = SDL_CreateWindow("717130 Game Framework", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);

		if (m_pWindow == 0)
		{
			LogSDLError();
			return (false);
		}
		else
		{
			m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, SDL_RENDERER_ACCELERATED); 

			if (m_pRenderer == 0)
			{
				LogSDLError();
				return (false);
			}
			else
			{
				int imageResult = IMG_Init(IMG_INIT_PNG);

				if (imageResult == 0)
				{
					LogSDLError();
					return (false);
				}
			}
		}
	}

	m_pTextureManager = new TextureManager();
	assert(m_pTextureManager);
	m_pTextureManager->Initialise(m_pRenderer);

	return (true);
}
Пример #13
0
bool init() {
  bool l_success = true;
  
  if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
    printf("SDL could not initialize! SDL Error: %s\n",
	   SDL_GetError());
    l_success = false;
  } else {
    if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) {
      printf("Warning: Linear texture filtering not enabled");
    }  
    //Create window
    g_window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, 
				SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
				SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
  
    if(g_window == NULL) {
      printf("Window could not be created! SDL Error: %s\n",
	     SDL_GetError());
      l_success = false;
    } else {
      //Creates vsynced renderer for window
      g_renderer = SDL_CreateRenderer(g_window, -1,
				      SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
      if(g_renderer == NULL) {
	printf("Renderer could not be created! SDL Error:%s\n",
	       SDL_GetError());
	l_success = false;
      } else {
	SDL_SetRenderDrawColor(g_renderer, 0xFF, 0xFF, 0xFF, 0xFF);

	//Initialize PNG loading
	int imgFlags = IMG_INIT_PNG;
	if(!(IMG_Init(imgFlags) & imgFlags)) {
	  printf("SDL_image could not initialize! SDL_image Error: %s\n",
		 IMG_GetError());
	  l_success = false;
	}
	
	//Initialize SDL_mixer
	if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) {
	  printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError());
	}
      }
    }
  }
  return l_success;
}
Пример #14
0
// Called before render is available
bool Textures::awake(pugi::xml_node &node)
{
	LOG("Init Image library");
	bool ret = true;
	// load support for the PNG image format
	int flags = IMG_INIT_PNG;
	int init = IMG_Init(flags);

	if((init & flags) != flags)
	{
		LOG("Could not initialize Image lib. IMG_Init: %s", IMG_GetError());
		ret = false;
	}

	return ret;
}
Пример #15
0
void sdl_init(uint32_t sdl_flags, int img_flags)
{
    sp_logger = common::logging_get_logger("sdlwrap");

    sp_logger->info("Initializing SDL");
    auto result = SDL_Init(sdl_flags);
    if (result){
        sdl_throw_error("SDL_Init");
    }

    sp_logger->info("Initializing SDL image");
    result = IMG_Init(img_flags);
    if (result != img_flags){
        sdl_img_throw_error("IMG_Init");
    }
}
Пример #16
0
int main (int argc, char** argv)
{
	//init libraries at the top level to avoid game system dependencies and because I'm using SDL_main anyway
	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
	IMG_Init(IMG_INIT_PNG);

	Game game;
	game.run();
	game.destroy();

	//stop libraries
	IMG_Quit();
	SDL_Quit();

	return 0;
}
Пример #17
0
void Game::Init()
{
    int ret;
    ret = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO);
    assert(ret >= 0);
    window = SDL_CreateWindow("Chinese Chess", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Config::SCREEN_WIDTH, Config::SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
    assert(window != NULL);
    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    assert(renderer != NULL);
    SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
    int imgFlags = IMG_INIT_PNG;
    ret = IMG_Init(imgFlags) & imgFlags;
    assert(ret);
    ret = TTF_Init();
    assert(ret != -1);
}
Пример #18
0
// Called before render is available
bool j1Textures::Awake(j1IniReader* conf)
{
	LOG("Init Image library");
	bool ret = true;
	// load support for the PNG image format
	int flags = IMG_INIT_PNG;
	int init = IMG_Init(flags);

	if((init & flags) != flags)
	{
		LOG("Could not initialize Image lib. IMG_Init: %s", IMG_GetError());
		ret = false;
	}

	return ret;
}
Пример #19
0
int SGL_Init(void)
{
	int error = SDL_Init(SDL_INIT_EVERYTHING);
	if(error != 0)
	{
		SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, SDL_GetError());
		return error;
	}
	error = IMG_Init(IMG_INIT_PNG);
	if (error == 0)
	{
		SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, SDL_GetError());
		return error;
	}
	return 0;
}
int init_SDL_all()
{
    SDL_Init(SDL_INIT_VIDEO);              // Initialize SDL2

    //init image loader
    if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG){
	    logSDLError("IMG_Init");
	    return 1;
    }

    if (TTF_Init() != 0){
	    logSDLError("TTF_Init");
	    return 1;
    }
    return 0;
}
Пример #21
0
bool init()
{
	bool success = true;

	// Attempt to initialize SDL, log error on failure
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		// Oops, something happened with SDL
		std::cout << "Cannot initalize SDL. Reason: " << SDL_GetError() << std::endl;
		success = false;
	}
	else
	{
		// We've made it this far, so let's create the main window
		window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,	screen_width, screen_height, SDL_WINDOW_SHOWN);
		if (window == nullptr)
		{
			// No window, so log the reason why and get out of here
			std::cout << "Cannot create window. Reason: " << SDL_GetError() << std::endl;
			success = false;
		}
		else
		{
			// Now create the window's renderer
			renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
			if (renderer == nullptr)
			{
				std::cout << "Cannot create renderer. Reason: " << SDL_GetError() << std::endl;
				success = false;
			}
			else
			{
				// Set the rendering color to opaque plain white.
				SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);

				// Now initalize the image library for PNG loading
				int imgFlags = IMG_INIT_PNG;
				if (!(IMG_Init(imgFlags) & imgFlags))
				{
					std::cout << "Cannot load image library. Reason: " << IMG_GetError() << std::endl;
					success = false;
				}
			}
		}
	}
	return success;
}
Пример #22
0
void RenderHelper::Init()
{
    m_cWindow = nullptr;
    m_cWindow = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
    if( m_cWindow == nullptr )
    {
        logger.LogError( std::string("SDL_CreateWindow: ") + SDL_GetError() );
        return 2;
    }
    else
    {
        logger.Log("SDL_CreateWindow was successful");
    }

    m_cRenderer = nullptr;
    m_cRenderer = SDL_CreateRenderer(m_cWindow, -1, SDL_RENDERER_PRESENTVSYNC);
    if( m_cRenderer == nullptr )
    {
        logger.LogError( std::string("SDL_CreateRenderer: ") + SDL_GetError() );
        return 3;
    }
    else
    {
        logger.Log("SDL_CreateRenderer was successful");
    }

    int img_flags = IMG_INIT_JPG|IMG_INIT_PNG;
    if ((IMG_Init(img_flags) != img_flags))
    {
        logger.LogError("IMG_Init failed to init jpeg with error "  + std::string(SDL_GetError()) );
        return 4;
    }
    else
    {
        logger.Log("IMG_Init was successful!");
    }

    if (TTF_Init() == -1)
    {
        logger.LogError("TTF_Init Failed with error: "  + std::string(TTF_GetError()) );
        return 5;
    }
    else
    {
        logger.Log("TTF_Init was successful!");
    }
}
Пример #23
0
SDLRenderer::SDLRenderer() {
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_EVENTS) != 0) {
        Log::error(_("SDL could not be initialized: %s"), SDL_GetError());
        return;
    }

    atexit(SDL_Quit);
    Log::info(_("SDL initialized."));

    SDL_Surface* surfaceAppIcon = IMG_Load("data/img/appicon.png");
    if (surfaceAppIcon == nullptr) {
        Log::error(_("Could not load graphic 'data/img/appicon.png': %s"), SDL_GetError());
        return;
    }

    window = SDL_CreateWindow(
         "OpenIsles", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_HIDDEN);
    if (window == nullptr) {
        Log::error(_("SDL could not create window: %s"), SDL_GetError());
        return;
    }

    SDL_SetWindowIcon(window, surfaceAppIcon);
    SDL_FreeSurface(surfaceAppIcon);

    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
    if (renderer == nullptr) {
        Log::error(_("SDL could not create renderer: %s"), SDL_GetError());
        SDL_DestroyWindow(window);
        return;
    }

    offscreenTexture = SDL_CreateTexture(
         renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, WINDOW_WIDTH, WINDOW_HEIGHT);

    if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG) {
        Log::error(_("Could not init SDL-image: %s"), IMG_GetError());
        return;
    }
    atexit(IMG_Quit);

    if (TTF_Init() != 0) {
        Log::error(_("Could not init SDL-TTF: %s"), TTF_GetError());
        return;
    }
    atexit(TTF_Quit);
}
Пример #24
0
SDL_Window *initSDL(options *opt, int *success)
{

	SDL_Window *temp;
	int SDL_Flags, IMG_Flags;
	SDL_Flags = SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_AUDIO;
	IMG_Flags = IMG_INIT_JPG | IMG_INIT_PNG;
	if(SDL_Init(SDL_Flags) < 0)
	{
		fprintf(stderr, "SDL_Init has failed : %s \n", SDL_GetError());
		*success = FAIL;
		return NULL;
	}
	if(TTF_Init() != 0)
	{
		fprintf(stderr, "TFF_Init has failed : %s \n", TTF_GetError());
		*success = FAIL;
		return NULL;
	}
	if(!(IMG_Init(IMG_Flags) & IMG_Flags))
	{
		fprintf(stderr, "IMG_Init has failed, %s \n", IMG_GetError());
		*success = FAIL;
		return NULL;
	
	}
	if(Mix_OpenAudio(opt->SAMPLE_FREQUENCY, MIX_DEFAULT_FORMAT, opt->NO_CHANNELS, opt->SAMPLE_SIZE) < 0)//first arg : frequency of audio, second arg : format, third arg : Number of audio channels, forth arg : sample size
	{
		fprintf(stderr, "Mix_OpenAudio has failed, %s \n", Mix_GetError());
		*success = FAIL;
		return NULL;
	
	}
	temp = SDL_CreateWindow(opt->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, opt->SCREEN_WIDTH, opt->SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
	if(!temp)
	{
		fprintf(stderr, "SDL_CreateWindow has failed : %s \n");
		*success = FAIL;
		return NULL;
	
	}
	
	return temp;



}
Пример #25
0
SDL_Setup::SDL_Setup(const int width, const int height) 
	: SCREEN_WIDTH(width), SCREEN_HEIGHT(height)
{
	e = new SDL_Event();

	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		std::printf("\nUnable to initialize SDL:  %s\n", SDL_GetError());
	}
	else
		if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"))
		{
			std::printf("Warning: Linear texture filtering not enabled!");
		}

	//Create Window
	gWindow = SDL_CreateWindow("Game Prototype", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 
								SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
	if (gWindow == NULL)
	{
		std::printf("Window failed to initialize! SDL Error: %s\n", SDL_GetError());
	}
	else
	{
		//Create renderer
		gRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
		if (gRenderer == NULL)
		{
			printf("Renderer failed to initialize! SDL Error: %s\n", SDL_GetError());
		}
		else
		{
			//Sets resolution for all platforms (letter boxing)
			SDL_RenderGetLogicalSize(gRenderer, &resWidth, &resHeight);

			//Intitialize render color
			SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);

			//Initialize PNG loading 
			int imgFlags = IMG_INIT_PNG;
			if (!(IMG_Init(imgFlags) & imgFlags))
			{
				printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
			}
		}
	}
}
Пример #26
0
int engine_init(SDL_Window** window, SDL_Renderer** renderer, Resources** resources)
{
	int flags;
//{ region init	
	flags = SDL_INIT_EVERYTHING;
	if(SDL_Init(flags) != 0)
	{
		LOG("SDL init error: %s", SDL_GetError());
		return 1;
	}
	flags = IMG_INIT_PNG;
	if(IMG_Init(flags) & flags != flags)
	{
		LOG("IMG init error: %s", IMG_GetError());
		return 1;
	}
	if(TTF_Init() != 0)
	{
		LOG("TTF init error %s", TTF_GetError());
		return 1;
	}
//}

	random_init();
	
	(*window) = SDL_CreateWindow("Lines",
		SDL_WINDOWPOS_UNDEFINED,
		SDL_WINDOWPOS_UNDEFINED,
		SCREEN_WIDTH,
		SCREEN_HEIGHT,
		SDL_WINDOW_SHOWN);
	if((*window) == NULL)
	{
		LOG("Window could not be created! SDL_Error: %s\n", SDL_GetError());
		return 1;
	}
	
	(*renderer) = SDL_CreateRenderer((*window),-1,SDL_RENDERER_ACCELERATED);
	if((*renderer) == NULL)
	{
		LOG("Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
		return 1;
	}
	
	(*resources) = loadMedia(*renderer);
	return 0;
}
Пример #27
0
bool init() {
  //Initialization flag
  bool success = true;

  //Initialize SDL
  if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
    printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
    success = false;
  } else {
    //Set texture filtering to linear
    if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) ) {
      printf( "Warning: Linear texture filtering not enabled!" );
    }

    //Create window
    gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
    if( gWindow == NULL ) {
      printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
      success = false;
    } else {
      //Create vsynced renderer for window
      gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
      if( gRenderer == NULL ) {
        printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
        success = false;
      } else {
        //Initialize renderer color
        SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );

        //Initialize PNG loading
        int imgFlags = IMG_INIT_PNG;
        if( !( IMG_Init( imgFlags ) & imgFlags ) ) {
          printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
          success = false;
        }

        //Initialize SDL_ttf
        if( TTF_Init() == -1 ) {
          printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
          success = false;
        }
      }
    }
  }

  return success;
}
Пример #28
0
bool init()
{
    bool working = true;

    if(SDL_Init(SDL_INIT_VIDEO))
    {
        cout << "\nSDL Video Subsystem failed. ERROR: " << SDL_GetError();
        working = false;
    }
    else
    {
        mainWindow = SDL_CreateWindow("Space Invaders v1.2.5", ((1920 - gameWidth) / 2), ((1080 - gameHeight) / 2), gameWidth, gameHeight, SDL_WINDOW_SHOWN);
        if(!mainWindow)
        {
            cout << "\nFailed to create main game window. ERROR: " << SDL_GetError();
            working = false;
        }
        else
        {
            mainRenderer = SDL_CreateRenderer(mainWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
            if(!mainRenderer)
            {
                cout << "\nFailed to initialize renderer. ERROR: " << SDL_GetError();
                working = false;
            }
            else
            {
                SDL_SetRenderDrawColor(mainRenderer, 0xFF, 0xFF, 0xFF, 0xFF);


                int imgFlags = IMG_INIT_PNG;
                if(!(IMG_Init(imgFlags) & imgFlags))
                {
                    cout << "\nSDL_image PNG module failed to initialize.Error: " << IMG_GetError();
                    working = false;
                }

                if(TTF_Init() == -1)
                {
                    cout << "SDL_ttf could not initialize! SDL_ttf Error: " << TTF_GetError();
                    working = false;
                }
            }
        }
    }
    return working;
}
Пример #29
0
//A function that runs when the game starts to initialize things
bool Initialize()
{
	//Initiate SDL Video and checks if there is an error
	if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
	{
		printf("SDL could not be initialized! SDL_Error: %s\n", SDL_GetError());
		Sleep(1000);
		return false;
	}

	//Create the window
	window = SDL_CreateWindow("Leikurinn Minn",
		SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
		SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);

	//Checks if there is an error when creating the window
	if (window == NULL)
	{
		printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
		Sleep(1000);
		return false;
	}

	//Create the renderer and if there is an error it will display
	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
	if (renderer == NULL)
	{
		printf("We were not able to create the renderer! SDL Error %s\n", SDL_GetError());
		return false;
	}

	if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
	{
		cout << "SDL Mixer Error!" << endl;
	}

	SDL_SetRenderDrawColor(renderer, 144, 195, 212, 255);
	
	int imgFlags = IMG_INIT_PNG;
	if (!(IMG_Init(imgFlags) & imgFlags))
	{
		return false;
	}

	return true;
}
bool WindowManagerSdl::initialiseSDL()
{
        if (SDL_Init(SDL_INIT_VIDEO) == -1)
        {
                std::cerr << "Failed to initialise SDL" << std::endl;
                return false;
        }

        int flags = IMG_INIT_PNG;
        if ((IMG_Init(flags) & flags) == -1)
        {
                std::cerr << "Failed to initialise SDL_image" << std::endl;
                return false;
        }

        return true;
}