Exemplo n.º 1
0
/**
 * @return whether window initialization succeeded
 * @param title char* string with window title
 *
 * Initializes the game window
 */
bool SpringApp::InitWindow(const char* title)
{
	// SDL will cause a creation of gpu-driver thread that will clone its name from the starting threads (= this one = mainthread)
	Threading::SetThreadName("gpu-driver");

	// the crash reporter should be catching errors, not SDL
	if ((SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) == -1)) {
		LOG_L(L_FATAL, "Could not initialize SDL: %s", SDL_GetError());
		return false;
	}

	PrintAvailableResolutions();
	SDL_DisableScreenSaver();

	if (!CreateSDLWindow(title)) {
		LOG_L(L_FATAL, "Failed to set SDL video mode: %s", SDL_GetError());
		return false;
	}

	if (cmdline->IsSet("minimise")) {
		SDL_HideWindow(window);
	}

	// anyone other thread spawned from the main-process should be `unknown`
	Threading::SetThreadName("unknown");
	return true;
}
Exemplo n.º 2
0
NAMESPACE_BEGIN

Renderer::Renderer(const String& basePath, const String& prefPath,
                   Input* inputMgr, const String& windowTitle)
    : mInputMgr(inputMgr),
      mWindow(nullptr),
	  mLogManager(nullptr),
	  mLog(nullptr),
	  mRoot(nullptr),
      mSceneManager(nullptr),
	  mRootNode(nullptr),
      mRenderWindow(nullptr),
      mViewport(nullptr),
      mDefaultCamera(nullptr),
      mRaySceneQuery(nullptr),
	  mRenderSystemPlugin(nullptr),
	  mParticleUniversePlugin(nullptr),
      mRTRoot(nullptr),
      mRTRootPosition(Position::origin)
{
    // Read config file
    Vec2i displayMode = Config::Get<Vec2i>("displaymode", Vec2i(1280, 800));
    bool fullscreen = Config::Get<bool>("fullscreen", false);
    bool vsync = Config::Get<bool>("vsync", true);

    // Set up Ogre's log manager
    mLogManager = new Ogre::LogManager();
    mLog = mLogManager->createLog(prefPath + "ogre.log", true, false, false);

    // Create the Ogre root
    mRoot = new Ogre::Root("", "");
    LOG << "Created Ogre Root";
    LOG << "\tVersion: " << OGRE_VERSION_MAJOR << "." << OGRE_VERSION_MINOR << "."
                << OGRE_VERSION_PATCH << " " << OGRE_VERSION_NAME;

    // PLUGIN STAGE
    LoadPlugins();

    // Set the render system to the first available renderer
    if (mRoot->getAvailableRenderers().empty())
    {
        // TODO: THIS SHOULD NEVER HAPPEN
        assert(0);
    }
    mRoot->setRenderSystem(mRoot->getAvailableRenderers().front());

    // WINDOW CREATION STAGE

    // Window options
    Ogre::NameValuePairList options;
    options["vsync"] = vsync ? "true" : "false";
    options["gamma"] = "true";
    options["title"] = windowTitle;
    CreateSDLWindow(windowTitle, displayMode, fullscreen, options);

    // Initialise Ogre and use the SDL window
    mRoot->initialise(false, "", "");
    mRenderWindow = mRoot->createRenderWindow(windowTitle, displayMode.x, displayMode.y, fullscreen, &options);
    mRenderWindow->setVisible(true);

    // OGRE IS NOW READY, SET UP THE SCENE
	InitResources(basePath);
    InitScene();

    // Set up the raycast query object
    mRaySceneQuery = mSceneManager->createRayQuery(Ogre::Ray(), Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
    mRaySceneQuery->setSortByDistance(true);
    mRaySceneQuery->setQueryMask(UNIVERSE_OBJECT);

    // Set up the deferred shading system
    mDeferredShadingMgr = new DeferredShadingManager(mViewport, mSceneManager);

    // Set up post processing
    mHDRComp = Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "HDR");
    mBlurComp = Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "GaussianBlur");
    mHDRComp->setEnabled(true);
    //mBlurComp->setEnabled(true);

    // Set up the sprite manager
    mSpriteManager = new SpriteManager(mViewport, mSceneManager);

    // Set up the root scene nodes
    mRootNode = mSceneManager->getRootSceneNode();
    mRTRoot = mRootNode->createChildSceneNode();

    // Add event delegates
    ADD_LISTENER(Renderer, EvtData_KeyDown);
}
Exemplo n.º 3
0
/*
 * Initializes the OpenGL window
 */
static qboolean
GLimp_InitGraphics(qboolean fullscreen)
{
	int flags;
	int msaa_samples;
	int stencil_bits;
	int width, height;
	char title[24];

	if (GetWindowSize(&width, &height) && (width == vid.width) && (height == vid.height))
	{
		/* If we want fullscreen, but aren't */
		if (fullscreen != IsFullscreen())
		{
			GLimp_ToggleFullscreen();
		}

		/* Are we now? */
		if (fullscreen == IsFullscreen())
		{
			return true;
		}
	}

	/* Is the surface used? */
	if (window)
	{
#if SDL_VERSION_ATLEAST(2, 0, 0)
		SDL_GL_DeleteContext(context);
		SDL_DestroyWindow(window);
#else
		SDL_FreeSurface(window);
#endif
	}

	/* Create the window */
	VID_NewWindow(vid.width, vid.height);

	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);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

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

		if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) == -1)
		{
			Com_Printf("MSAA is unsupported: %s\n", SDL_GetError());
			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) == -1)
		{
			Com_Printf("MSAA %ix is unsupported: %s\n", msaa_samples, SDL_GetError());
			Cvar_SetValue("gl_msaa_samples", 0);
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
		}
	}

	/* Initiate the flags */
	flags = SDL_OPENGL;

	if (fullscreen)
	{
		flags |= SDL_FULLSCREEN;
	}

#if !SDL_VERSION_ATLEAST(2, 0, 0)
	/* For SDL1.2, these things must be done before creating the window */

	/* Set the icon */
	SetSDLIcon();

	/* Set vsync */
	SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, gl_swapinterval->value ? 1 : 0);
#endif

	while (1)
	{
		if (!CreateSDLWindow(flags))
		{
			if (gl_msaa_samples->value)
			{
				VID_Printf(PRINT_ALL, "SDL SetVideoMode failed: %s\n",
						SDL_GetError());
				VID_Printf(PRINT_ALL, "Reverting to %s gl_mode %i (%ix%i) without MSAA.\n",
						(flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed",
						(int)Cvar_VariableValue("gl_mode"), vid.width, vid.height);

				/* Try to recover */
				Cvar_SetValue("gl_msaa_samples", 0);
				SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
				SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
			}
			else if (vid.width != 640 || vid.height != 480 || (flags & SDL_FULLSCREEN))
			{
				VID_Printf(PRINT_ALL, "SDL SetVideoMode failed: %s\n",
						SDL_GetError());
				VID_Printf(PRINT_ALL, "Reverting to windowed gl_mode 4 (640x480).\n");

				/* Try to recover */
				Cvar_SetValue("gl_mode", 4);
				Cvar_SetValue("vid_fullscreen", 0);
				vid.width = 640;
				vid.height = 480;
				flags &= ~SDL_FULLSCREEN;
			}
			else
			{
				VID_Error(ERR_FATAL, "Failed to revert to gl_mode 4. Exiting...\n");
				return false;
			}
		}
		else
		{
			break;
		}
	}

#if SDL_VERSION_ATLEAST(2, 0, 0)
	/* For SDL2, these things must be done after creating the window */

	/* Set the icon */
	SetSDLIcon();

	/* Set vsync - TODO: -1 could be set for "late swap tearing" */
	SDL_GL_SetSwapInterval(gl_swapinterval->value ? 1 : 0);
#endif

	/* Initialize the stencil buffer */
	if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits))
	{
		VID_Printf(PRINT_ALL, "Got %d bits of stencil.\n", stencil_bits);

		if (stencil_bits >= 1)
		{
			have_stencil = true;
		}
	}

	/* Initialize hardware gamma */
	InitGamma();

	/* Window title */
	snprintf(title, sizeof(title), "Yamagi Quake II %s", YQ2VERSION);
#if SDL_VERSION_ATLEAST(2, 0, 0)
	SDL_SetWindowTitle(window, title);
#else
	SDL_WM_SetCaption(title, title);
#endif

	/* No cursor */
	SDL_ShowCursor(0);

	return true;
}
Exemplo n.º 4
0
/*
 * Creates a window using SDL
 *
 */
void CreateInterface () {
       
	// Create GL Context
    CreateSDLWindow();	
    
}