static gboolean
clutter_backend_sdl_post_parse (ClutterBackend  *backend,
                                GError         **error)
{
  int err;

  if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
    {
      g_set_error (error, CLUTTER_INIT_ERROR,
		   CLUTTER_INIT_ERROR_BACKEND,
		   "Unable to Initialize SDL");
      return FALSE;
    }

#if defined(WIN32)
  err = SDL_GL_LoadLibrary ("opengl32.dll");
#elif defined(__linux__) || defined(__FreeBSD__)
  err = SDL_GL_LoadLibrary ("libGL.so");
#else
#error Your platform is not supported
  err = 1;
#endif

  if (err != 0)
    {
      g_set_error (error, CLUTTER_INIT_ERROR,
		   CLUTTER_INIT_ERROR_BACKEND,
		   SDL_GetError ());
      return FALSE;
    }

  CLUTTER_NOTE (BACKEND, "SDL successfully initialized");

  return TRUE;
}
示例#2
0
文件: sdl_qgl.c 项目: Picmip/qfusion
/*
** QGL_Init
**
** This is responsible for binding our qgl function pointers to
** the appropriate GL stuff.  In Windows this means doing a
** LoadLibrary and a bunch of calls to GetProcAddress.  On other
** operating systems we need to do the right thing, whatever that
** might be.
**
*/
qgl_initerr_t QGL_Init( const char *dllname ) {
	int result = -1;

	glw_state.OpenGLLib = (void *)0;
	if( SDL_InitSubSystem( SDL_INIT_VIDEO ) < 0 ) {
		Com_Printf( "SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s", SDL_GetError() );
		return qgl_initerr_unknown;
	}

	// try the system default first
	result = SDL_GL_LoadLibrary( NULL );
	if( result == -1 ) {
		result = SDL_GL_LoadLibrary( dllname );
	}

	if( result == -1 ) {
		Com_Printf( "Error loading %s: %s\n", dllname ? dllname : "OpenGL dlib", SDL_GetError() );
		return qgl_initerr_invalid_driver;
	} else {
		glw_state.OpenGLLib = (void *)1;
		if( dllname ) {
			Com_Printf( "Using %s for OpenGL...\n", dllname );
		}
	}

#define QGL_FUNC( type, name, params )                                   \
	( q ## name ) = (void *)qglGetProcAddress( (const GLubyte *)#name );   \
	if( !( q ## name ) ) {                                                 \
		Com_Printf( "QGL_Init: Failed to get address for %s\n", #name ); \
		return qgl_initerr_invalid_driver;                               \
	}
#define QGL_FUNC_OPT( type, name, params ) ( q ## name ) = (void *)qglGetProcAddress( (const GLubyte *)#name );
#define QGL_EXT( type, name, params ) ( q ## name ) = NULL;
#define QGL_WGL( type, name, params )
#define QGL_WGL_EXT( type, name, params )
#define QGL_GLX( type, name, params )
#define QGL_GLX_EXT( type, name, params )
#define QGL_EGL( type, name, params )
#define QGL_EGL_EXT( type, name, params )

#include "../ref_gl/qgl.h"

#undef QGL_EGL_EXT
#undef QGL_EGL
#undef QGL_GLX_EXT
#undef QGL_GLX
#undef QGL_WGL_EXT
#undef QGL_WGL
#undef QGL_EXT
#undef QGL_FUNC_OPT
#undef QGL_FUNC

	qglGetGLWExtensionsString = _qglGetGLWExtensionsString;

	return qgl_initerr_ok;
}
示例#3
0
文件: sdl.c 项目: BruceJawn/FlashNES
	int main(int argc, char *argv[])
	#endif
	{
			FCEUD_Message("\nStarting FCE Ultra "FCEU_VERSION"...\n");

			#ifdef WIN32
			/* Taken from win32 sdl_main.c */
			SDL_SetModuleHandle(GetModuleHandle(NULL));
			#endif

		if(SDL_Init(SDL_INIT_VIDEO)) /* SDL_INIT_VIDEO Needed for (joystick config) event processing? */
		{
		 printf("Could not initialize SDL: %s.\n", SDL_GetError());
		 return(-1);
		}

		#ifdef OPENGL
		 #ifdef APPLEOPENGL
		 sdlhaveogl = 1;	/* Stupid something...  Hack. */
		 #else
		 if(!SDL_GL_LoadLibrary(0)) sdlhaveogl=1;
		 else sdlhaveogl=0;
		 #endif
		#endif

		SetDefaults();

		{
		 int ret=CLImain(argc,argv);
		 SDL_Quit();
		 return(ret?0:-1);
		}
	}
void initSDL()
{
	SDL_DisplayMode video_info;
	int init_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK;

	if(SDL_Init(init_flags) < 0)
	{
		printf("SDL Failed to Init!!!! (%s)\n", SDL_GetError());
		borExit(0);
	}
	SDL_ShowCursor(SDL_DISABLE);
	atexit(SDL_Quit);

#ifdef LOADGL
	if(SDL_GL_LoadLibrary(NULL) < 0)
	{
		printf("Warning: couldn't load OpenGL library (%s)\n", SDL_GetError());
	}
#endif

	SDL_GetCurrentDisplayMode(0, &video_info);
	nativeWidth = video_info.w;
	nativeHeight = video_info.h;
	printf("debug:nativeWidth, nativeHeight, bpp, Hz  %d, %d, %d, %d\n", nativeWidth, nativeHeight, SDL_BITSPERPIXEL(video_info.format), video_info.refresh_rate);

	SDL_initFramerate(&framerate_manager);
	SDL_setFramerate(&framerate_manager, 200);
}
示例#5
0
static SDL_bool
load_glproc()
{
    static int init=0;
    CONF_ITEM *cf_libgl=cf_get_item_by_name("libglpath");
    if (init) return SDL_TRUE;
    init=1;
    if (SDL_GL_LoadLibrary(CF_STR(cf_libgl))==-1) {
        printf("Unable to load OpenGL library: %s\n", CF_STR(cf_libgl));
        return SDL_FALSE;
    }
	
    pglClearColor	= SDL_GL_GetProcAddress("glClearColor");
    pglClear		= SDL_GL_GetProcAddress("glClear");
    pglEnable		= SDL_GL_GetProcAddress("glEnable");
    pglViewport		= SDL_GL_GetProcAddress("glViewport");
    pglTexParameteri	= SDL_GL_GetProcAddress("glTexParameteri");
    pglPixelStorei	= SDL_GL_GetProcAddress("glPixelStorei");
    pglTexImage2D	= SDL_GL_GetProcAddress("glTexImage2D");
    pglBegin		= SDL_GL_GetProcAddress("glBegin");
    pglEnd		= SDL_GL_GetProcAddress("glEnd");
    pglTexCoord2f	= SDL_GL_GetProcAddress("glTexCoord2f");
    pglVertex2f		= SDL_GL_GetProcAddress("glVertex2f");
	
    return SDL_TRUE;
}
示例#6
0
int draw13_init(running_machine &machine, sdl_draw_info *callbacks)
{
	const char *stemp;

	// fill in the callbacks
	callbacks->exit = draw13_exit;
	callbacks->attach = draw13_attach;

	mame_printf_verbose("Using SDL native texturing driver (SDL 2.0+)\n");

	expand_copy_info(blit_info_default);
	//FIXME: -opengl16 should be -opengl -prefer16bpp
	//if (video_config.prefer16bpp_tex)
	expand_copy_info(blit_info_16bpp);

	// Load the GL library now - else MT will fail

	stemp = downcast<sdl_options &>(machine.options()).gl_lib();
	if (stemp != NULL && strcmp(stemp, SDLOPTVAL_AUTO) == 0)
		stemp = NULL;

	// No fatalerror here since not all video drivers support GL !
	if (SDL_GL_LoadLibrary(stemp) != 0) // Load library (default for e==NULL
		mame_printf_verbose("Warning: Unable to load opengl library: %s\n", stemp ? stemp : "<default>");
	else
		mame_printf_verbose("Loaded opengl shared library: %s\n", stemp ? stemp : "<default>");

	return 0;
}
示例#7
0
int main(int argc, char **argv)
{
    int retval = 1;

    #if 0
    printf("MojoShader availableprofile\n");
    printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET);
    printf("Linked against changeset %s\n", MOJOSHADER_changeset());
    printf("\n");
    #endif

    if (SDL_Init(SDL_INIT_VIDEO) == -1)
        fprintf(stderr, "SDL_Init(SDL_INIT_VIDEO) error: %s\n", SDL_GetError());
    else
    {
        SDL_GL_LoadLibrary(NULL);
        if (SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL)
            fprintf(stderr, "SDL_SetVideoMode() error: %s\n", SDL_GetError());
        else
            retval = check_available();
        SDL_Quit();
    } // else

    return retval;
} // main
示例#8
0
文件: sdlstub.c 项目: AliSayed/MoSync
int main(int argc, char *argv[])
{
	(void) argc;
	(void) argv;

	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
	{
		fprintf(stderr, "SDL error: %s\n", SDL_GetError());
		return 1;
	}
	atexit(SDL_Quit);

	{
		int err;
#if defined(WIN32)
		err = SDL_GL_LoadLibrary("opengl32.dll");
#elif defined(__linux__) || defined(__FreeBSD__)
		err = SDL_GL_LoadLibrary("libGL.so");
#else
#error Your platform is not supported
		err = 1;
#endif
		if (err != 0)
		{
			fprintf(stderr, "Can't load OpenGL library: %s\n", SDL_GetError());
			return 1;
		}
	}

	SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 0);
	SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 0);
	SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 0);
	SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0);

	if (SDL_SetVideoMode(600, 600, 0, SDL_OPENGL) == NULL)
	{
		fprintf(stderr, "SDL error: %s\n", SDL_GetError());
		return 1;
	}

	_dgles_load_library(NULL, proc_loader);

	SDL_WM_SetCaption("Desktop OpenGL ES", NULL);

	return test();
}
示例#9
0
boolean LoadGL(void)
{
#ifndef STATIC_OPENGL
	const char *OGLLibname = NULL;
	const char *GLULibname = NULL;

	if (M_CheckParm ("-OGLlib") && M_IsNextParm())
		OGLLibname = M_GetNextParm();

	if (SDL_GL_LoadLibrary(OGLLibname) != 0)
	{
		DEBPRINT(va("Could not load OpenGL Library: %s\n"
					"Falling back to Software mode.\n", SDL_GetError()));
		if (!M_CheckParm ("-OGLlib"))
			DEBPRINT("If you know what is the OpenGL library's name, use -OGLlib\n");
		return 0;
	}

#if 0
	GLULibname = "/proc/self/exe";
#elif defined (_WIN32)
	GLULibname = "GLU32.DLL";
#elif defined (__MACH__)
	GLULibname = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib";
#elif defined (macintos)
	GLULibname = "OpenGLLibrary";
#elif defined (__unix__)
	GLULibname = "libGLU.so.1";
#elif defined (__HAIKU__)
	GLULibname = "libGLU.so";
#else
	GLULibname = NULL;
#endif

	if (M_CheckParm ("-GLUlib") && M_IsNextParm())
		GLULibname = M_GetNextParm();

	if (GLULibname)
	{
		GLUhandle = hwOpen(GLULibname);
		if (GLUhandle)
			return SetupGLfunc();
		else
		{
			DEBPRINT(va("Could not load GLU Library: %s\n", GLULibname));
			if (!M_CheckParm ("-GLUlib"))
				DEBPRINT("If you know what is the GLU library's name, use -GLUlib\n");
		}
	}
	else
	{
		DEBPRINT("Could not load GLU Library\n");
		DEBPRINT("If you know what is the GLU library's name, use -GLUlib\n");
	}
#endif
	return SetupGLfunc();
}
示例#10
0
boolean LoadGL(void)
{
	const char *OGLLibname = NULL;
	const char *GLULibname = NULL;

	if (M_CheckParm ("-OGLlib") && M_IsNextParm())
		OGLLibname = M_GetNextParm();

	if (SDL_GL_LoadLibrary(OGLLibname) != 0)
	{
		I_OutputMsg("Could not load OpenGL Library: %s\n", SDL_GetError());
		I_OutputMsg("falling back to Software mode\n");
		if (!M_CheckParm ("-OGLlib"))
			I_OutputMsg("if you know what is the OpenGL library's name, use -OGLlib\n");
		return 0;
	}

#if 0
	GLULibname = "/proc/self/exe";
#elif defined (_WIN32)
	GLULibname = "GLU32.DLL";
#elif defined (__MACH__)
	GLULibname = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib";
#elif defined (macintos)
	GLULibname = "OpenGLLibrary";
#elif defined (__unix__) || defined (__HAIKU__)
	GLULibname = "libGLU.so";
#else
	GLULibname = NULL;
#endif

	if (M_CheckParm ("-GLUlib") && M_IsNextParm())
		GLULibname = M_GetNextParm();

	if (GLULibname)
	{
		GLUhandle = hwOpen(GLULibname);
		if (GLUhandle)
			return SetupGLfunc();
		else
		{
			I_OutputMsg("Could not load GLU Library: %s\n", GLULibname);
			I_OutputMsg("falling back to Software mode\n");
			if (!M_CheckParm ("-GLUlib"))
				I_OutputMsg("if you know what is the GLU library's name, use -GLUlib\n");
		}
	}
	else
	{
		I_OutputMsg("Please fill a bug report to tell SRB2 where to find the default GLU library for this unknown OS\n");
		I_OutputMsg("falling back to Software mode\n");
		I_OutputMsg("if you know what is the GLU library's name, use -GLUlib\n");
	}
	return 0;
}
示例#11
0
BOOL CGfxLibrary::InitDriver_OGL(BOOL init3dfx)
{
  ASSERT( gl_hiDriver==NONE);  // this is managed inside SDL, so we never load a library ourselves.

  if (SDL_GL_LoadLibrary(NULL) == -1) {
    sdlCheckError(0, "Failed to load OpenGL API");
    return FALSE;
  }

  // done
  return TRUE;
}
示例#12
0
/*
==================
R_Init_OpenGL
==================
*/
qboolean R_Init_OpenGL( void )
{
	GL_SetupAttributes();
#ifdef XASH_SDL
	if( SDL_GL_LoadLibrary( NULL ) )
	{
		MsgDev( D_ERROR, "Couldn't initialize OpenGL: %s\n", SDL_GetError());
		return false;
	}
#endif
	return VID_SetMode();
}
示例#13
0
/*
==================
R_Init_OpenGL
==================
*/
qboolean R_Init_OpenGL( void )
{
	GL_SetupAttributes();

	if( SDL_GL_LoadLibrary( EGL_LIB ) )
	{
		MsgDev( D_ERROR, "Couldn't initialize OpenGL: %s\n", SDL_GetError());
		return false;
	}

	return VID_SetMode();
}
示例#14
0
   bool OpenGLDLLInit()
   {
      OpenGLDLLShutdown();

      // load libGL.so
      if (SDL_GL_LoadLibrary("libGL.so") == -1 &&
         SDL_GL_LoadLibrary("libGL.so.1") == -1)
      {
         Con::errorf("Error loading GL library: %s", SDL_GetError());
         return false;
      }

      // bind functions
      if (!bindGLFunctions())
      {
         Con::errorf("Error binding GL functions");
         OpenGLDLLShutdown();
         return false;
      }

      return true;
   }
示例#15
0
void AndroidPreCreateWindow() {
  // Apply scaler setting prior creating surface
  if (g_android_scaler_resolution.x() && g_android_scaler_resolution.y()) {
    // Initialize OpenGL function pointers inside SDL
    if (SDL_GL_LoadLibrary(NULL) < 0) {
      SDL_LogError(SDL_LOG_CATEGORY_ERROR,
                   "couldn't initialize OpenGL library\n");
    }

    // Hook eglCreateWindowSurface call
    SDL_VideoDevice* device = SDL_GetVideoDevice();
    device->egl_data->eglCreateWindowSurface = HookEglCreateWindowSurface;
  }
}
示例#16
0
Renderer::Renderer(int w, int h,const char* caption) : gfx(1024), 
	windowed_w(w), windowed_h(h){
	if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0){
		fprintf(stderr, "Video error: %s\n", SDL_GetError());
		exit(1);
	}
	SDL_GL_LoadLibrary(NULL);
	SDL_WM_SetCaption(caption, NULL);
	
	fullscreen_w = SDL_GetVideoInfo()->current_w;
	fullscreen_h = SDL_GetVideoInfo()->current_h;
	
	reload(w, h, SDL_OPENGL | SDL_ANYFORMAT);
	SDL_Delay(200);
}
示例#17
0
int main(int argc, char **argv)
{
    //printf("MojoShader finderrors\n");
    //printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET);
    //printf("Linked against changeset %s\n", MOJOSHADER_changeset());
    //printf("\n");

    if (argc <= 2)
        printf("\n\nUSAGE: %s <profile> [dir1] ... [dirN]\n\n", argv[0]);
    else
    {
        int total = 0;
        int i;
        const char *profile = argv[1];

        #if FINDERRORS_COMPILE_SHADERS
        SDL_Init(SDL_INIT_VIDEO);
        SDL_GL_LoadLibrary(NULL);
        SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
        printf("Best profile is '%s'\n", MOJOSHADER_glBestProfile(lookup, 0));
        MOJOSHADER_glContext *ctx;
        ctx = MOJOSHADER_glCreateContext(profile, lookup, 0, 0, 0, 0);
        if (ctx == NULL)
        {
            printf("MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError());
            SDL_Quit();
            return 1;
        } // if
        MOJOSHADER_glMakeContextCurrent(ctx);
        #endif

        for (i = 2; i < argc; i++)
            total += do_dir(argv[i], profile);

        printf("Saw %d files.\n", total);

        #if FINDERRORS_COMPILE_SHADERS
        MOJOSHADER_glDestroyContext(ctx);
        SDL_Quit();
        #endif
    } // else

    return 0;
} // main
示例#18
0
文件: draw13.cpp 项目: bradhugh/mame
// FIXME: machine only used to access options.
void renderer_sdl2::init(running_machine &machine)
{
	osd_printf_verbose("Using SDL native texturing driver (SDL 2.0+)\n");

#if USE_OPENGL
	// Load the GL library now - else MT will fail
	const char *stemp = downcast<sdl_options &>(machine.options()).gl_lib();
#else
	const char *stemp = nullptr;
#endif
	if (stemp != nullptr && strcmp(stemp, OSDOPTVAL_AUTO) == 0)
		stemp = nullptr;

	// No fatalerror here since not all video drivers support GL !
	if (SDL_GL_LoadLibrary(stemp) != 0) // Load library (default for e==nullptr
		osd_printf_warning("Warning: Unable to load opengl library: %s\n", stemp ? stemp : "<default>");
	else
		osd_printf_verbose("Loaded opengl shared library: %s\n", stemp ? stemp : "<default>");
}
示例#19
0
int
FB_CreateWindow(_THIS, SDL_Window * window)
{
    SDL_WindowData *wdata;
    SDL_VideoDisplay *display;

    /* Allocate window internal data */
    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
    if (wdata == NULL) {
        return SDL_OutOfMemory();
    }
    display = SDL_GetDisplayForWindow(window);

    /* Windows have one size for now */
    window->w = display->desktop_mode.w;
    window->h = display->desktop_mode.h;

    /* OpenGL ES is the law here, buddy */
    window->flags |= SDL_WINDOW_OPENGL;

    if (!_this->egl_data) {
        if (SDL_GL_LoadLibrary(NULL) < 0) {
            return -1;
        }
    }

    wdata->egl_surface = SDL_EGL_CreateSurface(_this, 0);
    if (wdata->egl_surface == EGL_NO_SURFACE) {
        return SDL_SetError("Could not create GLES window surface");
    }

    /* Setup driver data for this window */
    window->driverdata = wdata;

    /* One window, it always has focus */
    SDL_SetMouseFocus(window);
    SDL_SetKeyboardFocus(window);

    /* Window has been successfully created */
    return 0;
}
示例#20
0
void gl_InitOpenGL() {
	SDL_Surface *screen_surface;

	if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1)<0)	// page-flipping needs double buffering
	{
		printf("Unable to set GL attribute : %s\n",SDL_GetError());
		exit(1);
	}
	
	if (SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,1)<0)	// enable page-flipping
	{
		printf("Unable to set GL attribute : %s\n",SDL_GetError());
		exit(1);
	}
	
	if (SDL_GL_LoadLibrary(NULL)<0)
	{
		printf("Unable to dynamically open GL lib : %s\n",SDL_GetError());
		exit(1);
	}
	
	if (FullScreen) 
		screen_surface = SDL_SetVideoMode(0, 0, 0, SDL_OPENGL|SDL_FULLSCREEN);
	else
		screen_surface = SDL_SetVideoMode(640, 512, 0, SDL_OPENGL);

	if (screen_surface == NULL)
	{
		printf("Unable to open video mode : %s\n",SDL_GetError());
		SDL_Quit();
		exit(1);
	}

	screen_width = screen_surface->w;
	screen_height = screen_surface->h;
		
	init_glfuncs();
}
示例#21
0
文件: gl3_sdl.c 项目: yquake2/yquake2
/*
 * This function returns the flags used at the SDL window
 * creation by GLimp_InitGraphics(). In case of error -1
 * is returned.
 */
int GL3_PrepareForWindow(void)
{
	// Mkay, let's try to load the libGL,
	const char *libgl;
	cvar_t *gl3_libgl = ri.Cvar_Get("gl3_libgl", "", CVAR_ARCHIVE);

	if (strlen(gl3_libgl->string) == 0)
	{
		libgl = NULL;
	}
	else
	{
		libgl = gl3_libgl->string;
	}

	while (1)
	{
		if (SDL_GL_LoadLibrary(libgl) < 0)
		{
			if (libgl == NULL)
			{
				ri.Sys_Error(ERR_FATAL, "Couldn't load libGL: %s!", SDL_GetError());

				return -1;
			}
			else
			{
				R_Printf(PRINT_ALL, "Couldn't load libGL: %s!\n", SDL_GetError());
				R_Printf(PRINT_ALL, "Retrying with default...\n");

				ri.Cvar_Set("gl3_libgl", "");
				libgl = NULL;
			}
		}
		else
		{
			break;
		}
	}

	// Set GL context attributs bound to the window.
	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_DEPTH_SIZE, 24);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	if (SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8) == 0)
	{
		gl3config.stencil = true;
	}
	else
	{
		gl3config.stencil = false;
	}

	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

	// Set GL context flags.
	int contextFlags = SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG;

	if (gl3_debugcontext && gl3_debugcontext->value)
	{
		contextFlags |= SDL_GL_CONTEXT_DEBUG_FLAG;
	}

	if (contextFlags != 0)
	{
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextFlags);
	}

	// Let's see if the driver supports MSAA.
	int msaa_samples = 0;

	if (gl_msaa_samples->value)
	{
		msaa_samples = gl_msaa_samples->value;

		if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) < 0)
		{
			R_Printf(PRINT_ALL, "MSAA is unsupported: %s\n", SDL_GetError());

			ri.Cvar_SetValue ("gl_msaa_samples", 0);

			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
		}
		else if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa_samples) < 0)
		{
			R_Printf(PRINT_ALL, "MSAA %ix is unsupported: %s\n", msaa_samples, SDL_GetError());

			ri.Cvar_SetValue("gl_msaa_samples", 0);

			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
		}
	}
	else
	{
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
	}

	return SDL_WINDOW_OPENGL;
}
示例#22
0
int
RPI_CreateWindow(_THIS, SDL_Window * window)
{
    SDL_WindowData *wdata;
    SDL_VideoDisplay *display;
    SDL_DisplayData *displaydata;
    VC_RECT_T dst_rect;
    VC_RECT_T src_rect;
    VC_DISPMANX_ALPHA_T         dispman_alpha;
    DISPMANX_UPDATE_HANDLE_T dispman_update;

    /* Disable alpha, otherwise the app looks composed with whatever dispman is showing (X11, console,etc) */
    dispman_alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS; 
    dispman_alpha.opacity = 0xFF; 
    dispman_alpha.mask = 0;

    /* Allocate window internal data */
    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
    if (wdata == NULL) {
        return SDL_OutOfMemory();
    }
    display = SDL_GetDisplayForWindow(window);
    displaydata = (SDL_DisplayData *) display->driverdata;

    /* Windows have one size for now */
    window->w = display->desktop_mode.w;
    window->h = display->desktop_mode.h;

    /* OpenGL ES is the law here, buddy */
    window->flags |= SDL_WINDOW_OPENGL;

    /* Create a dispman element and associate a window to it */
    dst_rect.x = 0;
    dst_rect.y = 0;
    dst_rect.width = window->w;
    dst_rect.height = window->h;

    src_rect.x = 0;
    src_rect.y = 0;
    src_rect.width = window->w << 16;
    src_rect.height = window->h << 16;

    dispman_update = vc_dispmanx_update_start( 0 );
    wdata->dispman_window.element = vc_dispmanx_element_add ( dispman_update, displaydata->dispman_display, SDL_RPI_VIDEOLAYER /* layer */, &dst_rect, 0/*src*/, &src_rect, DISPMANX_PROTECTION_NONE, &dispman_alpha /*alpha*/, 0/*clamp*/, 0/*transform*/);
    wdata->dispman_window.width = window->w;
    wdata->dispman_window.height = window->h;
    vc_dispmanx_update_submit_sync( dispman_update );
    
    if (!_this->egl_data) {
        if (SDL_GL_LoadLibrary(NULL) < 0) {
            return -1;
        }
    }
    wdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) &wdata->dispman_window);

    if (wdata->egl_surface == EGL_NO_SURFACE) {
        return SDL_SetError("Could not create GLES window surface");
    }

    /* Setup driver data for this window */
    window->driverdata = wdata;
    
    /* One window, it always has focus */
    SDL_SetMouseFocus(window);
    SDL_SetKeyboardFocus(window);

    /* Window has been successfully created */
    return 0;
}
static void PlatformInitOpenGL(void*& ContextPtr, void*& PrevContextPtr, int InMajorVersion, int InMinorVersion)
{
	static bool bInitialized = (SDL_GL_GetCurrentWindow() != NULL) && (SDL_GL_GetCurrentContext() != NULL);

	if (!bInitialized)
	{
		check(InMajorVersion > 3 || (InMajorVersion == 3 && InMinorVersion >= 2));
		if (SDL_WasInit(0) == 0)
		{
			SDL_Init(SDL_INIT_VIDEO);
		}
		else
		{
			Uint32 InitializedSubsystemsMask = SDL_WasInit(SDL_INIT_EVERYTHING);
			if ((InitializedSubsystemsMask & SDL_INIT_VIDEO) == 0)
			{
				SDL_InitSubSystem(SDL_INIT_VIDEO);
			}
		}

		if (SDL_GL_LoadLibrary(NULL))
		{
			UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("Unable to dynamically load libGL: %s"), ANSI_TO_TCHAR(SDL_GetError()));
		}

		if	(SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, InMajorVersion))
		{
			UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("Failed to set GL major version: %s"), ANSI_TO_TCHAR(SDL_GetError()));
		}

		if	(SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, InMinorVersion))
		{
			UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("Failed to set GL minor version: %s"), ANSI_TO_TCHAR(SDL_GetError()));
		}

		if	(SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG))
		{
			UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("Failed to set GL flags: %s"), ANSI_TO_TCHAR(SDL_GetError()));
		}

		if	(SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE))
		{
			UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("Failed to set GL mask/profile: %s"), ANSI_TO_TCHAR(SDL_GetError()));
		}

		// Create a dummy context to verify opengl support.
		FPlatformOpenGLContext DummyContext;
		_PlatformCreateDummyGLWindow(&DummyContext);
		_PlatformCreateOpenGLContextCore(&DummyContext);

		if (DummyContext.hGLContext)
		{
			_ContextMakeCurrent(DummyContext.hWnd, DummyContext.hGLContext);
		}
		else
		{
			UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("OpenGL %d.%d not supported by driver"), InMajorVersion, InMinorVersion);
			return;
		}

		PrevContextPtr = NULL;
		ContextPtr = DummyContext.hGLContext;
		bInitialized = true;
	}

	PrevContextPtr = reinterpret_cast<void*>(SDL_GL_GetCurrentContext());
	SDL_HGLContext NewContext = SDL_GL_CreateContext(SDL_GL_GetCurrentWindow());
	SDL_GL_MakeCurrent(SDL_GL_GetCurrentWindow(), NewContext);
	ContextPtr = reinterpret_cast<void*>(NewContext);
}
示例#24
0
/*! initializes the engine in console + graphical mode
 */
void engine::init(const char* ico) {
	engine::mode = engine::GRAPHICAL;
	m->print(msg::MDEBUG, "engine.cpp", "initializing albion 2 engine in console + graphical mode");

	// initialize sdl
	atexit(SDL_Quit);
	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) == -1) {
		m->print(msg::MERROR, "engine.cpp", "can't init SDL: %s", SDL_GetError());
		exit(1);
	}
	else {
		m->print(msg::MDEBUG, "engine.cpp", "sdl initialized");
	}

	// load opengl library
	SDL_GL_LoadLibrary(NULL);

	// get video info
	video_info = SDL_GetVideoInfo();
	if(!video_info) {
		m->print(msg::MDEBUG, "engine.cpp", "video query failed: %s", SDL_GetError());
		exit(1);
	}

	// not working any more?
	//m->print(msg::MDEBUG, "engine.cpp", "amount of available video memory: %u kb", video_info->video_mem);

	// set some flags
	engine::flags |= SDL_HWPALETTE;
	engine::flags |= SDL_OPENGL;
	engine::flags |= SDL_DOUBLEBUF;
	/*if(video_info->hw_available) {
		//engine::flags |= SDL_HWSURFACE;
		m->print(msg::MDEBUG, "engine.cpp", "using hardware surface");
	}
	else {
		//engine::flags |= SDL_SWSURFACE;
		m->print(msg::MDEBUG, "engine.cpp", "using software surface");
	}*/
	engine::flags |= SDL_HWSURFACE;

	if(fullscreen) {
		engine::flags |= SDL_FULLSCREEN;
		m->print(msg::MDEBUG, "engine.cpp", "fullscreen enabled");
	}
	else {
		m->print(msg::MDEBUG, "engine.cpp", "fullscreen disabled");
	}
	engine::flags |= SDL_HWACCEL;

	// gl attributes
	switch(depth) {
		case 16:
			SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
			SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
			SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
			break;
		case 24:
			SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
			SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
			SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
			break;
		case 32:
			SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
			SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
			SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
			break;
		default:
			if(depth < 16) {
				m->print(msg::MERROR, "engine.cpp", "init(): to low depth, please use at least a depth of 16bit!");
				return;
			}
			else { // depth > 16
				m->print(msg::MERROR, "engine.cpp", "init(): unknown depth of %ubit! engine will run in 16bit mode!", depth);
				depth = 16;
				SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
				SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
				SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
			}
			break;
	}

	SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, depth);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, zbuffer);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencil);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

	// ... load icon before SDL_SetVideoMode
	if(ico != NULL) load_ico(ico);

	// create screen
	engine::height = height;
	engine::width = width;
	engine::depth = depth;
	screen = SDL_SetVideoMode(width, height, depth, flags);
	if(screen == NULL) {
		m->print(msg::MERROR, "engine.cpp", "can't set video mode: %s", SDL_GetError());
		exit(1);
	}
	else {
		m->print(msg::MDEBUG, "engine.cpp", "video mode set: w%u h%u d%u", width,
			height, depth);
	}

	int tmp = 0;
	SDL_GL_GetAttribute(SDL_GL_BUFFER_SIZE, &tmp);
	m->print(msg::MDEBUG, "engine.cpp", "color depth set to %d bits", tmp);
	SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &tmp);
	m->print(msg::MDEBUG, "engine.cpp", "z buffer set to %d bits", tmp);
	SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &tmp);
	m->print(msg::MDEBUG, "engine.cpp", "stencil buffer set to %d bits", tmp);
	SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &tmp);
	m->print(msg::MDEBUG, "engine.cpp", "double buffering %s", tmp == 1 ? "enabled" : "disabled");

	g->set_surface(screen);

	// print out some opengl informations
	m->print(msg::MDEBUG, "engine.cpp", "vendor: %s", glGetString(GL_VENDOR));
	m->print(msg::MDEBUG, "engine.cpp", "renderer: %s", glGetString(GL_RENDERER));
	m->print(msg::MDEBUG, "engine.cpp", "version: %s", glGetString(GL_VERSION));

	// enable key repeat
	if((SDL_EnableKeyRepeat(key_repeat, SDL_DEFAULT_REPEAT_INTERVAL))) {
		m->print(msg::MDEBUG, "engine.cpp", "setting keyboard repeat failed: %s",
				SDL_GetError());
		exit(1);
	}
	else {
		m->print(msg::MDEBUG, "engine.cpp", "keyboard repeat set");
	}

	// initialize ogl
	init_gl();
	m->print(msg::MDEBUG, "engine.cpp", "opengl initialized");

	// resize stuff
	resize_window();

	// reserve memory for position and rotation ...
	engine::position = new vertex3();
	engine::rotation = new vertex3();

	// create extension class object
	exts = new ext(engine::mode, m);

	// set flip state of core class to true if fbos are supported
	if(exts->is_fbo_support()) {
		c->set_flip(true);
	}

	// create render to texture object
	r = new rtt(m, c, g, exts, screen->w, screen->h);

	// print out informations about additional threads
	omp_set_num_threads(thread_count);
	thread_count = omp_get_max_threads();
	thread_count == 1 ? m->print(msg::MDEBUG, "engine.cpp", "using one single thread!") :
		m->print(msg::MDEBUG, "engine.cpp", "using %u threads!", thread_count);

	// if GL_RENDERER is that damn m$ gdi driver, exit a2e ...
	// no official support for this crappy piece of software ...
	if(strcmp((const char*)glGetString(GL_RENDERER), "GDI Generic") == 0) {
		m->print(msg::MERROR, "engine.cpp", "A2E doesn't support the MS GDI Generic driver!\nGo and install one of these (that match your grapic card):\nhttp://www.ati.com  http://www.nvidia.com  http://www.matrox.com  http://www.3dlabs.com http://www.intel.com");
		SDL_Delay(10000);
		exit(1);
	}

	// set standard texture filtering
	t->set_filtering(engine::filtering);

	// check if hdrr is technically possible
	if(hdr && !exts->is_shader_support() && !exts->is_fbo_support()) {
		hdr = false;
	}
	m->print(msg::MDEBUG, "engine.cpp", "HDR-Rendering is %s!", (hdr ? "enabled" : "disabled"));
}
示例#25
0
void Engine_InitSDLVideo()
{
    Uint32 video_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS;

    if(screen_info.FS_flag)
    {
        video_flags |= SDL_WINDOW_FULLSCREEN;
    }
    else
    {
        video_flags |= (SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
    }

    ///@TODO: is it really needede for correct work?
    if(SDL_GL_LoadLibrary(NULL) < 0)
    {
        Sys_Error("Could not init OpenGL driver");
    }

    // Check for correct number of antialias samples.
    if(renderer.settings().antialias)
    {
        /* Request opengl 3.2 context. */
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
        /* I do not know why, but settings of this temporary window (zero position / size) are applied to the main window, ignoring screen settings */
        sdl_window     = SDL_CreateWindow(NULL, screen_info.x, screen_info.y, screen_info.w, screen_info.h, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
        sdl_gl_context = SDL_GL_CreateContext(sdl_window);
        SDL_GL_MakeCurrent(sdl_window, sdl_gl_context);

        GLint maxSamples = 0;
        glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
        maxSamples = (maxSamples > 16)?(16):(maxSamples);   // Fix for faulty GL max. sample number.

        if(renderer.settings().antialias_samples > maxSamples)
        {
            if(maxSamples == 0)
            {
                renderer.settings().antialias = 0;
                renderer.settings().antialias_samples = 0;
                Sys_DebugLog(LOG_FILENAME, "InitSDLVideo: can't use antialiasing");
            }
            else
            {
                renderer.settings().antialias_samples = maxSamples;   // Limit to max.
                Sys_DebugLog(LOG_FILENAME, "InitSDLVideo: wrong AA sample number, using %d", maxSamples);
            }
        }

        SDL_GL_DeleteContext(sdl_gl_context);
        SDL_DestroyWindow(sdl_window);

        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, renderer.settings().antialias);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, renderer.settings().antialias_samples);
    }
    else
    {
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
    }

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, renderer.settings().z_depth);
#if STENCIL_FRUSTUM
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
#endif
    // set the opengl context version
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

    sdl_window = SDL_CreateWindow("OpenTomb", screen_info.x, screen_info.y, screen_info.w, screen_info.h, video_flags);
    sdl_gl_context = SDL_GL_CreateContext(sdl_window);
    assert(sdl_gl_context);
    SDL_GL_MakeCurrent(sdl_window, sdl_gl_context);

    ConsoleInfo::instance().addLine((const char*)glGetString(GL_VENDOR), FONTSTYLE_CONSOLE_INFO);
    ConsoleInfo::instance().addLine((const char*)glGetString(GL_RENDERER), FONTSTYLE_CONSOLE_INFO);
    std::string version = "OpenGL version ";
    version += (const char*)glGetString(GL_VERSION);
    ConsoleInfo::instance().addLine(version, FONTSTYLE_CONSOLE_INFO);
    ConsoleInfo::instance().addLine((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION), FONTSTYLE_CONSOLE_INFO);
}
示例#26
0
SDL_Surface* OpenGLPlugin::OpenGLInit(int w,int h, int bpp, bool fs, int glScanline)
{
	_GLScanlines = glScanline;

#ifdef _WIN32
	const char *gl_library = "OpenGL32.DLL";
#else
	const char *gl_library = "libGL.so.1";
#endif
	int surface_bpp;
	
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	if (SDL_GL_LoadLibrary(gl_library)<0)
	{
		fprintf(stderr,"Unable to dynamically open GL lib : %s\n",SDL_GetError());
		return NULL;
	}
	
	if (!fs)
	{
		w=CPCVisibleSCRWidth*2;
		h=CPCVisibleSCRHeight*2;
	}
	_video=SDL_SetVideoMode(w,h,0,SDL_OPENGL | (fs?SDL_FULLSCREEN:0));
	if (!_video)
	{
		fprintf(stderr, "Could not set requested video mode: %s\n", SDL_GetError());
		return NULL;
	}
	if (init_glfuncs()!=0)
	{
		fprintf(stderr, "Cannot init OpenGL functions: %s\n", SDL_GetError());
		return NULL;
	}
	
	int major, minor;
	const char *version;
	version = (char *) eglGetString(GL_VERSION); 
	if (sscanf(version, "%d.%d", &major, &minor) != 2) {
		fprintf(stderr, "Unable to get OpenGL version\n");
		return NULL;
	}
	
	GLint max_texsize;
	eglGetIntegerv(GL_MAX_TEXTURE_SIZE,&max_texsize);
	if (max_texsize<512) {
		fprintf(stderr, "Your OpenGL implementation doesn't support 512x512 textures\n");
		return NULL;
	}
	
	// We have to react differently to the bpp parameter than with software rendering
	// Here are the rules :
	// for 8bpp OpenGL, we need the GL_EXT_paletted_texture extension
	// for 16bpp OpenGL, we need OpenGL 1.2+
	// for 24bpp reversed OpenGL, we need OpenGL 1.2+
	surface_bpp=0;
	switch(bpp)
	{
	case 8:
		surface_bpp = (HaveOpenGLExtension("GL_EXT_paletted_texture"))?8:0;
		break;
	case 15:
	case 16:
		surface_bpp = ((major>1)||(major == 1 && minor >= 2))?16:0;
		break;
	case 24:
		surface_bpp = ((major>1)||(major == 1 && minor >= 2))?24:0;
	case 32:
		surface_bpp = ((major>1)||(major == 1 && minor >= 2))?32:0;
	default:
		surface_bpp = ((major>1)||(major == 1 && minor >= 2))?32:0;
		break;
	}
	if (surface_bpp==0) {
		fprintf(stderr, "Your OpenGL implementation doesn't support %dbpp textures\n",surface_bpp);
		return NULL;
	}
	
	eglDisable(GL_FOG);
	eglDisable(GL_LIGHTING);
	eglDisable(GL_CULL_FACE);
	eglDisable(GL_DEPTH_TEST);
	eglDisable(GL_BLEND);
	eglDisable(GL_NORMALIZE);
	eglDisable(GL_ALPHA_TEST);
	eglEnable(GL_TEXTURE_2D);
	eglBlendFunc (GL_SRC_ALPHA, GL_ONE);
	
	eglGenTextures(1,&_screenTexnum);
	eglBindTexture(GL_TEXTURE_2D,_screenTexnum);
	eglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _openGLFilter?GL_LINEAR:GL_NEAREST);
	eglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _openGLFilter?GL_LINEAR:GL_NEAREST);
	_texWidth=512;
	_texHeight=512;
	
	switch(surface_bpp)
	{
	case 32:
		eglTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA,_texWidth,_texHeight, 0,
			GL_RGBA,
			GL_UNSIGNED_BYTE, NULL);
		break;
	case 24:
		eglTexImage2D(GL_TEXTURE_2D, 0,GL_RGB,_texWidth,_texHeight, 0,
			GL_RGB,
			GL_UNSIGNED_BYTE, NULL);
		break;
	case 16:
		eglTexImage2D(GL_TEXTURE_2D, 0,GL_RGB5,_texWidth,_texHeight, 0,
			GL_RGB,
			GL_UNSIGNED_BYTE, NULL);
		break;
	case 8:
		eglTexImage2D(GL_TEXTURE_2D, 0,GL_COLOR_INDEX8_EXT,_texWidth,_texHeight, 0,
			GL_COLOR_INDEX,
			GL_UNSIGNED_BYTE, NULL);
		break;
	}
	
	if (_GLScanlines!=0)
	{
		Uint8 texmod;
		switch(_GLScanlines)
		{
		case 25:
			texmod=192; break;
		case 50:
			texmod=128; break;
		case 75:
			texmod=64; break;
		case 100:
			texmod=0; break;
		default:
			texmod=255;
		}
		eglGenTextures(1,&_modulateTexnum);
		eglBindTexture(GL_TEXTURE_2D,_modulateTexnum);
		eglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _openGLFilter?GL_LINEAR:GL_NEAREST);
		eglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _openGLFilter?GL_LINEAR:GL_NEAREST);
		
		Uint8 modulate_texture[]={
			255,255,255,
				0,0,0};
			modulate_texture[3]=texmod;
			modulate_texture[4]=texmod;
			modulate_texture[5]=texmod;
			eglTexImage2D(GL_TEXTURE_2D, 0,GL_RGB8,1,2, 0,GL_RGB,GL_UNSIGNED_BYTE, modulate_texture);
	}
	eglViewport(0,0,w,h);
	eglMatrixMode(GL_PROJECTION);
	eglLoadIdentity();
	eglOrtho(0,w,h,0,-1.0, 1.0);
	
	eglMatrixMode(GL_MODELVIEW);
	eglLoadIdentity();
	
//	_publicVideo=SDL_CreateRGBSurface(SDL_SWSURFACE,CPCVisibleSCRWidth,CPCVisibleSCRHeight,surface_bpp,0,0,0,0);
	return _publicVideo;
}
示例#27
0
int Wayland_CreateWindow(_THIS, SDL_Window *window)
{
    SDL_WindowData *data;
    SDL_VideoData *c;
    struct wl_region *region;

    data = calloc(1, sizeof *data);
    if (data == NULL)
        return SDL_OutOfMemory();

    c = _this->driverdata;
    window->driverdata = data;

    if (!(window->flags & SDL_WINDOW_OPENGL)) {
        SDL_GL_LoadLibrary(NULL);
        window->flags |= SDL_WINDOW_OPENGL;
    }

    if (window->x == SDL_WINDOWPOS_UNDEFINED) {
        window->x = 0;
    }
    if (window->y == SDL_WINDOWPOS_UNDEFINED) {
        window->y = 0;
    }

    data->waylandData = c;
    data->sdlwindow = window;

    data->surface =
        wl_compositor_create_surface(c->compositor);
    wl_surface_set_user_data(data->surface, data);

    if (c->shell.xdg) {
        data->shell_surface.xdg.surface = xdg_wm_base_get_xdg_surface(c->shell.xdg, data->surface);
        /* !!! FIXME: add popup role */
        data->shell_surface.xdg.roleobj.toplevel = xdg_surface_get_toplevel(data->shell_surface.xdg.surface);
        xdg_toplevel_add_listener(data->shell_surface.xdg.roleobj.toplevel, &toplevel_listener_xdg, data);
        xdg_toplevel_set_app_id(data->shell_surface.xdg.roleobj.toplevel, c->classname);
    } else if (c->shell.zxdg) {
        data->shell_surface.zxdg.surface = zxdg_shell_v6_get_xdg_surface(c->shell.zxdg, data->surface);
        /* !!! FIXME: add popup role */
        data->shell_surface.zxdg.roleobj.toplevel = zxdg_surface_v6_get_toplevel(data->shell_surface.zxdg.surface);
        zxdg_toplevel_v6_add_listener(data->shell_surface.zxdg.roleobj.toplevel, &toplevel_listener_zxdg, data);
        zxdg_toplevel_v6_set_app_id(data->shell_surface.zxdg.roleobj.toplevel, c->classname);
    } else {
        data->shell_surface.wl = wl_shell_get_shell_surface(c->shell.wl, data->surface);
        wl_shell_surface_set_class(data->shell_surface.wl, c->classname);
    }

#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
    if (c->surface_extension) {
        data->extended_surface = qt_surface_extension_get_extended_surface(
                c->surface_extension, data->surface);

        QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION);
        QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS);
    }
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */

    data->egl_window = WAYLAND_wl_egl_window_create(data->surface,
                                            window->w, window->h);

    /* Create the GLES window surface */
    data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window);
    
    if (data->egl_surface == EGL_NO_SURFACE) {
        return SDL_SetError("failed to create a window surface");
    }

    if (c->shell.xdg) {
        if (data->shell_surface.xdg.surface) {
            xdg_surface_set_user_data(data->shell_surface.xdg.surface, data);
            xdg_surface_add_listener(data->shell_surface.xdg.surface, &shell_surface_listener_xdg, data);
        }
    } else if (c->shell.zxdg) {
        if (data->shell_surface.zxdg.surface) {
            zxdg_surface_v6_set_user_data(data->shell_surface.zxdg.surface, data);
            zxdg_surface_v6_add_listener(data->shell_surface.zxdg.surface, &shell_surface_listener_zxdg, data);
        }
    } else {
        if (data->shell_surface.wl) {
            wl_shell_surface_set_user_data(data->shell_surface.wl, data);
            wl_shell_surface_add_listener(data->shell_surface.wl, &shell_surface_listener_wl, data);
        }
    }

#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
    if (data->extended_surface) {
        qt_extended_surface_set_user_data(data->extended_surface, data);
        qt_extended_surface_add_listener(data->extended_surface,
                                         &extended_surface_listener, data);
    }
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */

    region = wl_compositor_create_region(c->compositor);
    wl_region_add(region, 0, 0, window->w, window->h);
    wl_surface_set_opaque_region(data->surface, region);
    wl_region_destroy(region);

    if (c->relative_mouse_mode) {
        Wayland_input_lock_pointer(c->input);
    }

    wl_surface_commit(data->surface);
    WAYLAND_wl_display_flush(c->display);

    /* we have to wait until the surface gets a "configure" event, or
       use of this surface will fail. This is a new rule for xdg_shell. */
    if (c->shell.xdg) {
        if (data->shell_surface.xdg.surface) {
            while (!data->shell_surface.xdg.initial_configure_seen) {
                WAYLAND_wl_display_flush(c->display);
                WAYLAND_wl_display_dispatch(c->display);
            }
        }
    } else if (c->shell.zxdg) {
        if (data->shell_surface.zxdg.surface) {
            while (!data->shell_surface.zxdg.initial_configure_seen) {
                WAYLAND_wl_display_flush(c->display);
                WAYLAND_wl_display_dispatch(c->display);
            }
        }
    }

    return 0;
}
示例#28
0
bool Rimp_Init (void)
{
	SDL_version version;
	int attrValue;

	Com_Printf("\n------- video initialization -------\n");

	OBJZERO(r_sdl_config);

	if (r_driver->string[0] != '\0') {
		Com_Printf("using driver: %s\n", r_driver->string);
		SDL_GL_LoadLibrary(r_driver->string);
	}

	Sys_Setenv("SDL_VIDEO_CENTERED", "1");
	Sys_Setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "0");

	if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
		if (SDL_Init(SDL_INIT_VIDEO) < 0)
			Com_Error(ERR_FATAL, "Video SDL_Init failed: %s", SDL_GetError());
	}

	SDL_VERSION(&version)
	Com_Printf("SDL version: %i.%i.%i\n", version.major, version.minor, version.patch);

#if SDL_VERSION_ATLEAST(2,0,0)
	int screen = 0;
	const int modes = SDL_GetNumDisplayModes(screen);
	if (modes > 0) {
		r_sdl_config.modes = Mem_AllocTypeN(rect_t, modes);
		for (int i = 0; i < modes; i++) {
			SDL_DisplayMode displayMode;
			SDL_GetDisplayMode(screen, i, &displayMode);
			r_sdl_config.modes[i][0] = displayMode.w;
			r_sdl_config.modes[i][1] = displayMode.h;
		}
	}
#else
	const SDL_VideoInfo* info = SDL_GetVideoInfo();
	if (info != nullptr) {
		SDL_VideoInfo videoInfo;
		SDL_PixelFormat pixelFormat;
		SDL_Rect** modes;
		Com_Printf("I: desktop depth: %ibpp\n", info->vfmt->BitsPerPixel);
		r_config.videoMemory = info->video_mem;
		Com_Printf("I: video memory: %i\n", r_config.videoMemory);
		memcpy(&pixelFormat, info->vfmt, sizeof(pixelFormat));
		memcpy(&videoInfo, info, sizeof(videoInfo));
		videoInfo.vfmt = &pixelFormat;
		modes = SDL_ListModes(videoInfo.vfmt, SDL_OPENGL | SDL_FULLSCREEN);
		if (modes) {
			if (modes == (SDL_Rect**)-1) {
				Com_Printf("I: Available resolutions: any resolution is supported\n");
				r_sdl_config.modes = nullptr;
			} else {
				for (r_sdl_config.numModes = 0; modes[r_sdl_config.numModes]; r_sdl_config.numModes++) {}

				r_sdl_config.modes = Mem_AllocTypeN(rect_t, r_sdl_config.numModes);
				for (int i = 0; i < r_sdl_config.numModes; i++) {
					r_sdl_config.modes[i][0] = modes[i]->w;
					r_sdl_config.modes[i][1] = modes[i]->h;
				}
			}
		} else {
			Com_Printf("I: Could not get list of available resolutions\n");
		}
	}
	char videoDriverName[MAX_VAR] = "";
	SDL_VideoDriverName(videoDriverName, sizeof(videoDriverName));
	Com_Printf("I: video driver: %s\n", videoDriverName);
#endif
	if (r_sdl_config.numModes > 0) {
		char buf[4096] = "";
		Q_strcat(buf, sizeof(buf), "I: Available resolutions:");
		for (int i = 0; i < r_sdl_config.numModes; i++) {
			Q_strcat(buf, sizeof(buf), " %ix%i", r_sdl_config.modes[i][0], r_sdl_config.modes[i][1]);
		}
		Com_Printf("%s (%i)\n", buf, r_sdl_config.numModes);
	}

	if (!R_SetMode())
		Com_Error(ERR_FATAL, "Video subsystem failed to initialize");

#if !SDL_VERSION_ATLEAST(2,0,0)
	SDL_WM_SetCaption(GAME_TITLE, GAME_TITLE_LONG);

	/* we need this in the renderer because if we issue an vid_restart we have
	 * to set these values again, too */
	SDL_EnableUNICODE(SDL_ENABLE);
	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
#endif

	R_SetSDLIcon();

	if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &attrValue))
		Com_Printf("I: got %d bits of stencil\n", attrValue);
	if (!SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &attrValue))
		Com_Printf("I: got %d bits of depth buffer\n", attrValue);
	if (!SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &attrValue))
		Com_Printf("I: got double buffer\n");
	if (!SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &attrValue))
		Com_Printf("I: got %d bits for red\n", attrValue);
	if (!SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &attrValue))
		Com_Printf("I: got %d bits for green\n", attrValue);
	if (!SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &attrValue))
		Com_Printf("I: got %d bits for blue\n", attrValue);
	if (!SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &attrValue))
		Com_Printf("I: got %d bits for alpha\n", attrValue);
	if (!SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &attrValue))
		Com_Printf("I: got multisample %s\n", attrValue != 0 ? "enabled" : "disabled");
	if (!SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &attrValue))
		Com_Printf("I: got %d multisample buffers\n", attrValue);

	return true;
}
示例#29
0
int Wayland_CreateWindow(_THIS, SDL_Window *window)
{
    SDL_WindowData *data;
    SDL_VideoData *c;
    struct wl_region *region;

    data = calloc(1, sizeof *data);
    if (data == NULL)
        return 0;

    c = _this->driverdata;
    window->driverdata = data;

    if (!(window->flags & SDL_WINDOW_OPENGL)) {
        SDL_GL_LoadLibrary(NULL);
        window->flags |= SDL_WINDOW_OPENGL;
    }

    if (window->x == SDL_WINDOWPOS_UNDEFINED) {
        window->x = 0;
    }
    if (window->y == SDL_WINDOWPOS_UNDEFINED) {
        window->y = 0;
    }

    data->waylandData = c;
    data->sdlwindow = window;

    data->surface =
        wl_compositor_create_surface(c->compositor);
    wl_surface_set_user_data(data->surface, data);
    data->shell_surface = wl_shell_get_shell_surface(c->shell,
                                                     data->surface);
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH    
    if (c->surface_extension) {
        data->extended_surface = qt_surface_extension_get_extended_surface(
                c->surface_extension, data->surface);
    }
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */

    /**
     * If the user specified 0x0 as the size (turned to 1x1 by SDL_CreateWindow
     * in SDL_video.c), we want to make the window fill the whole screen
     **/
    if (window->w == 1) {
        window->w = c->screen_allocation.width;
    }
    if (window->h == 1) {
        window->h = c->screen_allocation.height;
    }

    data->egl_window = WAYLAND_wl_egl_window_create(data->surface,
                                            window->w, window->h);

    /* Create the GLES window surface */
    data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window);
    
    if (data->egl_surface == EGL_NO_SURFACE) {
        SDL_SetError("failed to create a window surface");
        return -1;
    }

    if (data->shell_surface) {
        wl_shell_surface_set_user_data(data->shell_surface, data);
        wl_shell_surface_add_listener(data->shell_surface,
                                      &shell_surface_listener, data);
    }

#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
    if (data->extended_surface) {
        qt_extended_surface_set_user_data(data->extended_surface, data);
        qt_extended_surface_add_listener(data->extended_surface,
                                         &extended_surface_listener, data);
    }
#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */

    region = wl_compositor_create_region(c->compositor);
    wl_region_add(region, 0, 0, window->w, window->h);
    wl_surface_set_opaque_region(data->surface, region);
    wl_region_destroy(region);

    WAYLAND_wl_display_flush(c->display);

    return 0;
}
示例#30
0
int loadgldriver(const char *driver)
{
	void *t;
	int err=0;
	
#ifdef RENDERTYPEWIN
	if (hGLDLL) return 0;
#endif

	if (!driver) {
#ifdef _WIN32
		driver = "OPENGL32.DLL";
#elif defined __APPLE__
		driver = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
#else
		driver = "libGL.so";
#endif
	}

	initprintf("Loading %s\n",driver);

#if defined RENDERTYPESDL
	if (SDL_GL_LoadLibrary(driver)) return -1;
#elif defined _WIN32
	hGLDLL = LoadLibrary(driver);
	if (!hGLDLL) return -1;
#endif
	gldriver = strdup(driver);

#ifdef RENDERTYPEWIN
	bwglCreateContext	= GETPROC("wglCreateContext");
	bwglDeleteContext	= GETPROC("wglDeleteContext");
	bwglGetProcAddress	= GETPROC("wglGetProcAddress");
	bwglMakeCurrent		= GETPROC("wglMakeCurrent");

	bwglSwapBuffers		= GETPROC("wglSwapBuffers");
	bwglChoosePixelFormat	= GETPROC("wglChoosePixelFormat");
	bwglDescribePixelFormat	= GETPROC("wglDescribePixelFormat");
	bwglGetPixelFormat	= GETPROC("wglGetPixelFormat");
	bwglSetPixelFormat	= GETPROC("wglSetPixelFormat");
#endif

	bglClearColor		= GETPROC("glClearColor");
	bglClear		= GETPROC("glClear");
	bglColorMask		= GETPROC("glColorMask");
	bglAlphaFunc		= GETPROC("glAlphaFunc");
	bglBlendFunc		= GETPROC("glBlendFunc");
	bglCullFace		= GETPROC("glCullFace");
	bglFrontFace		= GETPROC("glFrontFace");
	bglPolygonOffset	= GETPROC("glPolygonOffset");
	bglPolygonMode		= GETPROC("glPolygonMode");
	bglEnable		= GETPROC("glEnable");
	bglDisable		= GETPROC("glDisable");
	bglGetFloatv		= GETPROC("glGetFloatv");
	bglGetIntegerv		= GETPROC("glGetIntegerv");
	bglPushAttrib		= GETPROC("glPushAttrib");
	bglPopAttrib		= GETPROC("glPopAttrib");
	bglGetError		= GETPROC("glGetError");
	bglGetString		= GETPROC("glGetString");
	bglHint			= GETPROC("glHint");

	// Depth
	bglDepthFunc		= GETPROC("glDepthFunc");
	bglDepthMask		= GETPROC("glDepthMask");
	bglDepthRange		= GETPROC("glDepthRange");

	// Matrix
	bglMatrixMode		= GETPROC("glMatrixMode");
	bglOrtho		= GETPROC("glOrtho");
	bglFrustum		= GETPROC("glFrustum");
	bglViewport		= GETPROC("glViewport");
	bglPushMatrix		= GETPROC("glPushMatrix");
	bglPopMatrix		= GETPROC("glPopMatrix");
	bglLoadIdentity		= GETPROC("glLoadIdentity");
	bglLoadMatrixf		= GETPROC("glLoadMatrixf");

	// Drawing
	bglBegin		= GETPROC("glBegin");
	bglEnd			= GETPROC("glEnd");
	bglVertex2f		= GETPROC("glVertex2f");
	bglVertex2i		= GETPROC("glVertex2i");
	bglVertex3d		= GETPROC("glVertex3d");
	bglVertex3fv		= GETPROC("glVertex3fv");
	bglColor4f		= GETPROC("glColor4f");
	bglColor4ub		= GETPROC("glColor4ub");
	bglTexCoord2d		= GETPROC("glTexCoord2d");
	bglTexCoord2f		= GETPROC("glTexCoord2f");

	// Lighting
	bglShadeModel		= GETPROC("glShadeModel");

	// Raster funcs
	bglReadPixels		= GETPROC("glReadPixels");

	// Texture mapping
	bglTexEnvf		= GETPROC("glTexEnvf");
	bglGenTextures		= GETPROC("glGenTextures");
	bglDeleteTextures	= GETPROC("glDeleteTextures");
	bglBindTexture		= GETPROC("glBindTexture");
	bglTexImage2D		= GETPROC("glTexImage2D");
	bglTexSubImage2D	= GETPROC("glTexSubImage2D");
	bglTexParameterf	= GETPROC("glTexParameterf");
	bglTexParameteri	= GETPROC("glTexParameteri");
	bglGetTexLevelParameteriv = GETPROC("glGetTexLevelParameteriv");

	// Fog
	bglFogf			= GETPROC("glFogf");
	bglFogi			= GETPROC("glFogi");
	bglFogfv		= GETPROC("glFogfv");

	loadglextensions();

	if (err) unloadgldriver();
	return err;
}