예제 #1
0
파일: windows.cpp 프로젝트: MicroVirus/7kaa
// Based on the example provided by Eric Wasylishen
// https://discourse.libsdl.org/t/sdl-getdesktopdisplaymode-resolution-reported-in-windows-10-when-using-app-scaling/22389
void WIN_InitDPI()
{
	void* userDLL;
	void* shcoreDLL;

	shcoreDLL = SDL_LoadObject("SHCORE.DLL");
	if (shcoreDLL)
	{
		SetProcessDpiAwareness = (HRESULT(WINAPI *)(PROCESS_DPI_AWARENESS)) SDL_LoadFunction(shcoreDLL, "SetProcessDpiAwareness");
	}

	if (SetProcessDpiAwareness)
	{
		/* Try Windows 8.1+ version */
		HRESULT result = SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
		return;
	}

	userDLL = SDL_LoadObject("USER32.DLL");
	if (userDLL)
	{
		SetProcessDPIAware = (BOOL(WINAPI *)(void)) SDL_LoadFunction(userDLL, "SetProcessDPIAware");
	}

	if (SetProcessDPIAware)
	{
		/* Try Vista - Windows 8 version.
		This has a constant scale factor for all monitors.
		*/
		BOOL success = SetProcessDPIAware();
	}
}
예제 #2
0
bool load() {
	if (loaded) return true;
	lib           = SDL_LoadObject("libgtk-3.so.0");
	if (!lib) lib = SDL_LoadObject("libgtk-x11-2.0.so.0");
	if (!lib) {
		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Cannot show open file dialog: no GTK library available.");
		return false;
	}

	loadFunc(g_free);
	loadFunc(gtk_dialog_get_type);
	loadFunc(gtk_dialog_run);
	loadFunc(gtk_events_pending);
	loadFunc(gtk_file_chooser_add_filter);
	loadFunc(gtk_file_chooser_dialog_new);
	loadFunc(gtk_file_chooser_get_filename);
	loadFunc(gtk_file_chooser_get_type);
	loadFunc(gtk_file_filter_add_pattern);
	loadFunc(gtk_file_filter_new);
	loadFunc(gtk_file_filter_set_name);
	loadFunc(gtk_init_check);
	loadFunc(gtk_main_iteration);
	loadFunc(gtk_widget_destroy);
	loadFunc(gtk_window_get_type);
	loadFunc(gtk_window_new);
	loadFunc(g_type_check_instance_cast);

	loaded = true;
	return true;
}
예제 #3
0
int
VIVANTE_VideoInit(_THIS)
{
    SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;

#if SDL_VIDEO_DRIVER_VIVANTE_VDK
    videodata->vdk_private = vdkInitialize();
    if (!videodata->vdk_private) {
        return SDL_SetError("vdkInitialize() failed");
    }
#else
    videodata->egl_handle = SDL_LoadObject("libEGL.so.1");
    if (!videodata->egl_handle) {
        videodata->egl_handle = SDL_LoadObject("libEGL.so");
        if (!videodata->egl_handle) {
            return -1;
        }
    }
#define LOAD_FUNC(NAME) \
    videodata->NAME = SDL_LoadFunction(videodata->egl_handle, #NAME); \
    if (!videodata->NAME) return -1;

    LOAD_FUNC(fbGetDisplay);
    LOAD_FUNC(fbGetDisplayByIndex);
    LOAD_FUNC(fbGetDisplayGeometry);
    LOAD_FUNC(fbGetDisplayInfo);
    LOAD_FUNC(fbDestroyDisplay);
    LOAD_FUNC(fbCreateWindow);
    LOAD_FUNC(fbGetWindowGeometry);
    LOAD_FUNC(fbGetWindowInfo);
    LOAD_FUNC(fbDestroyWindow);
#endif

    if (VIVANTE_SetupPlatform(_this) < 0) {
        return -1;
    }

    if (VIVANTE_AddVideoDisplays(_this) < 0) {
        return -1;
    }

    VIVANTE_UpdateDisplayScale(_this);

#ifdef SDL_INPUT_LINUXEV
    if (SDL_EVDEV_Init() < 0) {
        return -1;
    }
#endif

    return 0;
}
예제 #4
0
int
PND_gl_loadlibrary(_THIS, const char *path)
{
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;

    /* Check if OpenGL ES library is specified for GF driver */
    if (path == NULL) {
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
        if (path == NULL) {
            path = SDL_getenv("SDL_OPENGLES_LIBRARY");
        }
    }

    /* Check if default library loading requested */
    if (path == NULL) {
        /* Already linked with GF library which provides egl* subset of  */
        /* functions, use Common profile of OpenGL ES library by default */
        path = "/usr/lib/libGLES_CM.so";
    }

    /* Load dynamic library */
    _this->gl_config.dll_handle = SDL_LoadObject(path);
    if (!_this->gl_config.dll_handle) {
        /* Failed to load new GL ES library */
        SDL_SetError("PND: Failed to locate OpenGL ES library");
        return -1;
    }

    /* Store OpenGL ES library path and name */
    SDL_strlcpy(_this->gl_config.driver_path, path,
                SDL_arraysize(_this->gl_config.driver_path));

    /* New OpenGL ES library is loaded */
    return 0;
}
예제 #5
0
static int
DSOUND_Load(void)
{
    int loaded = 0;

    DSOUND_Unload();

    DSoundDLL = SDL_LoadObject("DSOUND.DLL");
    if (DSoundDLL == NULL) {
        SDL_SetError("DirectSound: failed to load DSOUND.DLL");
    } else {
        /* Now make sure we have DirectX 8 or better... */
        #define DSOUNDLOAD(f) { \
            p##f = (fn##f) SDL_LoadFunction(DSoundDLL, #f); \
            if (!p##f) loaded = 0; \
        }
        loaded = 1;  /* will reset if necessary. */
        DSOUNDLOAD(DirectSoundCreate8);
        DSOUNDLOAD(DirectSoundEnumerateW);
        DSOUNDLOAD(DirectSoundCaptureEnumerateW);
        #undef DSOUNDLOAD

        if (!loaded) {
            SDL_SetError("DirectSound: System doesn't appear to have DX8.");
        }
    }

    if (!loaded) {
        DSOUND_Unload();
    }

    return loaded;
}
    static bool jsplugin_get_entry_points(const String& pluginLibrary, atomic_plugin_validate_function* fvalidate,
                                          duk_c_function* finit, String& errorMsg)
    {
        *fvalidate = NULL;
        *finit = NULL;

        // TODO: cache and use SDL_UnloadObject (when no longer needed)
        void* handle = SDL_LoadObject(pluginLibrary.CString());

        if (handle == NULL)
        {
            errorMsg = ToString("Native Plugin: Unable to load %s", pluginLibrary.CString());
            return false;
        }

        *fvalidate = (atomic_plugin_validate_function) SDL_LoadFunction(handle, "atomic_plugin_validate");

        if (!*fvalidate)
        {
            errorMsg = ToString("Native Plugin: Unable to get atomic_plugin_validate entry point in %s", pluginLibrary.CString());
            return false;
        }

        *finit = (duk_c_function) SDL_LoadFunction(handle, "atomic_plugin_init");

        if (!*finit)
        {
            LOGERRORF("Native Plugin: Unable to get atomic_plugin_init entry point in %s", pluginLibrary.CString());
            return false;
        }

        return true;

    }
예제 #7
0
internal sdl_game_code
SDLLoadGameCode(const char *SourceDLLName, const char *TempDLLName,
                const char *LockFileName)
{
    sdl_game_code Result = {};

    if (access(LockFileName, F_OK) == -1) {
        Result.DLLLastWriteTime = SDLGetLastWriteTime(SourceDLLName);
        SDLCopyFile(SourceDLLName, TempDLLName);
        Result.GameCodeDLL = SDL_LoadObject(TempDLLName);

        if (Result.GameCodeDLL) {
            Result.UpdateAndRender = (game_update_and_render *)
                SDL_LoadFunction(Result.GameCodeDLL, "GameUpdateAndRender");
            Result.GetSoundSamples = (game_get_sound_samples *)
                SDL_LoadFunction(Result.GameCodeDLL, "GameGetSoundSamples");

            Result.IsValid = (Result.UpdateAndRender && Result.GetSoundSamples);
        }
    }

    if (!Result.IsValid) {
        Result.UpdateAndRender = 0;
        Result.GetSoundSamples = 0;
    }

    return Result;
}
예제 #8
0
int
SDL_UDEV_LoadLibrary(void)
{
    int retval = 0, i;
    
    if (_this == NULL) {
        return SDL_SetError("UDEV not initialized");
    }
    
   
    if (_this->udev_handle == NULL) {
        for( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
            _this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]);
            if (_this->udev_handle != NULL) {
                retval = SDL_UDEV_load_syms();
                if (retval < 0) {
                    SDL_UDEV_UnloadLibrary();
                }
                else {
                    break;
                }
            }
        }
        
        if (_this->udev_handle == NULL) {
            retval = -1;
            /* Don't call SDL_SetError(): SDL_LoadObject already did. */
        }
    }

    return retval;
}
예제 #9
0
SDL_bool 
D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface )
{
	*pD3DDLL = SDL_LoadObject("D3D9.DLL");
	if (*pD3DDLL) {
		IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);

		D3DCreate =
			(IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(*pD3DDLL,
			"Direct3DCreate9");
		if (D3DCreate) {
			*pDirect3D9Interface = D3DCreate(D3D_SDK_VERSION);
		}
		if (!*pDirect3D9Interface) {
			SDL_UnloadObject(*pD3DDLL);
			*pD3DDLL = NULL;
			return SDL_FALSE;
		}

		return SDL_TRUE;
	} else {
		*pDirect3D9Interface = NULL;
		return SDL_FALSE;
	}
}
예제 #10
0
SDL_bool 
DXGI_LoadDLL( void **pDXGIDLL , IDXGIFactory **pDXGIFactory )
{
	*pDXGIDLL = SDL_LoadObject("DXGI.DLL");
	if (*pDXGIDLL ) {
		HRESULT (WINAPI *CreateDXGI)( REFIID riid, void **ppFactory );

		CreateDXGI =
			(HRESULT (WINAPI *) (REFIID, void**)) SDL_LoadFunction(*pDXGIDLL,
			"CreateDXGIFactory");
		if (CreateDXGI) {
			GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}};
			if( !SUCCEEDED( CreateDXGI( &dxgiGUID, (void**)pDXGIFactory ))) {
				*pDXGIFactory = NULL;
			}
		}
		if (!*pDXGIFactory) {
			SDL_UnloadObject(*pDXGIDLL);
			*pDXGIDLL = NULL;
			return SDL_FALSE;
		}

		return SDL_TRUE;
	} else {
		*pDXGIFactory = NULL;
		return SDL_FALSE;
	}
}
예제 #11
0
/* returns non-zero if all needed symbols were loaded. */
int
SDL_X11_LoadSymbols(void)
{
    int rc = 1;                 /* always succeed if not using Dynamic X11 stuff. */

#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
    /* deal with multiple modules (dga, x11, etc) needing these symbols... */
    if (x11_load_refcount++ == 0) {
        int i;
        int *thismod = NULL;
        for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
            if (x11libs[i].libname != NULL) {
                x11libs[i].lib = SDL_LoadObject(x11libs[i].libname);
            }
        }

#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; /* default yes */
#define SDL_X11_SYM(a,fn,x,y,z)
#include "SDL_x11sym.h"
#undef SDL_X11_MODULE
#undef SDL_X11_SYM

#define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
#define SDL_X11_SYM(a,fn,x,y,z) p##fn = (SDL_DYNX11FN_##fn) X11_GetSym(#fn,thismod);
#include "SDL_x11sym.h"
#undef SDL_X11_MODULE
#undef SDL_X11_SYM

#ifdef X_HAVE_UTF8_STRING
        pXCreateIC = (SDL_DYNX11FN_XCreateIC)
                        X11_GetSym("XCreateIC", &SDL_X11_HAVE_UTF8);
        pXGetICValues = (SDL_DYNX11FN_XGetICValues)
                        X11_GetSym("XGetICValues", &SDL_X11_HAVE_UTF8);
#endif

        if (SDL_X11_HAVE_BASEXLIB) {
            /* all required symbols loaded. */
            SDL_ClearError();
        } else {
            /* in case something got loaded... */
            SDL_X11_UnloadSymbols();
            rc = 0;
        }
    }
#else
#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; /* default yes */
#define SDL_X11_SYM(a,fn,x,y,z)
#include "SDL_x11sym.h"
#undef SDL_X11_MODULE
#undef SDL_X11_SYM

#ifdef X_HAVE_UTF8_STRING
    pXCreateIC = XCreateIC;
    pXGetICValues = XGetICValues;
#endif
#endif

    return rc;
}
예제 #12
0
int
main(int argc, char *argv[])
{
    int retval = 0;
    int hello = 0;
    const char *libname = NULL;
    const char *symname = NULL;
    void *lib = NULL;
    fntype fn = NULL;

    if (argc != 3) {
        const char *app = argv[0];
        SDL_Log("USAGE: %s <library> <functionname>\n", app);
        SDL_Log("       %s --hello <lib with puts()>\n", app);
        return 1;
    }

    /* Initialize SDL */
    if (SDL_Init(0) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
        return 2;
    }

    if (strcmp(argv[1], "--hello") == 0) {
        hello = 1;
        libname = argv[2];
        symname = "puts";
    } else {
        libname = argv[1];
        symname = argv[2];
    }

    lib = SDL_LoadObject(libname);
    if (lib == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadObject('%s') failed: %s\n",
                libname, SDL_GetError());
        retval = 3;
    } else {
        fn = (fntype) SDL_LoadFunction(lib, symname);
        if (fn == NULL) {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadFunction('%s') failed: %s\n",
                    symname, SDL_GetError());
            retval = 4;
        } else {
            SDL_Log("Found %s in %s at %p\n", symname, libname, fn);
            if (hello) {
                SDL_Log("Calling function...\n");
                fflush(stdout);
                fn("     HELLO, WORLD!\n");
                SDL_Log("...apparently, we survived.  :)\n");
                SDL_Log("Unloading library...\n");
                fflush(stdout);
            }
        }
        SDL_UnloadObject(lib);
    }
    SDL_Quit();
    return retval;
}
MFCOpenGLContext::MFCOpenGLContext(HGLRC hglrc): _render_context(hglrc)
{
	if (_oglDllHandle == nullptr)
	{
		_oglDllHandle = SDL_LoadObject("OPENGL32.DLL");
	}
	++_oglDllReferenceCount;
}
예제 #14
0
int Mix_InitOgg()
{
 if ( vorbis.loaded == 0 ) {
   vorbis.handle = SDL_LoadObject(OGG_DYNAMIC);
   if ( vorbis.handle == NULL ) {
     return -1;
   }
   vorbis.ov_clear =
     (int (*)(OggVorbis_File *))
     SDL_LoadFunction(vorbis.handle, "ov_clear");
   if ( vorbis.ov_clear == NULL ) {
     SDL_UnloadObject(vorbis.handle);
     return -1;
   }
   vorbis.ov_info =
     (vorbis_info *(*)(OggVorbis_File *,int))
     SDL_LoadFunction(vorbis.handle, "ov_info");
   if ( vorbis.ov_info == NULL ) {
     SDL_UnloadObject(vorbis.handle);
     return -1;
   }
   vorbis.ov_open_callbacks =
     (int (*)(void *, OggVorbis_File *, char *, long, ov_callbacks))
     SDL_LoadFunction(vorbis.handle, "ov_open_callbacks");
   if ( vorbis.ov_open_callbacks == NULL ) {
     SDL_UnloadObject(vorbis.handle);
     return -1;
   }
   vorbis.ov_pcm_total =
     (ogg_int64_t (*)(OggVorbis_File *,int))
     SDL_LoadFunction(vorbis.handle, "ov_pcm_total");
   if ( vorbis.ov_pcm_total == NULL ) {
     SDL_UnloadObject(vorbis.handle);
     return -1;
   }
   vorbis.ov_read =
#ifdef OGG_USE_TREMOR
     (long (*)(OggVorbis_File *,char *,int,int *))
#else
     (long (*)(OggVorbis_File *,char *,int,int,int,int,int *))
#endif
     SDL_LoadFunction(vorbis.handle, "ov_read");
   if ( vorbis.ov_read == NULL ) {
     SDL_UnloadObject(vorbis.handle);
     return -1;
   }
   vorbis.ov_time_seek =
     (int (*)(OggVorbis_File *,double))
     SDL_LoadFunction(vorbis.handle, "ov_time_seek");
   if ( vorbis.ov_time_seek == NULL ) {
     SDL_UnloadObject(vorbis.handle);
     return -1;
   }
 }
 ++vorbis.loaded;

 return 0;
}
예제 #15
0
/* returns non-zero if all needed symbols were loaded. */
int
SDL_WAYLAND_LoadSymbols(void)
{
    int rc = 1;                 /* always succeed if not using Dynamic WAYLAND stuff. */

    /* deal with multiple modules (dga, wayland, etc) needing these symbols... */
    if (wayland_load_refcount++ == 0) {
#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
        int i;
        int *thismod = NULL;
        for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
            if (waylandlibs[i].libname != NULL) {
                waylandlibs[i].lib = SDL_LoadObject(waylandlibs[i].libname);
            }
        }

#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */
#define SDL_WAYLAND_SYM(rc,fn,params)
#define SDL_WAYLAND_INTERFACE(iface)
#include "SDL_waylandsym.h"
#undef SDL_WAYLAND_MODULE
#undef SDL_WAYLAND_SYM
#undef SDL_WAYLAND_INTERFACE

#define SDL_WAYLAND_MODULE(modname) thismod = &SDL_WAYLAND_HAVE_##modname;
#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn) WAYLAND_GetSym(#fn,thismod);
#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = (struct wl_interface *) WAYLAND_GetSym(#iface,thismod);
#include "SDL_waylandsym.h"
#undef SDL_WAYLAND_MODULE
#undef SDL_WAYLAND_SYM
#undef SDL_WAYLAND_INTERFACE

        if (SDL_WAYLAND_HAVE_WAYLAND_CLIENT) {
            /* all required symbols loaded. */
            SDL_ClearError();
        } else {
            /* in case something got loaded... */
            SDL_WAYLAND_UnloadSymbols();
            rc = 0;
        }

#else  /* no dynamic WAYLAND */

#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */
#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = fn;
#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = &iface;
#include "SDL_waylandsym.h"
#undef SDL_WAYLAND_MODULE
#undef SDL_WAYLAND_SYM
#undef SDL_WAYLAND_INTERFACE

#endif
    }

    return rc;
}
예제 #16
0
/* returns non-zero if all needed symbols were loaded. */
int SDL_X11_LoadSymbols(void)
{
	int rc = 1;  /* always succeed if not using Dynamic X11 stuff. */

	#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
	/* deal with multiple modules (dga, x11, etc) needing these symbols... */
	if (x11_load_refcount++ == 0) {
		int i;
		int *thismod = NULL;
		for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
			if (x11libs[i].libname != NULL) {
				x11libs[i].lib = SDL_LoadObject(x11libs[i].libname);
			}
		}
		#define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
		#define SDL_X11_SYM(rc,fn,params,args,ret) \
            p##fn = (rc(*)params) X11_GetSym(#fn, thismod);
		#include "SDL_x11sym.h"
		#undef SDL_X11_MODULE
		#undef SDL_X11_SYM

		#ifdef X_HAVE_UTF8_STRING
		pXCreateIC = (XIC(*)(XIM,...)) X11_GetSym("XCreateIC",
		                                          &SDL_X11_HAVE_UTF8);
		pXGetICValues = (char * (*)(XIC,...)) X11_GetSym("XGetICValues",
		                                                 &SDL_X11_HAVE_UTF8);
		#endif

		/*
		 * In case we're built with newer Xlib headers, we need to make sure
		 *  that _XGetRequest() is available, even on older systems.
		 *  Otherwise, various Xlib macros we use will call a NULL pointer.
		 */
		if (!SDL_X11_HAVE_XGETREQUEST) {
			p_XGetRequest = SDL_XGetRequest_workaround;
		}

		if (SDL_X11_HAVE_BASEXLIB) {  /* all required symbols loaded. */
			SDL_ClearError();
		} else {
			SDL_X11_UnloadSymbols();  /* in case something got loaded... */
			rc = 0;
		}
	}
	#else
		#if DEBUG_DYNAMIC_X11
		printf("X11: No dynamic X11 support in this build of SDL.\n");
		#endif
		#ifdef X_HAVE_UTF8_STRING
		pXCreateIC = XCreateIC;
		pXGetICValues = XGetICValues;
		#endif
	#endif

	return rc;
}
예제 #17
0
int Mac_GL_LoadLibrary(_THIS, const char *location)
{
	if (location == NULL)
		location = "OpenGLLibrary";

	this->hidden->libraryHandle = SDL_LoadObject(location);

	this->gl_config.driver_loaded = 1;
	return (this->hidden->libraryHandle != NULL) ? 0 : -1;
}
예제 #18
0
파일: sv_game.c 프로젝트: chrisglass/ufoai
static qboolean SV_LoadGame (const char *path)
{
	char name[MAX_OSPATH];

	Com_sprintf(name, sizeof(name), "%s/game_"CPUSTRING".%s", path, SO_EXT);
	svs.gameLibrary = SDL_LoadObject(name);
	if (!svs.gameLibrary) {
		Com_sprintf(name, sizeof(name), "%s/game.%s", path, SO_EXT);
		svs.gameLibrary = SDL_LoadObject(name);
	}

	if (svs.gameLibrary) {
		Com_Printf("found at '%s'\n", path);
		return qtrue;
	} else {
		Com_Printf("not found at '%s'\n", path);
		Com_DPrintf(DEBUG_SYSTEM, "%s\n", SDL_GetError());
		return qfalse;
	}
}
예제 #19
0
	bool loadPlugin() {
		assert(!_dlHandle);
		_dlHandle = SDL_LoadObject(_filename.c_str());

		if (!_dlHandle) {
			warning("Failed loading plugin '%s' (%s)", _filename.c_str(), SDL_GetError());
			return false;
		}

		return DynamicPlugin::loadPlugin();
	}
예제 #20
0
	int extloader(lua_State * L)
	{
		const char * filename = lua_tostring(L, -1);
		std::string tokenized_name(filename);
		std::string tokenized_function(filename);

		for (unsigned int i = 0; i < tokenized_name.size(); i++)
		{
			if (tokenized_name[i] == '.')
			{
				tokenized_name[i] = '/';
				tokenized_function[i] = '_';
			}
		}

		tokenized_name += library_extension();

		void * handle = SDL_LoadObject((std::string(instance->getAppdataDirectory()) + LOVE_PATH_SEPARATOR LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR + tokenized_name).c_str());
		if (!handle && instance->isRelease())
			handle = SDL_LoadObject((std::string(instance->getSaveDirectory()) + LOVE_PATH_SEPARATOR + tokenized_name).c_str());

		if (!handle)
		{
			lua_pushfstring(L, "\n\tno extension \"%s\" in LOVE paths.\n", filename);
			return 1;
		}

		void * func = SDL_LoadFunction(handle, ("loveopen_" + tokenized_function).c_str());
		if (!func)
			func = SDL_LoadFunction(handle, ("luaopen_" + tokenized_function).c_str());

		if (!func)
		{
			SDL_UnloadObject(handle);
			lua_pushfstring(L, "\n\textension \"%s\" is incompatible.\n", filename);
			return 1;
		}

		lua_pushcfunction(L, (lua_CFunction) func);
		return 1;
	}
예제 #21
0
int Mac_GL_LoadLibrary(_THIS, const char *location)
{
	if (location == NULL)
#if __MACH__
		location = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
#else
		location = "OpenGLLibrary";
#endif

	this->hidden->libraryHandle = SDL_LoadObject(location);

	this->gl_config.driver_loaded = 1;
	return (this->hidden->libraryHandle != NULL) ? 0 : -1;
}
예제 #22
0
/* returns non-zero if all needed symbols were loaded. */
int
SDL_MIR_LoadSymbols(void)
{
    int rc = 1;                 /* always succeed if not using Dynamic MIR stuff. */

    /* deal with multiple modules (dga, wayland, mir, etc) needing these symbols... */
    if (mir_load_refcount++ == 0) {
#ifdef SDL_VIDEO_DRIVER_MIR_DYNAMIC
        int i;
        int *thismod = NULL;
        for (i = 0; i < SDL_TABLESIZE(mirlibs); i++) {
            if (mirlibs[i].libname != NULL) {
                mirlibs[i].lib = SDL_LoadObject(mirlibs[i].libname);
            }
        }

#define SDL_MIR_MODULE(modname) SDL_MIR_HAVE_##modname = 1; /* default yes */
#define SDL_MIR_SYM(rc,fn,params)
#include "SDL_mirsym.h"
#undef SDL_MIR_MODULE
#undef SDL_MIR_SYM

#define SDL_MIR_MODULE(modname) thismod = &SDL_MIR_HAVE_##modname;
#define SDL_MIR_SYM(rc,fn,params) MIR_##fn = (SDL_DYNMIRFN_##fn) MIR_GetSym(#fn,thismod);
#include "SDL_mirsym.h"
#undef SDL_MIR_MODULE
#undef SDL_MIR_SYM

        if ((SDL_MIR_HAVE_MIR_CLIENT) && (SDL_MIR_HAVE_XKBCOMMON)) {
            /* all required symbols loaded. */
            SDL_ClearError();
        } else {
            /* in case something got loaded... */
            SDL_MIR_UnloadSymbols();
            rc = 0;
        }

#else  /* no dynamic MIR */

#define SDL_MIR_MODULE(modname) SDL_MIR_HAVE_##modname = 1; /* default yes */
#define SDL_MIR_SYM(rc,fn,params) MIR_##fn = fn;
#include "SDL_mirsym.h"
#undef SDL_MIR_MODULE
#undef SDL_MIR_SYM

#endif
    }

    return rc;
}
예제 #23
0
	void PluginManager::LoadPlugins()
	{
		tinydir_dir dir;
		if (tinydir_open(&dir, PLUGINPATH) == -1)
		{
			Log("Error opening file");
		}

		int cpt = 0;

		while (dir.has_next)
		{
			tinydir_file file;
			if (tinydir_readfile(&dir, &file) == -1)
			{
				Log("Error getting file");
			}

			if (std::string(file.extension) == "dll")
			{
				void* handle = nullptr;
				handle = SDL_LoadObject(file.path);
				if (handle != nullptr)
				{
					std::vector<std::string>* (*func)();
					func = (std::vector<std::string>*(*)())SDL_LoadFunction(handle, "GetPluginFeatures");
					if (func != nullptr)
					{
						std::vector<std::string>* pluginFeatures = func();
						_plugins.push_back(handle);

						for (std::string& str : (*pluginFeatures))
						{
							_features[str].push_back(handle);
						}

						delete pluginFeatures;
					}
					else
						Log("Unable to load GetPluginFeatures function in : " + std::string(file.path));
				}
				else
					Log("Unable to load plugin : "+std::string(file.path));
			}

			tinydir_next(&dir);
		}
		tinydir_close(&dir);
	}
예제 #24
0
void SetBrightness(float val)
{
	/* This function exists because SDL2 uses function for brightness which is not supported by opensource X11 drivers */
	/* val < 0.0f tries to restore the brightness, less than -1.0 doesn't affect SDL function */
#ifdef USE_X11_GAMMA
	static BOOL firstCall = true;
	SDL_SysWMinfo sysInfo;
	SDL_VERSION(&sysInfo.version);
	if (SDL_GetWindowWMInfo(sdlWin, &sysInfo) && sysInfo.subsystem == SDL_SYSWM_X11)
	{
		static XF86VidModeGamma gammaToRestore = {-1.0f, -1.0f, -1.0f};
		static _XF86VidModeGetGamma XF86VidModeGetGamma;
		static _XF86VidModeSetGamma XF86VidModeSetGamma;
		if (firstCall && (!XF86VidModeGetGamma || !XF86VidModeSetGamma))
		{
			void *Xxf86vm = SDL_LoadObject(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE);
			if (Xxf86vm)
			{
				XF86VidModeGetGamma = SDL_LoadFunction(Xxf86vm, "XF86VidModeGetGamma");
				XF86VidModeSetGamma = SDL_LoadFunction(Xxf86vm, "XF86VidModeSetGamma");
			}
		}
		firstCall = false;
		if (XF86VidModeGetGamma && XF86VidModeSetGamma)
		{
			int screen = SDL_GetWindowDisplayIndex(sdlWin);
			if (screen < 0)
				screen = 0;
			if (gammaToRestore.red == -1.0f && gammaToRestore.green == -1.0f && gammaToRestore.blue == -1.0f)
				XF86VidModeGetGamma(sysInfo.info.x11.display, screen, &gammaToRestore); //Get brightness at first attempt
			if (val < 0.0f)
			{
				if (gammaToRestore.red >= 0.0f && gammaToRestore.green >= 0.0f && gammaToRestore.blue >= 0.0f && XF86VidModeSetGamma(sysInfo.info.x11.display, screen, &gammaToRestore)) //Restore brightness
					return;
				else
					val = 1.0f;
			}
			if (val >= 0.0f)
			{
				XF86VidModeGamma gamma = {val, val, val};
				if (XF86VidModeSetGamma(sysInfo.info.x11.display, screen, &gamma)) //Set brightness
					return;
			}
		}
	}
#endif
	if (val >= -1.0f)
		SDL_SetWindowBrightness(sdlWin, val < 0.0f ? 1.0f : val);
}
예제 #25
0
int IMG_InitTIF()
{
	if ( lib.loaded == 0 ) {
		lib.handle = SDL_LoadObject(LOAD_TIF_DYNAMIC);
		if ( lib.handle == NULL ) {
			return -1;
		}
		lib.TIFFClientOpen =
			(TIFF* (*)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc))
			SDL_LoadFunction(lib.handle, "TIFFClientOpen");
		if ( lib.TIFFClientOpen == NULL ) {
			SDL_UnloadObject(lib.handle);
			return -1;
		}
		lib.TIFFClose =
			(void (*)(TIFF*))
			SDL_LoadFunction(lib.handle, "TIFFClose");
		if ( lib.TIFFClose == NULL ) {
			SDL_UnloadObject(lib.handle);
			return -1;
		}
		lib.TIFFGetField =
			(int (*)(TIFF*, ttag_t, ...))
			SDL_LoadFunction(lib.handle, "TIFFGetField");
		if ( lib.TIFFGetField == NULL ) {
			SDL_UnloadObject(lib.handle);
			return -1;
		}
		lib.TIFFReadRGBAImage =
			(int (*)(TIFF*, uint32, uint32, uint32*, int))
			SDL_LoadFunction(lib.handle, "TIFFReadRGBAImage");
		if ( lib.TIFFReadRGBAImage == NULL ) {
			SDL_UnloadObject(lib.handle);
			return -1;
		}
		lib.TIFFSetErrorHandler =
			(TIFFErrorHandler (*)(TIFFErrorHandler))
			SDL_LoadFunction(lib.handle, "TIFFSetErrorHandler");
		if ( lib.TIFFSetErrorHandler == NULL ) {
			SDL_UnloadObject(lib.handle);
			return -1;
		}
	}
	++lib.loaded;

	return 0;
}
예제 #26
0
int
WIN_GL_LoadLibrary(_THIS, const char *path)
{
    void *handle;

    if (path == NULL) {
        path = SDL_getenv("SDL_OPENGL_LIBRARY");
    }
    if (path == NULL) {
        path = DEFAULT_OPENGL;
    }
    _this->gl_config.dll_handle = SDL_LoadObject(path);
    if (!_this->gl_config.dll_handle) {
        return -1;
    }
    SDL_strlcpy(_this->gl_config.driver_path, path,
                SDL_arraysize(_this->gl_config.driver_path));

    /* Allocate OpenGL memory */
    _this->gl_data = (struct SDL_GLDriverData *) SDL_calloc(1, sizeof(struct SDL_GLDriverData));
    if (!_this->gl_data) {
        return SDL_OutOfMemory();
    }

    /* Load function pointers */
    handle = _this->gl_config.dll_handle;
    _this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
                                        SDL_LoadFunction(handle, "wglGetProcAddress");
    _this->gl_data->wglCreateContext = (HGLRC(WINAPI *) (HDC))
                                       SDL_LoadFunction(handle, "wglCreateContext");
    _this->gl_data->wglDeleteContext = (BOOL(WINAPI *) (HGLRC))
                                       SDL_LoadFunction(handle, "wglDeleteContext");
    _this->gl_data->wglMakeCurrent = (BOOL(WINAPI *) (HDC, HGLRC))
                                     SDL_LoadFunction(handle, "wglMakeCurrent");
    _this->gl_data->wglShareLists = (BOOL(WINAPI *) (HGLRC, HGLRC))
                                    SDL_LoadFunction(handle, "wglShareLists");

    if (!_this->gl_data->wglGetProcAddress ||
            !_this->gl_data->wglCreateContext ||
            !_this->gl_data->wglDeleteContext ||
            !_this->gl_data->wglMakeCurrent) {
        return SDL_SetError("Could not retrieve OpenGL functions");
    }

    return 0;
}
예제 #27
0
static int
LoadSNDIOLibrary(void)
{
    int retval = 0;
    if (sndio_handle == NULL) {
        sndio_handle = SDL_LoadObject(sndio_library);
        if (sndio_handle == NULL) {
            retval = -1;
            /* Don't call SDL_SetError(): SDL_LoadObject already did. */
        } else {
            retval = load_sndio_syms();
            if (retval < 0) {
                UnloadSNDIOLibrary();
            }
        }
    }
    return retval;
}
예제 #28
0
static BOOL
CE_SHFullScreen(HWND hwndRequester, DWORD dwState)
{
    if (SHFullScreen == 0 && aygshell_loaded == 0) {
        aygshell_loaded = 0;
        void *lib = SDL_LoadObject("aygshell.dll");
        if (lib) {
            SHFullScreen =
                (BOOL(WINAPI *) (HWND, DWORD)) SDL_LoadFunction(lib,
                                                                "SHFullScreen");
        }
    }

    if (SHFullScreen) {
        SHFullScreen(hwndRequester, dwState);
        //printf("SHFullscreen(%i)\n",dwState);
    }
}
예제 #29
0
static int
LoadALSALibrary(void)
{
    int retval = 0;
    if (alsa_handle == NULL) {
        alsa_handle = SDL_LoadObject(alsa_library);
        if (alsa_handle == NULL) {
            retval = -1;
            /* Don't call SDL_SetError(): SDL_LoadObject already did. */
        } else {
            retval = load_alsa_syms();
            if (retval < 0) {
                UnloadALSALibrary();
            }
        }
    }
    return retval;
}
예제 #30
0
static int LoadALSALibrary(void) {
	int i, retval = -1;

	alsa_handle = SDL_LoadObject(alsa_library);
	if (alsa_handle) {
		alsa_loaded = 1;
		retval = 0;
		for (i = 0; i < SDL_arraysize(alsa_functions); i++) {
			*alsa_functions[i].func = SDL_LoadFunction(alsa_handle,alsa_functions[i].name);
			if (!*alsa_functions[i].func) {
				retval = -1;
				UnloadALSALibrary();
				break;
			}
		}
	}
	return retval;
}