Exemplo n.º 1
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;
}
Exemplo n.º 2
0
bool game::init(const char* title, int xPos, int yPos, int width, int height, bool fullscreen)
{
    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);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

    if (SDL_Init(SDL_INIT_EVERYTHING) >= 0)
    {
        _window = SDL_CreateWindow(title, xPos, yPos, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);

        _context = SDL_GL_CreateContext(_window);

        if (_context)
        {
            glewExperimental = GL_TRUE;
            GLenum glewError = glewInit();
            if (glewError != GLEW_OK)
            {
                printf("Error initializing GLEW! %s\n", glewGetErrorString(glewError));
            }
        }
    }

    SDL_GL_SetSwapInterval(1);

    std::cout << "SDL init success \n";

    _timer = std::shared_ptr<GameTick>(new GameTick);

    int currentWindowWidth = 0;
    int currentWindowHeight = 0;
    SDL_GetWindowSize(_window, &currentWindowWidth, &currentWindowHeight);

    gameData::instance().setData(_renderer, _window, xPos, yPos, currentWindowWidth, currentWindowHeight, fullscreen);

    _stateHandler = std::shared_ptr<stateHandlerGen>(new stateHandlerGen);
    _input.reset(new inputSystem);

    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");


    _running = true;

    return true;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
    if (SDL_Init(SDL_INIT_VIDEO) != 0)
    {
        qDebug() << "SDL_Init failed: " << QString::fromStdString(SDL_GetError());
        return 0;
    }

    QApplication app(argc, argv);

    // Now we make sure the current dir is set to application path
    QDir dir(QCoreApplication::applicationDirPath());

#ifdef Q_OS_MAC
    if (dir.dirName() == "MacOS") {
        dir.cdUp();
        dir.cdUp();
        dir.cdUp();
    }

    // force Qt to load only LOCAL plugins, don't touch system Qt installation
    QDir pluginsPath(QCoreApplication::applicationDirPath());
    pluginsPath.cdUp();
    pluginsPath.cd("Plugins");

    QStringList libraryPaths;
    libraryPaths << pluginsPath.path() << QCoreApplication::applicationDirPath();
    app.setLibraryPaths(libraryPaths);
#endif

    QDir::setCurrent(dir.absolutePath());

    // Support non-latin characters
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

    MainDialog mainWin;

    if (mainWin.setup()) {
        mainWin.show();
    } else {
        return 0;
    }

    int returnValue = app.exec();
    SDL_Quit();
    return returnValue;
}
Exemplo n.º 4
0
//--------------------------------------------------------------------------------
//	@	WindowManager::init()
//--------------------------------------------------------------------------------
//		General constructor
//--------------------------------------------------------------------------------
void WindowManager::init(uint32 w, uint32 h, bool _fullScreen, std::string _title)
{
	//Set title
	title = _title;

	//Set flags
	fullScreen = _fullScreen;

	//Set up the screen
	if (fullScreen)
	{
		// make the scaled rendering look smoother.
		SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  

		sdlScreen = SDL_CreateWindow(title.c_str(),
                          SDL_WINDOWPOS_UNDEFINED,
                          SDL_WINDOWPOS_UNDEFINED,
                          w, h,
                          SDL_WINDOW_FULLSCREEN_DESKTOP);
	}
	else
		sdlScreen = SDL_CreateWindow(title.c_str(),
                          SDL_WINDOWPOS_UNDEFINED,
                          SDL_WINDOWPOS_UNDEFINED,
                          w, h,
                          SDL_WINDOW_OPENGL);

    //If there was an error in setting up the screen
    if( sdlScreen == NULL )
    {
        std::cerr << "@WindowManager::WindowManager(...) -> Could not create screen" << std::endl;
    }

	sdlRenderer = SDL_CreateRenderer(sdlScreen, -1, 0);

	sdlTexture = SDL_CreateTexture(sdlRenderer,
                               SDL_PIXELFORMAT_ARGB8888,
                               SDL_TEXTUREACCESS_STREAMING,
                               w, h);

	//Letterbox full screenf
	SDL_RenderSetLogicalSize(sdlRenderer, w, h);

	//Set data
	ww = w;
	wh = h;

}	//End: WindowManager::init()
Exemplo n.º 5
0
int video_setup_yuv_overlay(const yuv_video_mode *mode)
{
	stored_yuv_mode = *mode;
	yuv_mode = 1;
	if(opengl) return video_gl_setup_yuv_overlay(mode);

	SDL_DestroyTexture(texture);
	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
	texture = SDL_CreateTexture(renderer,
	                            SDL_PIXELFORMAT_YV12,
	                            SDL_TEXTUREACCESS_STREAMING,
	                            mode->width, mode->height);
	if(!stretch)
		SDL_RenderSetLogicalSize(renderer, mode->display_width, mode->display_height);
	return texture ? 1 : 0;
}
void InputManager::init()
{
	if(initialized())
		deinit();

	SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, 
		Settings::getInstance()->getBool("BackgroundJoystickInput") ? "1" : "0");
	SDL_InitSubSystem(SDL_INIT_JOYSTICK);
	SDL_JoystickEventState(SDL_ENABLE);

	// first, open all currently present joysticks
        this->addAllJoysticks();

	mKeyboardInputConfig = new InputConfig(DEVICE_KEYBOARD, -1, "Keyboard", KEYBOARD_GUID_STRING, 0);
	loadInputConfig(mKeyboardInputConfig);
}
Exemplo n.º 7
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());
			}
		}
	}
}
bool GameApplication::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!");
		}
		window = SDL_CreateWindow("Mahjong", SDL_WINDOWPOS_UNDEFINED,
		SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
		if (window == NULL) {
			printf("Window could not be created! SDL Error: %s\n",
					SDL_GetError());
			success = false;
		} else {
			renderer = SDL_CreateRenderer(window, -1,
					SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
			if (renderer == NULL) {
				printf("Renderer could not be created! SDL Error: %s\n",
						SDL_GetError());
				success = false;
			} else {
				SDL_SetRenderDrawColor(renderer, 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;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
/*
 * Set the value of a hint.
 * 
 * @overload []=(hint, value)
 *   Set a hint with normal priority.
 *
 *   @param hint [String] the name of the hint to query
 *   @param value [String] the value of the hint varaible
 *
 * @overload []=(hint, priority: , value)
 *   Set a hint with given priority.
 *
 *   @param hint [String] the name of the hint to query
 *   @param priority [Integer] the priority, one of the
 *     {DEFAULT}, {NORMAL}, or {OVERRIDE}.
 *   @param value [String] the value of the hint varaible
 *   
 * @return [Boolean] return true if the hint was set
 *
 * @example
 *   SDL2::Hints["SDL_HINT_XINPUT_ENABLED", priority: SDL2::Hints::OVERRIDE] = "0"
 *
 */
static VALUE Hints_s_aset(int argc, VALUE* argv, VALUE self)
{
    VALUE name, pri, value;
    rb_scan_args(argc, argv, "21", &name, &pri, &value);
    
    if (argc == 2) {
        value = pri;
        return INT2BOOL(SDL_SetHint(StringValueCStr(name), StringValueCStr(value)));
    } else {
        Check_Type(pri, T_HASH);
        return INT2BOOL(SDL_SetHintWithPriority(StringValueCStr(name),
                                                StringValueCStr(value),
                                                NUM2INT(rb_hash_aref(pri, sym_priority))));
    }
        
    return Qnil;
}
void graphics_initialize(char *windowName, int viewWidth, int viewHeight, int renderWidth, int renderHeight, int fullscreen)
{
    Uint32 flags = 0;
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
    {
        slog("Unable to initilaize SDL system: %s",SDL_GetError());
        return;
    }
    atexit(SDL_Quit);
    if (fullscreen)
    {
        if (renderWidth == 0)
        {
            flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
        }
        else
        {
            flags |= SDL_WINDOW_FULLSCREEN;
        }
    }
    graphicsMainWindow = SDL_CreateWindow(windowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderWidth, renderHeight, flags);
    if (!graphicsMainWindow)
    {
        slog("failed to create main window: %s",SDL_GetError());
        graphics_close();
        return;
    }
    
    graphicsRenderer = SDL_CreateRenderer(graphicsMainWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
    if (!graphicsRenderer)
    {
        slog("failed to create renderer: %s",SDL_GetError());
        graphics_close();
        return;
    }
    
    SDL_RenderClear(graphicsRenderer);
    SDL_RenderPresent(graphicsRenderer);
	//sets a hint with normal priority, this specifically sets the scaling quality to be linear, this is supported by OpenGL and Direct3D
    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
    //sets a device independent resolution for rendering
	SDL_RenderSetLogicalSize(graphicsRenderer, renderWidth, renderHeight);
    
    atexit(graphics_close);
    slog("graphics initialized\n");
}
Exemplo n.º 12
0
ScreenGlobalInit::ScreenGlobalInit()
{
  Uint32 flags = SDL_INIT_VIDEO;
  if (!IsKobo())
    flags |= SDL_INIT_AUDIO;

  if (::SDL_Init(flags) != 0) {
    fprintf(stderr, "SDL_Init() has failed: %s\n", ::SDL_GetError());
    exit(EXIT_FAILURE);
  }

#if defined(HAVE_GLES) && SDL_MAJOR_VERSION >= 2
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#ifdef HAVE_GLES2
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif
#endif

#if SDL_MAJOR_VERSION >= 2
  // Keep screen on (works on iOS, and maybe for other platforms)
  SDL_SetHint(SDL_HINT_IDLE_TIMER_DISABLED, "1");
#endif

  if (HasTouchScreen())
    SDL_ShowCursor (SDL_FALSE);

#if SDL_MAJOR_VERSION < 2
  ::SDL_EnableKeyRepeat(250, 50);
  ::SDL_EnableUNICODE(true);
#endif

#if defined(ENABLE_OPENGL)
  ::SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  ::SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);

  OpenGL::Initialise();
#endif

  Font::Initialise();

  event_queue = new EventQueue();

  ScreenInitialized();
}
Exemplo n.º 13
0
bool Game::Start(const char* title, int argc, char** argv)
{
  // Init SDL
  if (SDL_Init(SDL_INIT_VIDEO) < 0)
  {
    printf("Could not init SDL: %s\n", SDL_GetError());
    return false;
  }

  // TODO read arguments and config file
  // Enable VSync
  /*
  if (!SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"))
  {
    printf("VSync not enabled!\n");
  }
  */

  // Set texture filtering to linear
  if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"))
  {
    printf("Linear texture filtering not enabled!\n");
  }

  // Create window
  window_ = SDL_CreateWindow(
    title,
    SDL_WINDOWPOS_CENTERED,
    SDL_WINDOWPOS_CENTERED,
    WINDOW_WIDTH,
    WINDOW_HEIGHT,
    SDL_WINDOW_SHOWN
  );
  if (window_ == NULL)
  {
    printf("Could not create window: %s\n", SDL_GetError());
    return false;
  }

  renderer_ = new Renderer(window_, SDL_RENDERER_ACCELERATED);

  this->init_ = true;

  return true;
}
Exemplo n.º 14
0
void input_joysticks_detect() {
	// Initialize any joysticks
	printf("%i joystick(s) found:\n", SDL_NumJoysticks());
	
	int i;
	
	for (i = 0; i < SDL_NumJoysticks(); i++) {
		joystick = SDL_JoystickOpen(i);
		printf("%s\n", SDL_JoystickName(joystick));
	}

	SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
	
	turbostate.p1a = turbotoggle.p1a = 0;
	turbostate.p1b = turbotoggle.p1b = 0;
	turbostate.p2a = turbotoggle.p2a = 0;
	turbostate.p2b = turbotoggle.p2b = 0;
}
Exemplo n.º 15
0
/* video extension functions to be called by the video plugin */
EXPORT m64p_error CALL VidExt_Init(void)
{
    /* call video extension override if necessary */
    if (l_VideoExtensionActive)
        return (*l_ExternalVideoFuncTable.VidExtFuncInit)();

#if SDL_VERSION_ATLEAST(2,0,0)
    SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
#endif

    if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
    {
        DebugMessage(M64MSG_ERROR, "SDL video subsystem init failed: %s", SDL_GetError());
        return M64ERR_SYSTEM_FAIL;
    }

    return M64ERR_SUCCESS;
}
Exemplo n.º 16
0
void renderer_initialize(Renderer * renderer) {
  SDL_InitSubSystem(SDL_INIT_VIDEO);

  SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best");

  renderer->window = create_sdl_window();
  renderer->gl_context = SDL_GL_CreateContext(renderer->window);

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_BLEND);
  glDepthFunc(GL_LEQUAL);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_LINE_SMOOTH);
  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

  renderer_notify_viewport_resized(renderer);
  renderer->camera = (Vector3) { INITIAL_CAMERA_X, INITIAL_CAMERA_Y, INITIAL_CAMERA_Z };
}
Exemplo n.º 17
0
/*..........................................................................................
bool Init(string * files);

Purpose:Initializes the program by checking for the SDL Library files and then
constructing a window that will hold the image.

Entry: char * headerName[]: is a pointer to a char array.  It holds the command line
arguments, and in this case the image file's directory and name.

Exit: bool pass: is a variable that returns true if everything succeeds in the method.
...........................................................................................
*/
bool cSurfMan::Init(string * path)
{
	bool pass = true;

	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		cout << "Initialization failure. ERROR: ", SDL_GetError();
		pass = false;
	}
	else
	{
		if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"))
		{
			cout << "Linear Texture Filtering not enabled!";
		}	 
		mWindow = SDL_CreateWindow(path->c_str(), SDL_WINDOWPOS_UNDEFINED,
			SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_SHOWN);
		if (mWindow == nullptr)
		{
			cout << "Can't Create Window! SDL ERROR: " << SDL_GetError();
			pass = false;
		}
		else
		{
			mRenderer = SDL_CreateRenderer(mWindow, -1,	SDL_RENDERER_ACCELERATED);
			if (mRenderer == nullptr)
			{
				cout << "Renderer Failed to be created!";
				pass = false;
			}
			else
			{	
				SDL_SetRenderDrawColor(mRenderer, 0x00, 0x00, 0x00, 0x00);  //(UNIT8 red, UNIT8 green, UNIT8 blue, UNIT8 Alpha) sets the renderer color to black
				int imgFlags = IMG_INIT_PNG;
				if (!(IMG_Init(imgFlags) & imgFlags))
				{
					cout << "SDL_Image couldn't initialize!";
					pass = false;
				}
			}
		}
	}
	return pass;
}
Exemplo n.º 18
0
bool init()
{
    bool success = true;

    if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Nie mozna zainicjowac SDL'a! SDL Error: %s\n", SDL_GetError() );
        success = false;
    }
    else
    {
        if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
        {
            printf( "Filtrowanie tekstur jest wylaczone!\n" );
        }
        window = SDL_CreateWindow( "Lekcja 11", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
        if( window == NULL )
        {
            printf( "Nie mozna utworzyc okienka! SDL Error: %s\n", SDL_GetError() );
            success = false;
        }
        else
        {
            renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED );
            if( renderer == NULL )
            {
                printf( "Render nie moze zostac utworzony! SDL Error: %s\n", SDL_GetError() );
                success = false;
            }
            else
            {
                SDL_SetRenderDrawColor( renderer, 0xFF, 0xFF, 0xFF, 0xFF );

                int F = IMG_INIT_PNG;
                if(!(IMG_Init(F)&F))
                {
                    printf( "Nie mozna zainicjowac IMG INIT! SDL_mage Error: %s\n", IMG_GetError() );
                    success = false;
                }
            }
        }
    }
    return success;
}
Exemplo n.º 19
0
SDL_Renderer *Renderer::createRenderer()
{
    // Automatically choose the best driver.
    const int bestDriver = -1;

    SDL_Renderer *rendererContext = SDL_CreateRenderer(
                                        this->window, bestDriver, SDL_RENDERER_ACCELERATED);
    Debug::check(rendererContext != nullptr, "Renderer", "SDL_CreateRenderer");

    // Set pixel interpolation hint.
    SDL_bool status = SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY,
                                  Renderer::DEFAULT_RENDER_SCALE_QUALITY.c_str());
    if (status != SDL_TRUE)
    {
        Debug::mention("Renderer", "Could not set interpolation hint.");
    }

    // Set the size of the render texture to be the size of the whole screen
    // (it automatically scales otherwise).
    auto *nativeSurface = this->getWindowSurface();

    // If this fails, we might not support hardware accelerated renderers for some reason
    // (such as with Linux), so we retry with software.
    if (!nativeSurface)
    {
        Debug::mention("Renderer",
                       "Failed to initialize with hardware accelerated renderer, trying software.");

        SDL_DestroyRenderer(rendererContext);

        rendererContext = SDL_CreateRenderer(this->window, bestDriver, SDL_RENDERER_SOFTWARE);
        Debug::check(rendererContext != nullptr, "Renderer", "SDL_CreateRenderer software");

        nativeSurface = this->getWindowSurface();
    }

    Debug::check(nativeSurface != nullptr, "Renderer", "SDL_GetWindowSurface");

    // Set the device-independent resolution for rendering (i.e., the
    // "behind-the-scenes" resolution).
    SDL_RenderSetLogicalSize(rendererContext, nativeSurface->w, nativeSurface->h);

    return rendererContext;
}
Exemplo n.º 20
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!" );
            }

            //Get number of displays
            gTotalDisplays = SDL_GetNumVideoDisplays();
            if( gTotalDisplays < 2 )
            {
                printf( "Warning: Only one display connected!" );
            }

            //Get bounds of each display
            gDisplayBounds = new SDL_Rect[ gTotalDisplays ];
            for( int i = 0; i < gTotalDisplays; ++i )
            {
                SDL_GetDisplayBounds( i, &gDisplayBounds[ i ] );
            }

            //Create window
            if( !gWindow.init() )
            {
                printf( "Window could not be created!\n" );
                success = false;
            }
        }

        return success;
    }
Exemplo n.º 21
0
bool Builder::init()
{
	bool success = true;

	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 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
		window = SDL_CreateWindow("SDL Tetris Attempt", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
		if (window == NULL)
		{
			printf ("Window could not be created! SDL Error: %s\n", SDL_GetError());
			success = false;
		}
		else
		{
			//Create renderer for window
			renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
			if (renderer == NULL)
			{
				printf ("Renderer could not be created! SDL Error: %s\n", SDL_GetError());
				success = false;
			}
			else
			{
				
				//Initialize renderer color
				SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
			}
		}
	}

	return success;
}
Exemplo n.º 22
0
/// --- FUNCTIONS ---
int init_Engine(){
int flags;

//Init SDL
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    return 1;
//Init TTF
if( TTF_Init() == -1 )
    return 2;

flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE;

if( SETTINGS.getFullScreen() )
    flags |= SDL_WINDOW_FULLSCREEN;

//Create Windows
WINDOW_MAIN = SDL_CreateWindow( "GAME PROJECT", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                SETTINGS.getScreenWidth(), SETTINGS.getScreenHeight(),
                                flags );//| SDL_WINDOW_FULLSCREEN
if( WINDOW_MAIN == NULL )
    return 3;

//Create Renderer
RENDERER_MAIN = SDL_CreateRenderer( WINDOW_MAIN, 0,
                                    SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
if( RENDERER_MAIN == NULL )
    return 4;

//Set Hints
SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "0" + SETTINGS.getRenderScaleQuality() );//"1"

//Init Fonts
loadFonts();

// -- INIT CLASSES --
CONS      .init();
ASSETS    .init();
MAP       .init();
EDIT_MODE .init();

return 0;
}
Exemplo n.º 23
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
    if(!g_window.init()) {
      printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
      l_success = false;
    } else {
      //Create renderer for window
      g_renderer = g_window.createRenderer();
      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_ttf
	if(TTF_Init() == -1) {
	  printf("SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError());
	  l_success = false;
	}
      }
    }
  }
  return l_success;
}
Exemplo n.º 24
0
bool TexturaBase::_criar(int largura, int altura, int qualidade_escala, EnumTipoTextura tipo)
{
	if (criada)
		return false;

	char buffer[2];
	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, SDL_itoa((int)qualidade_escala, buffer, 10));
	sdl_texture = SDL_CreateTexture(gGraficos.sdl_renderer, SDL_PIXELFORMAT_ARGB8888, (int)tipo, largura, altura);

	if (!sdl_texture)
		return false;

	SDL_SetTextureBlendMode(sdl_texture, SDL_BLENDMODE_BLEND);
	this->largura = largura;
	this->altura = altura;
	qualidadeEscala = qualidade_escala;

	criada = true;
	return true;
}
Exemplo n.º 25
0
bool init() {

	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		return false;
	}

	if (IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG) {
		return false;
	}

	if (TTF_Init() != 0) {
		return false;
	}

	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");



	return true;
}
Exemplo n.º 26
0
Display::Display(const unsigned width, const unsigned height) :
	window_{check_SDL(SDL_CreateWindow(
		"player", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
		width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE),
		"window"), SDL_DestroyWindow},
	renderer_{check_SDL(SDL_CreateRenderer(
		window_.get(), -1,
		SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
		"renderer"), SDL_DestroyRenderer},
	texture_{check_SDL(SDL_CreateTexture(
		renderer_.get(), SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,
		width, height), "renderer"), SDL_DestroyTexture} {

	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
	SDL_RenderSetLogicalSize(renderer_.get(), width, height);

	SDL_SetRenderDrawColor(renderer_.get(), 0, 0, 0, 255);
	SDL_RenderClear(renderer_.get());
	SDL_RenderPresent(renderer_.get());
}
Exemplo n.º 27
0
void InputManager::init()
{
	if(initialized())
		deinit();

	SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, 
		Settings::getInstance()->getBool("BackgroundJoystickInput") ? "1" : "0");
	SDL_InitSubSystem(SDL_INIT_JOYSTICK);
	SDL_JoystickEventState(SDL_ENABLE);

	// first, open all currently present joysticks
	int numJoysticks = SDL_NumJoysticks();
	for(int i = 0; i < numJoysticks; i++)
	{
		addJoystickByDeviceIndex(i);
	}

	mKeyboardInputConfig = new InputConfig(DEVICE_KEYBOARD, "Keyboard", KEYBOARD_GUID_STRING);
	loadInputConfig(mKeyboardInputConfig);
}
Exemplo n.º 28
0
SDLEvents::SDLEvents() {
    // Initialize the GameController database with the most recent file
    // from https://github.com/gabomdq/SDL_GameControllerDB
    // TODO: Instead of storing the file as a ressource, have it in some
    // directory so the user can modify it if needed..
    Q_INIT_RESOURCE( assets ); // needed to access resources before app.exec()
    QFile f( ":/assets/gamecontrollerdb.txt" );
    f.open( QIODevice::ReadOnly );
    SDL_SetHint( SDL_HINT_GAMECONTROLLERCONFIG, f.readAll().constData() );

    event_list = new SDL_Event[10]();

    this->moveToThread( &thread );
    polltimer.moveToThread( &thread );
    connect( &thread, SIGNAL( started() ), SLOT( threadStarted() ) );
    connect( &thread, SIGNAL( finished() ), SLOT( threadFinished() ) );
    thread.setObjectName( "phoenix-SDLEvents" );

    thread.start( QThread::HighPriority );
}
Exemplo n.º 29
0
BOOL BRWindowOpen (const char *titel, BOOL forceSoftwareRenderer, int interpolationMethod) {
  SDL_RendererInfo renInfo;
  BOOL accelerated;

  // Init window...
  sdlWindow = SDL_CreateWindow (
    titel,
    SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
    704, 576, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE /* | SDL_WINDOW_FULLSCREEN_DESKTOP */
  );
  if (!sdlWindow) {
    printf ("E: 'SDL_CreateWindow' failed: %s\n", SDL_GetError ());
    return FALSE;
  }

  // Init renderer...
  sdlRenderer = SDL_CreateRenderer (sdlWindow, -1, forceSoftwareRenderer ? SDL_RENDERER_SOFTWARE : 0);
  //sdlRenderer = SDL_CreateRenderer (sdlWindow, 1, 0);
  if (!sdlRenderer) {
    SDL_DestroyWindow (sdlWindow);
    sdlWindow = NULL;
    printf ("E: 'SDL_CreateRenderer' failed: %s\n", SDL_GetError ());
    return FALSE;
  }

  // Determine, set and report renderer type and scaling method...
  SDL_GetRendererInfo (sdlRenderer, &renInfo);
  accelerated = (renInfo.flags & SDL_RENDERER_ACCELERATED) ? TRUE : FALSE;
  if (!interpolationMethod) interpolationMethod = accelerated ? 2 : 1;
  SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, interpolationMethod == 2 ? "1" : "0");
  printf ("I: Using %s renderer '%s' and %s interpolation.\n",
          accelerated ? "accelerated" : "software", renInfo.name,
          interpolationMethod == 2 ? "trying bilinear" : "nearest-neighbor");

  //for (n = 0; n < (int) renInfo.num_texture_formats; n++)
  //  INFOF(("  SDL_Renderer [%i]:         %s", n, SDL_GetPixelFormatName (renInfo.texture_formats[n])));


  // Return with success...
  return TRUE;
}
Exemplo n.º 30
0
void SDLFrontend::initRenderer ()
{
	info(LOG_CLIENT, "init sdl renderer");
	const int renderers = SDL_GetNumRenderDrivers();
	SDL_RendererInfo ri;
	for (int i = 0; i < renderers; i++) {
		SDL_GetRenderDriverInfo(i, &ri);
		info(LOG_CLIENT, String::format("available renderer %s", ri.name));
	}

#if defined(SDL_VIDEO_OPENGL_ES2)
	const std::string rendererStr = "opengles2";
#elif defined(SDL_VIDEO_OPENGL_ES)
	const std::string rendererStr = "opengles";
#elif defined(SDL_VIDEO_OPENGL)
	const std::string rendererStr = "opengl";
#else
#error "No supported renderer found"
#endif

	const ConfigVarPtr& renderer = Config.getConfigVar("renderer", rendererStr, true);
	const std::string& rendererValue = renderer->getValue();
	info(LOG_CLIENT, "try renderer: " + rendererValue);
	SDL_SetHint(SDL_HINT_RENDER_DRIVER, rendererValue.c_str());
	_renderer = SDL_CreateRenderer(_window, -1, 0);
	SDL_GetRendererInfo(_renderer, &ri);

	SDL_RenderSetLogicalSize(_renderer, getWidth(), getHeight());

	_softwareRenderer = (ri.flags & SDL_RENDERER_SOFTWARE);

	info(LOG_CLIENT, String::format("actual renderer %s", ri.name));
	if (strcmp(ri.name, "opengles2")) {
		// disable shaders as they are currently built for glesv2
		ConfigManager::get().getConfigVar("shader")->setValue("false");
		info(LOG_CLIENT, "disable shaders for the current renderer");
	}
	info(LOG_CLIENT, String::format("max texture resolution: %i:%i", ri.max_texture_width, ri.max_texture_height));
	SDL_SetRenderDrawBlendMode(_renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(_renderer, 0, 0, 0, 255);
}