Esempio n. 1
0
void IN_Init(void)
{
	int appState;

	if (!SDL_WasInit(SDL_INIT_VIDEO))
	{
		Com_Error(ERR_FATAL, "IN_Init called before SDL_Init( SDL_INIT_VIDEO )");
		return;
	}

	mainScreen = (SDL_Window *)GLimp_MainWindow();

	Com_DPrintf("\n------- Input Initialization -------\n");

	in_keyboardDebug = Cvar_Get("in_keyboardDebug", "0", CVAR_TEMP);

	// mouse variables
	in_mouse = Cvar_Get("in_mouse", "1", CVAR_ARCHIVE);

	if (in_mouse->integer == 2)
	{
		Com_Printf("Trying to emulate non raw input\n");
		if (!SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1", SDL_HINT_OVERRIDE))
		{
			Com_Printf(S_COLOR_RED "Failed to set the hint");
		}
	}
	else
	{
		SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "0", SDL_HINT_OVERRIDE);
	}

	in_nograb = Cvar_Get("in_nograb", "0", CVAR_ARCHIVE);

	in_joystick          = Cvar_Get("in_joystick", "0", CVAR_ARCHIVE | CVAR_LATCH);
	in_joystickThreshold = Cvar_Get("joy_threshold", "0.15", CVAR_ARCHIVE);

	SDL_StartTextInput();

	mouseAvailable = (in_mouse->value != 0);
	IN_DeactivateMouse();

	appState = SDL_GetWindowFlags(mainScreen);
	Cvar_SetValue("com_unfocused", !((appState & SDL_WINDOW_INPUT_FOCUS) && (appState & SDL_WINDOW_MOUSE_FOCUS)));
	Cvar_SetValue("com_minimized", appState & SDL_WINDOW_MINIMIZED);

	IN_InitKeyLockStates();

	// FIXME: Joystick initialization crashes some Windows and Mac OS X clients (see SDL #2833)
	//IN_InitJoystick();

#ifdef DISABLE_DINGY
	IN_EnableDingFilter();
#endif
	Com_DPrintf("------------------------------------\n");
}
Esempio n. 2
0
/*
 * SDL.setHint(name, value, priority)
 *
 * Arguments:
 *	name the hint name
 *	value the hint value
 *	priority the hint priority - defaults to SDL.hintPriority.Normal.
 *
 * Returns:
 *	True on success or false
 *	The error message
 */
static int
l_setHint(lua_State *L)
{
	const char *name		= luaL_checkstring(L, 1);
	const char *value		= luaL_checkstring(L, 2);
	const SDL_HintPriority priority	= luaL_optinteger(L, 3, SDL_HINT_DEFAULT);

	return commonPush(L, "b", SDL_SetHintWithPriority(name, value, priority));
}
Esempio n. 3
0
void CInput::MouseModeRelative()
{
	if(!m_InputGrabbed)
	{
		m_InputGrabbed = 1;
		SDL_ShowCursor(SDL_DISABLE);
		if(SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, g_Config.m_InpGrab ? "0" : "1", SDL_HINT_OVERRIDE) == SDL_FALSE)
		{
			m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "input", "unable to switch relative mouse mode");
		}
		SDL_SetRelativeMouseMode(SDL_TRUE);
		SDL_GetRelativeMouseState(NULL, NULL);
	}
}
Esempio n. 4
0
File: game.cpp Progetto: wesulee/mr
bool Game::init(const Settings& settings) {
	if (!SDL::init())
		return false;

	// init game components
	InputHandler::init();

	SDL::window = SDL::createWindow(
		"mr", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
		Constants::windowWidth, Constants::windowHeight, SDL_WINDOW_SHOWN
	);

	// Create renderer
	SDL_RendererInfo renInfo;
	auto rendererPref = settings.getRendererPref();
	int rendererIndex = -1;		// default value
	SDL_SetHintWithPriority(	// set vsync preference
		SDL_HINT_RENDER_VSYNC,
		rendererPref.second ? SDLHintValue::TRUE : SDLHintValue::FALSE,
		SDL_HINT_OVERRIDE
	);
	if (!rendererPref.first.empty()) {
		// preference is set, search for renderer
		const int availDrivers = SDL::getNumRenderDrivers();
		for (int i = 0; i < availDrivers; ++i) {
			SDL::getRenderDriverInfo(i, &renInfo);
			if (std::strcmp(rendererPref.first.c_str(), renInfo.name) == 0) {
				rendererIndex = i;
				break;
			}
		}
		if (rendererIndex == -1) {
			Console::begin() << "The renderer " << q(rendererPref.first)
			                 << " is not available. Will use default renderer instead." << std::endl;
		}
	}
	SDL::renderer = SDL::createRenderer(SDL::window, rendererIndex, 0);
	SDL::getRendererInfo(SDL::renderer, &renInfo);
	std::string rendererFlags = SDL::rendererFlagsToString(renInfo.flags);
	if (rendererFlags.empty())
		rendererFlags = "none";
	Console::begin() << "renderer: " << q(renInfo.name) << " flags: " << rendererFlags << std::endl;
	// set target texture support flag
	SDL::targetTextureSupport = ((renInfo.flags & SDL_RENDERER_TARGETTEXTURE) != 0);
	if (!SDL::targetTextureSupport)
		Console::begin() << "Warning: TARGETTEXTURE not available." << std::endl;
	SDL::setRenderDrawBlendMode(SDL::renderer, SDL_BLENDMODE_BLEND);
	return true;
}
Esempio n. 5
0
static void sdl_refresh_input_size(sdl2_video_t *vid, bool menu, bool rgb32,
                                   unsigned width, unsigned height, unsigned pitch)
{
   sdl2_tex_t *target = menu ? &vid->menu : &vid->frame;

   if (!target->tex || target->w != width || target->h != height
       || target->rgb32 != rgb32 || target->pitch != pitch)
   {
      unsigned format;

      sdl_tex_zero(target);

      RARCH_PERFORMANCE_INIT(sdl_create_texture);
      RARCH_PERFORMANCE_START(sdl_create_texture);

      if (menu)
         format = rgb32 ? SDL_PIXELFORMAT_ARGB8888 : SDL_PIXELFORMAT_RGBA4444;
      else /* this assumes the frontend will convert 0RGB1555 to RGB565 */
         format = rgb32 ? SDL_PIXELFORMAT_ARGB8888 : SDL_PIXELFORMAT_RGB565;

      SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY,
                              (vid->video.smooth || menu) ? "linear" : "nearest",
                              SDL_HINT_OVERRIDE);

      target->tex = SDL_CreateTexture(vid->renderer, format,
                                      SDL_TEXTUREACCESS_STREAMING, width, height);

      RARCH_PERFORMANCE_STOP(sdl_create_texture);

      if (!target->tex)
      {
         RARCH_ERR("Failed to create %s texture: %s\n", menu ? "menu" : "main",
                   SDL_GetError());
         return;
      }

      if (menu)
         SDL_SetTextureBlendMode(target->tex, SDL_BLENDMODE_BLEND);

      target->w = width;
      target->h = height;
      target->pitch = pitch;
      target->rgb32 = rgb32;
      target->active = true;
   }
}
Esempio n. 6
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;
}
Esempio n. 7
0
static void sdl2_init_renderer(sdl2_video_t *vid)
{
   unsigned flags = SDL_RENDERER_ACCELERATED;

   if (vid->video.vsync)
      flags |= SDL_RENDERER_PRESENTVSYNC;

   SDL_ClearHints();
   SDL_SetHintWithPriority(SDL_HINT_RENDER_VSYNC,
                           vid->video.vsync ? "1" : "0", SDL_HINT_OVERRIDE);
   vid->renderer = SDL_CreateRenderer(vid->window, -1, flags);

   if (!vid->renderer)
   {
      RARCH_ERR("[SDL]: Failed to initialize renderer: %s", SDL_GetError());
      return;
   }

   SDL_SetRenderDrawColor(vid->renderer, 0, 0, 0, 255);
}
Esempio n. 8
0
bool CSDLPadManager::Init()
{
#if defined(SDL_HINT_ACCELEROMETER_AS_JOYSTICK)
	// On platforms that have accelerometer, don't return it as a joystick
	const int zero = 0;
	if (!SDL_SetHintWithPriority(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, (const char*)&zero, SDL_HINT_OVERRIDE))
	{
		gEnv->pLog->LogError("CSDLPadManager - SDL_SetHint SDL_HINT_ACCELEROMETER_AS_JOYSTICK failed: %s", SDL_GetError());
	}
#endif
	// setup devices
	int nGamePads = SDL_NumJoysticks();
	for (int i = 0; i < nGamePads; ++i)
	{
		if (!AddGamePad(i))
		{
			return false;
		}
	}
	return true;
}
Esempio n. 9
0
int graphics_Init(char** error, int use3dgraphics) {
    char errormsg[512];
    graphics3d = (use3dgraphics ? 1 : 0);

    if (!graphics3d) {
        // set scaling settings
        SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY,
        "1", SDL_HINT_OVERRIDE);

        // initialize SDL
        if (SDL_Init(SDL_INIT_TIMER) < 0) {
            snprintf(errormsg,sizeof(errormsg),"Failed to initialize SDL: %s", SDL_GetError());
            errormsg[sizeof(errormsg)-1] = 0;
            *error = strdup(errormsg);
            return 0;
        }
        return 1;
    }

    *error = strdup("3d graphics not available");
    return 0;
}
Esempio n. 10
0
SDL_bool
SDL_SetHint(const char *name, const char *value)
{
    return SDL_SetHintWithPriority(name, value, SDL_HINT_NORMAL);
}
Esempio n. 11
0
static int graphicsrender_drawCropped_SDL(
        struct graphicstexture *gt, int x, int y, float alpha,
        unsigned int sourcex, unsigned int sourcey,
        unsigned int sourcewidth, unsigned int sourceheight,
        unsigned int drawwidth, unsigned int drawheight,
        int rotationcenterx, int rotationcentery, double rotationangle,
        int horiflipped,
        double red, double green, double blue, int textureFiltering) {
    // calculate source dimensions
    SDL_Rect src,dest;
    src.x = sourcex;
    src.y = sourcey;
    src.w = sourcewidth;
    src.h = sourceheight;

    // set target dimensinos
    dest.x = x;
    dest.y = y;
    dest.w = drawwidth;
    dest.h = drawheight;    

    // set alpha mod:
    int i = (int)((float)255.0f * alpha);
    if (SDL_SetTextureAlphaMod(gt->sdltex, i) < 0) {
        printwarning("Warning: Cannot set texture alpha "
        "mod %d: %s\n", i, SDL_GetError());
    }

    // calculate rotation center:
    SDL_Point p;
    p.x = (int)((double)rotationcenterx * ((double)drawwidth / src.w));
    p.y = (int)((double)rotationcentery * ((double)drawheight / src.h));

    // set draw color:
    SDL_SetTextureColorMod(gt->sdltex, (red * 255.0f),
        (green * 255.0f), (blue * 255.0f));

    // set texture filter:
    if (!textureFiltering) {
        // disable texture filter
        /* SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY,
        "0", SDL_HINT_OVERRIDE); */

        // this doesn't work. we will need to wait for:
        // https://bugzilla.libsdl.org/show_bug.cgi?id=2167
    }

    // actual draw call:
    if (horiflipped) {
        // draw rotated and flipped
        SDL_RenderCopyEx(mainrenderer, gt->sdltex, &src, &dest,
            rotationangle, &p, SDL_FLIP_HORIZONTAL);
    } else {
        if (rotationangle > 0.001 || rotationangle < -0.001) {
            // draw rotated
            SDL_RenderCopyEx(mainrenderer, gt->sdltex, &src, &dest,
            rotationangle, &p, SDL_FLIP_NONE);
        } else {
            // don't rotate the rendered image if it's barely rotated
            // (this helps the software renderer)
            SDL_RenderCopy(mainrenderer, gt->sdltex, &src, &dest);
        }
    }
    if (!textureFiltering) {
        // re-enable texture filter
        SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY,
        "1", SDL_HINT_OVERRIDE);
    }
    return 1;
}
Esempio n. 12
0
static void graphics_setInitialHints(void) {
    SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY,
   "1", SDL_HINT_OVERRIDE);
}
Esempio n. 13
0
int video_set_mode(s_videomodes videomodes)
{
    //if(memcmp(&stored_videomodes, &videomodes, sizeof(videomodes))==0) return 1;
    stored_videomodes = videomodes;

    int b;
    int allocTextureWidth, allocTextureHeight;

    savedata.screen[videoMode][0] = 0;
    savedata.fullscreen = 1;
    bytes_per_pixel = videomodes.pixel;
    b = bytes_per_pixel - 1;

    //destroy all
    if(bscreen)
    {
        SDL_FreeSurface(bscreen);
    }
    bscreen = NULL;
    if(texture)
    {
        SDL_DestroyTexture(texture);
    }
    texture = NULL;
    if(buttons)
    {
        SDL_DestroyTexture(buttons);
    }
    buttons = NULL;
    //mysterious crash in sdl 2.0 if these are recreated, so leave them alone for now
    //if(renderer) SDL_DestroyRenderer(renderer);
    //renderer = NULL;
    //if(window) SDL_DestroyWindow(window);
    //window = NULL;

    if(videomodes.hRes == 0 && videomodes.vRes == 0)
    {
        return 0;
    }

    viewportWidth = nativeWidth;
    viewportHeight = nativeHeight;

    if(!window && !(window = SDL_CreateWindow("OpenBOR", 0, 0, nativeWidth, nativeHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN)))
    {
        printf("error: %s\n", SDL_GetError());
        return 0;
    }

    if(!renderer && !(renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED)))
    {
        printf("error: %s\n", SDL_GetError());
        return 0;
    }

    SDL_RendererInfo info;
    SDL_GetRendererInfo(renderer, &info);

    printf("SDL video Renderer: %s \n", info.name);

    SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY, savedata.glfilter[savedata.fullscreen] ? "nearest" : "linear", SDL_HINT_DEFAULT);

    // now create a texture
    textureWidth = videomodes.hRes;
    textureHeight = videomodes.vRes;

    allocTextureWidth = nextpowerof2(textureWidth);
    allocTextureHeight = nextpowerof2(textureHeight);

    int format = SDL_MasksToPixelFormatEnum (textureDepths[b], masks[b][0], masks[b][1], masks[b][2], masks[b][3]);
    if(!(texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, allocTextureWidth, allocTextureHeight)))
    {
        printf("error: %s\n", SDL_GetError());
        return 0;
    }

    setup_touch();

    if(!buttons)
    {
        bscreen = pngToSurface(buttonpng);
        if(!bscreen || !(buttons = SDL_CreateTextureFromSurface(renderer, bscreen)))
        {
            printf("error: %s\n", SDL_GetError());
            return 0;
        }
        SDL_FreeSurface(bscreen);
        bscreen = NULL;
    }

    //create a buffer for 8bit mode, masks don't really matter but anyway set them
    if(bytes_per_pixel == 1)
    {
        bscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, textureWidth, textureHeight, textureDepths[b], masks[b][0], masks[b][1], masks[b][2], masks[b][3]);
    }

    video_clearscreen();

    return 1;
}