Ejemplo n.º 1
0
SGL_Window* SGL_CreateWindow(const char* title, int GLMajorVersion, int GLMinorVersion, int x, int y, int w, int h, Uint32 SDLflags)
{
#if defined(_WINDOWS)
	SDL_DisplayMode targetMode;
	if (SDL_GetCurrentDisplayMode(0, &targetMode))
	{
		return NULL;
	}
	SDL_DisplayMode closestMode;
	SDL_GetClosestDisplayMode(0, &targetMode, &closestMode);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, GLMajorVersion);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, GLMinorVersion);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	SGL_Window* window = SDL_malloc(sizeof(SGL_Window));
	window->window = SDL_CreateWindow
		(
			title,
			x, y,
			w, h,
			SDLflags
		);
	window->context = SDL_GL_CreateContext(window->window);
	glewExperimental = GL_TRUE;
	glewInit();
#elif defined(ANDROID)
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, GLMajorVersion > 3 ? GLMajorVersion : 3);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
	SGL_Window* window = SDL_malloc(sizeof(SGL_Window));
	SDL_DisplayMode displayMode;
	if (SDL_GetCurrentDisplayMode(0, &displayMode))
	{
		return NULL;
	}
	window->window = SDL_CreateWindow
		(
			title,
			SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
			displayMode.w, displayMode.h,
			SDLflags
			);
	window->context = SDL_GL_CreateContext(window->window);
#endif
	SDL_Log("----------------------------------------------------------------\n");
	SDL_Log("Graphics Successfully Initialized For Window: %s\n", title);
	SDL_Log("OpenGL Info\n");
	SDL_Log("  Version: %s\n", glGetString(GL_VERSION));
	SDL_Log("   Vendor: %s\n", glGetString(GL_VENDOR));
	SDL_Log(" Renderer: %s\n", glGetString(GL_RENDERER));
	SDL_Log("  Shading: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
	SDL_Log("----------------------------------------------------------------\n");
	SGL_SetWindowIcon(window, NULL);
	return window;
}
Ejemplo n.º 2
0
/*
* Create a new window
* @param windowName is the window's title
* @param windowWidth is the window's width
* @param windowHeight is the window's height
* @param fullScreen specifies if the window is full screen or not
*/
void SDLInterface::createWindow(std::string windowName, int windowWidth, int windowHeight, bool fullScreen) {
	_windowWidth = windowWidth;
	_windowHeight = windowHeight;
	
		//Update the window flags
	Uint32 flags = SDL_WINDOW_SHOWN;
	if (fullScreen) {
		flags |= SDL_WINDOW_MAXIMIZED | SDL_WINDOW_BORDERLESS;
	}	

		//Create a SDL window centered into the middle of the screen
	_window = SDL_CreateWindow(windowName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _windowWidth, _windowHeight, flags);

		//Declare display mode structure to be filled in. It will allow us to get the current resolution
	SDL_DisplayMode current;
	SDL_GetCurrentDisplayMode(0, &current);
	_windowWidthFullScreen = current.w;
	_windowHeightFullScreen = current.h;
			
		// if the window creation succeeded create our renderer.
	if (_window != 0) {
		_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_PRESENTVSYNC);
			// Set to black
		setWindowBackgroundColor(0, 0, 0, 255);		
	}
	else {
		ErrorManagement::errorRunTime("[SDL Interface] A problem occurred when the window was created");
	}	
}
Ejemplo n.º 3
0
	void SDLWindow::Initialize()
	{
		assert(((start_location.w > 0 && start_location.h > 0) || start_location.w == start_location.h),
			"If a special resolution modifier is to be used, then both length and width must be equal.");

		if (start_location == USE_CURRENT_RESOLUTION)
		{
			SDL_DisplayMode display_mode;

			assert((SDL_GetCurrentDisplayMode(DISPLAY_NUMBER, &display_mode) == 0), SDL_GetError());

			start_location.w = (double)display_mode.w;
			start_location.h = (double)display_mode.h;
		}

		if (fullscreen)
		{
			SDL_CreateWindowAndRenderer(0, 0,
				(SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_BORDERLESS),
				&window, &write_to);
			// Scale so the user's code doesn't know the difference.
			SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  // make the scaled rendering look smoother.
			SDL_RenderSetLogicalSize(write_to, GfxRound(start_location.w), GfxRound(start_location.h));
		}
		else
		{
			SDL_CreateWindowAndRenderer(GfxRound(start_location.w), GfxRound(start_location.h), 0, &window, &write_to);
		}

		SDL_SetWindowTitle(this->window, this->title);

		SDL_SetRenderDrawColor(write_to, fill.r, fill.g, fill.b, fill.a);
		SDL_RenderClear(write_to);
		SDL_RenderPresent(write_to);
	}
Ejemplo n.º 4
0
static void wid_intro_settings_add_default_screen_modes (void)
{
    int w;
    int h;
#if SDL_MAJOR_VERSION == 2 /* { */
    SDL_DisplayMode mode;
    SDL_GetCurrentDisplayMode(0, &mode);
    w = mode.w;
    h = mode.h; 
#else
    const SDL_VideoInfo *info = SDL_GetVideoInfo();
    w = info->current_w;
    h = info->current_h; 
#endif
    char *tmp = dynprintf("%dx%d", w, h);
    int j;

    for (j = 0; j < WID_INTRO_MAX_VAL - 1; j++) {
        if (!wid_intro_button_value_string
            [WID_INTRO_SETTINGS_ROW_WINDOW][j]) {

            wid_intro_button_value_string
                [WID_INTRO_SETTINGS_ROW_WINDOW][j] = tmp;

            break;
        }
    } /* } */
}
Ejemplo n.º 5
0
void cWindow::RenderAt( cSurface* pImage, cPosition pSource ) {
	SDL_Rect Src, Dest;

	Src.w = mScreenSize.mWidth;
	Src.h = mScreenSize.mHeight;
	Src.x = pSource.mX + 16;
	Src.y = pSource.mY + 16;

	Dest.w = GetWindowSize().mWidth;
	Dest.h = GetWindowSize().mHeight;

	if (mWindowMode) {
		Dest.x = 0;
		Dest.y = 0;
	}
	else {
		SDL_DisplayMode current;
		SDL_GetCurrentDisplayMode(0, &current);

		Dest.x = (current.w - Dest.w) / 2;
		Dest.y = (current.h - Dest.h) / 2;
	}
	pImage->draw();

	SDL_RenderCopy( mRenderer, pImage->GetTexture(), &Src, &Dest );
}
Ejemplo n.º 6
0
void cWindow::RenderShrunk( cSurface* pImage ) {
	SDL_Rect Src, Dest;
	Src.w = pImage->GetWidth();
	Src.h = pImage->GetHeight();
	Src.x = 0;
	Src.y = 0;

	Dest.w = GetWindowSize().mWidth;
	Dest.h = GetWindowSize().mHeight;

	if (mWindowMode) {
		Dest.x = 0;
		Dest.y = 0;
	}
	else {
		SDL_DisplayMode current;
		SDL_GetCurrentDisplayMode(0, &current);

		Dest.x = (current.w - Dest.w) / 2;
		Dest.y = (current.h - Dest.h) / 2;
	}
	pImage->draw();

	SDL_RenderCopy( mRenderer, pImage->GetTexture(), &Src, &Dest);
}
Ejemplo n.º 7
0
Vector2 getDesktopSize( int display_index )
{
  SDL_DisplayMode current;
  // Get current display mode of all displays.
  int should_be_zero = SDL_GetCurrentDisplayMode(display_index, &current);
  return Vector2( (float)current.w, (float)current.h );
}
Ejemplo n.º 8
0
static void GfxInfo_f(void)
{
	SDL_DisplayMode current;

	Com_Printf_State(PRINT_ALL, "\nGL_VENDOR: %s\n", glConfig.vendor_string );
	Com_Printf_State(PRINT_ALL, "GL_RENDERER: %s\n", glConfig.renderer_string );
	Com_Printf_State(PRINT_ALL, "GL_VERSION: %s\n", glConfig.version_string );

	if (r_showextensions.value) {
		Com_Printf_State(PRINT_ALL, "GL_EXTENSIONS: %s\n", glConfig.extensions_string);
	}

	Com_Printf_State(PRINT_ALL, "PIXELFORMAT: color(%d-bits) Z(%d-bit)\n             stencil(%d-bits)\n", glConfig.colorBits, glConfig.depthBits, glConfig.stencilBits);

	if (SDL_GetCurrentDisplayMode(VID_DisplayNumber(r_fullscreen.value), &current) != 0) {
		current.refresh_rate = 0; // print 0Hz if we run into problem fetching data
	}

	Com_Printf_State(PRINT_ALL, "MODE: %d x %d @ %d Hz ", current.w, current.h, current.refresh_rate);
	
	if (r_fullscreen.integer) {
		Com_Printf_State(PRINT_ALL, "[fullscreen]\n");
	} else {
		Com_Printf_State(PRINT_ALL, "[windowed]\n");
	}

	Com_Printf_State(PRINT_ALL, "CONRES: %d x %d\n", r_conwidth.integer, r_conheight.integer );

}
Ejemplo n.º 9
0
void Adafruit_NeoPixel::initializeSdl() {

    if (sdlInitialized) return;
    sdlInitialized = true;

    if (SDL_Init(SDL_INIT_VIDEO) != 0) posixino.fatal("SDL init failed",3);

    SDL_GetCurrentDisplayMode(SDL_DISPLAY,&current);

    calcDims();

    window = SDL_CreateWindow(
                 "Posixino",
                 windowPosX,
                 windowPosY,
                 windowWidth,
                 windowHeight,
                 SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS
             );

    screenSurface = SDL_GetWindowSurface(window);
    SDL_FillRect(screenSurface,NULL,0);
    SDL_UpdateWindowSurface(window);

} // initializeSdl()
Ejemplo n.º 10
0
	void Video::initialize(const std::string& name, const std::string& icon, Console& console)
	{
		console.printLine("\n===Video initialization===");

		// Get current video mode
		SDL_DisplayMode currentVideoMode;		
		if (SDL_GetCurrentDisplayMode(0, &currentVideoMode))
		{
			D6_THROW(VideoException, std::string("Unable to determine current video mode: ") + SDL_GetError());
		}

		// Set graphics mode
		view = ViewParameters(0.1f, 100.0f, 45.0f);

#ifdef D6_DEBUG
		// Running fullscren makes switching to debugger problematic with SDL (focus is captured)
		screen = ScreenParameters(1280, 900, 32, 0, false);
#else
		screen = ScreenParameters(currentVideoMode.w, currentVideoMode.h, 32, 0, true);
#endif

		window = createWindow(name, icon, screen, console);
		glContext = createContext(screen, console);
		SDL_ShowCursor(SDL_DISABLE);
		setMode(Mode::Orthogonal);
	}
Ejemplo n.º 11
0
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);
}
Ejemplo n.º 12
0
bool RWindow::initializeSDL()
{
    SDL_DisplayMode current;

    if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
    {
        std::cerr << "Could not initialize SDL: " << SDL_GetError();
        std::cerr << std::endl;
        std::exit(1);
    }

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

    if(SDL_GetCurrentDisplayMode(0, &current) != 0)
    {
        // In case of error...
        std::cerr << "Could not get display mode for video display: ";
        std::cerr << SDL_GetError() << std::endl;
        return false;
    }
    else
    {
        // Everything is normal
        m_width = current.w;
        m_height = current.h;
    }

    m_window = SDL_CreateWindow(
                m_title.data(),
                SDL_WINDOWPOS_UNDEFINED,
                SDL_WINDOWPOS_UNDEFINED,
                m_width, m_height,
                SDL_WINDOW_OPENGL |
                SDL_WINDOW_FULLSCREEN_DESKTOP |
                SDL_WINDOW_HIDDEN);

    if(m_window == nullptr)
    {
        std::cerr << "Could not iniialize SDL Window: " << SDL_GetError();
        std::cerr << std::endl;
        return false;
    }

    m_surface = SDL_GetWindowSurface(m_window);
    m_context = SDL_GL_CreateContext(m_window);

    //Init cursors
    m_systemCursors[0] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
    m_systemCursors[1] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
    m_systemCursors[2] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
    m_systemCursors[3] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
    m_systemCursors[4] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);

    for(unsigned i = 0; i < 4; ++i)
        m_customCursors[i] = nullptr;

    return true;
}
Ejemplo n.º 13
0
void GHOST_SystemSDL::getMainDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const
{
  SDL_DisplayMode mode;
  SDL_GetCurrentDisplayMode(0, &mode); /* note, always 0 display */
  width = mode.w;
  height = mode.h;
}
Ejemplo n.º 14
0
static bool SetScreenParmsFullscreen( glimpParms_t parms )
{
	SDL_DisplayMode m = {0};
	int displayIdx = ScreenParmsHandleDisplayIndex( parms );
	if( displayIdx < 0 )
		return false;
		
	// get current mode of display the window should be full-screened on
	SDL_GetCurrentDisplayMode( displayIdx, &m );
	
	// change settings in that display mode according to parms
	// FIXME: check if refreshrate, width and height are supported?
	// m.refresh_rate = parms.displayHz;
	m.w = parms.width;
	m.h = parms.height;
	
	// set that displaymode
	if( SDL_SetWindowDisplayMode( window, &m ) < 0 )
	{
		common->Warning( "Couldn't set window mode for fullscreen, reason: %s", SDL_GetError() );
		return false;
	}
	
	// if we're currently not in fullscreen mode, we need to switch to fullscreen
	if( !( SDL_GetWindowFlags( window ) & SDL_WINDOW_FULLSCREEN ) )
	{
		if( SDL_SetWindowFullscreen( window, SDL_TRUE ) < 0 )
		{
			common->Warning( "Couldn't switch to fullscreen mode, reason: %s!", SDL_GetError() );
			return false;
		}
	}
	return true;
}
Ejemplo n.º 15
0
 void Game::initWindow()
 {
     if (config_->fullscreen) {
         SDL_DisplayMode mode;
         if (SDL_GetCurrentDisplayMode(0, &mode) == -1) {
             std::stringstream message;
             message << "Failed to get fullscreen display mode: "
                     << SDL_GetError();
             throw Error(message.str());
         }
         windowWidth_ = mode.w;
         windowHeight_ = mode.h;
     }
     Uint32 flags = SDL_WINDOW_OPENGL;
     if (config_->fullscreen) {
         flags |= SDL_WINDOW_FULLSCREEN;
     }
     window_ = SDL_CreateWindow("Crust", SDL_WINDOWPOS_CENTERED, 
                                SDL_WINDOWPOS_CENTERED, windowWidth_,
                                windowHeight_, flags);
     if (window_ == 0) {
         std::stringstream message;
         message << "Failed to create window: " << SDL_GetError();
         throw Error(message.str());
     }
     if (config_->fullscreen) {
         SDL_GetWindowSize(window_, &windowWidth_, &windowHeight_);
     }
 }
Ejemplo n.º 16
0
int SDL_COMPAT_GetBitsPerPixel(void)
{
  int bpp;
  SDL_DisplayMode mode;
  SDL_GetCurrentDisplayMode(0, &mode);
  bpp = SDL_BITSPERPIXEL(mode.format);
  return (bpp==24)? 32 : bpp;
}
Ejemplo n.º 17
0
bool CheckAvailableVideoModes()
{
	// Get available fullscreen/hardware modes
	const int numDisplays = SDL_GetNumVideoDisplays();

	SDL_DisplayMode ddm = {0, 0, 0, 0, nullptr};
	SDL_DisplayMode cdm = {0, 0, 0, 0, nullptr};

	// ddm is virtual, contains all displays in multi-monitor setups
	// for fullscreen windows with non-native resolutions, ddm holds
	// the original screen mode and cdm is the changed mode
	SDL_GetDesktopDisplayMode(0, &ddm);
	SDL_GetCurrentDisplayMode(0, &cdm);

	LOG(
		"[GL::%s] desktop={%ix%ix%ibpp@%iHz} current={%ix%ix%ibpp@%iHz}",
		__func__,
		ddm.w, ddm.h, SDL_BPP(ddm.format), ddm.refresh_rate,
		cdm.w, cdm.h, SDL_BPP(cdm.format), cdm.refresh_rate
	);

	for (int k = 0; k < numDisplays; ++k) {
		const int numModes = SDL_GetNumDisplayModes(k);

		if (numModes <= 0) {
			LOG("\tdisplay=%d bounds=N/A modes=N/A", k + 1);
			continue;
		}

		SDL_DisplayMode cm = {0, 0, 0, 0, nullptr};
		SDL_DisplayMode pm = {0, 0, 0, 0, nullptr};
		SDL_Rect db;
		SDL_GetDisplayBounds(k, &db);

		LOG("\tdisplay=%d modes=%d bounds={x=%d, y=%d, w=%d, h=%d}", k + 1, numModes, db.x, db.y, db.w, db.h);

		for (int i = 0; i < numModes; ++i) {
			SDL_GetDisplayMode(k, i, &cm);

			const float r0 = (cm.w *  9.0f) / cm.h;
			const float r1 = (cm.w * 10.0f) / cm.h;
			const float r2 = (cm.w * 16.0f) / cm.h;

			// skip legacy (3:2, 4:3, 5:4, ...) and weird (10:6, ...) ratios
			if (r0 != 16.0f && r1 != 16.0f && r2 != 25.0f)
				continue;
			// show only the largest refresh-rate and bit-depth per resolution
			if (cm.w == pm.w && cm.h == pm.h && (SDL_BPP(cm.format) < SDL_BPP(pm.format) || cm.refresh_rate < pm.refresh_rate))
				continue;

			LOG("\t\t[%2i] %ix%ix%ibpp@%iHz", int(i + 1), cm.w, cm.h, SDL_BPP(cm.format), cm.refresh_rate);
			pm = cm;
		}
	}

	// we need at least 24bpp or window-creation will fail
	return (SDL_BPP(ddm.format) >= 24);
}
Ejemplo n.º 18
0
void ZL_UpdateTPFLimit()
{
	SDL_DisplayMode DisplayMode = { 0, 0, 0, 0, 0 };
	SDL_GetCurrentDisplayMode(0, &DisplayMode);
	if (!DisplayMode.refresh_rate) return;
	bool UseVSync = (ZL_TPF_Limit && ZL_TPF_Limit == (unsigned int)((1000.0f / (float)DisplayMode.refresh_rate)-0.0495f));
	SDL_GL_SetSwapInterval(UseVSync ? 1 : 0);
	ZL_MainApplicationFlags = (UseVSync ? ZL_MainApplicationFlags & ~ZL_APPLICATION_NOVSYNC : ZL_MainApplicationFlags | ZL_APPLICATION_NOVSYNC);
}
Ejemplo n.º 19
0
	Coord2i getCurrentResolution(int display)
	{
		SDL_DisplayMode mode;
		if(SDL_GetCurrentDisplayMode(display, &mode) == 0)
		{
			return{mode.w, mode.h};
		}
		throw std::runtime_error("Could not get the current resolution of display " + std::to_string(display) + ". ");
	}
Ejemplo n.º 20
0
MainGame::MainGame()
{
    ConfigurationManager configManager(resourcePath() + "configuration.txt");
    
    //if SDL fails, close program
    if (SDL_Init(SDL_INIT_VIDEO)) throw std::logic_error("Failed to initialize SDL!  " + std::string(SDL_GetError()));
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
    
    if (configManager.GetItem<bool>("Multisampling"))
    {
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, configManager.GetItem<int>("MultisampleBuffers"));
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, configManager.GetItem<int>("MultisampleSamples"));
    }
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
    
    SDL_DisplayMode mode; SDL_GetCurrentDisplayMode(0, &mode);
    
    
    Uint32 windowFlags = SDL_WINDOW_OPENGL;
    size_t width = configManager.GetItem<float>("WindowWidth"), height = configManager.GetItem<float>("WindowHeight");
    if (configManager.GetItem<bool>("Fullscreen"))
    {
//        width = mode.w; height = mode.h;
        windowFlags|=SDL_WINDOW_FULLSCREEN_DESKTOP;
    }
    
    
    window = SDL_CreateWindow("Genetic Algorithm", 0, 0, width, height, windowFlags);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetSwapInterval(1);
    SDL_SetRelativeMouseMode(SDL_TRUE);
    if (window==nullptr) throw std::logic_error("Window failed to be initialized");
    SDL_GLContext context = SDL_GL_CreateContext(window);
    if (context==nullptr) throw std::logic_error("SDL_GL could not be initialized!");
    
    int cpuCount = SDL_GetCPUCount();
    
    
    GLManager glManager(resourcePath() + "fragmentShader.glsl", resourcePath() + "vertexShader.glsl", configManager);
    std::string fileLoc =resourcePath() + "performance.csv";
    EvolutionSystem evolutionSystem(fileLoc, configManager, cpuCount);
    Camera camera(configManager.GetItem<float>("WindowWidth"), configManager.GetItem<float>("WindowHeight"), configManager);
    
    while (GameState!=GameState::EXIT)
    {
        Update(evolutionSystem);
        camera.Update();
        glManager.Programs[0].SetMatrix4("transformMatrix", glm::value_ptr(camera.GetTransformMatrix()));
        Draw(evolutionSystem);
        SDL_GL_SwapWindow(window);
        HandleEvents(evolutionSystem,camera);
    }
}
Ejemplo n.º 21
0
int
main(int argc, char *argv[])
{
    SDL_DisplayMode mode;
    int num_displays, dpy;

	/* Enable standard application logging */
	SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

    /* Load the SDL library */
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
        return 1;
    }

    SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
    num_displays = SDL_GetNumVideoDisplays();

    SDL_Log("See %d displays.\n", num_displays);

    for (dpy = 0; dpy < num_displays; dpy++) {
        const int num_modes = SDL_GetNumDisplayModes(dpy);
        SDL_Rect rect = { 0, 0, 0, 0 };
        int m;

        SDL_GetDisplayBounds(dpy, &rect);
        SDL_Log("%d: \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);

        if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    CURRENT: failed to query (%s)\n", SDL_GetError());
        } else {
            print_mode("CURRENT", &mode);
        }

        if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DESKTOP: failed to query (%s)\n", SDL_GetError());
        } else {
            print_mode("DESKTOP", &mode);
        }

        for (m = 0; m < num_modes; m++) {
            if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    MODE %d: failed to query (%s)\n", m, SDL_GetError());
            } else {
                char prefix[64];
                SDL_snprintf(prefix, sizeof (prefix), "    MODE %d", m);
                print_mode(prefix, &mode);
            }
        }

        SDL_Log("\n");
    }

    return 0;
}
Ejemplo n.º 22
0
int16 cWindow::CalculateFullscreenSize() {
	SDL_DisplayMode current;
	SDL_GetCurrentDisplayMode(0, &current);
	int16 Multiplier = 1;

	while ((mOriginalResolution.mWidth * Multiplier) <= current.w && (mOriginalResolution.mHeight * Multiplier) <= current.h ) {
		++Multiplier;
	}

	return --Multiplier;
}
Ejemplo n.º 23
0
bool cWindow::CanChangeToMultiplier(const size_t pNewMultiplier) {
	SDL_DisplayMode current;
	SDL_GetCurrentDisplayMode(0, &current);

	if ((mOriginalResolution.mWidth  * pNewMultiplier >= (unsigned int) current.w ||
		mOriginalResolution.mHeight * pNewMultiplier >= (unsigned int) current.h) ||
		pNewMultiplier <= 0)
		return false;

	return true;
}
Ejemplo n.º 24
0
void cWindow::CalculateWindowSize() {
	SDL_DisplayMode current;
	SDL_GetCurrentDisplayMode(0, &current);

	while ((mOriginalResolution.mWidth * mWindow_Multiplier) <= (unsigned int) (current.w / 2) &&
		(mOriginalResolution.mHeight * mWindow_Multiplier) <= (unsigned int) (current.h / 2)) {
		++mWindow_Multiplier;
	}

	SetWindowSize(mWindow_Multiplier);
}
Ejemplo n.º 25
0
Dimension2i GraphicsEngine::getMaximumWindowSize() {
	SDL_DisplayMode current;
	if (SDL_GetCurrentDisplayMode(0, &current) == 0) {
		return Dimension2i(current.w, current.h);
	}
	else {
		std::cout << "Failed to get window data" << std::endl;
		std::cout << "GraphicsEngine::getMaximumWindowSize() -> return (0, 0)" << std::endl;
		return Dimension2i(0, 0);
	}
}
Ejemplo n.º 26
0
int query_display_mode(SDL_DisplayMode *display_mode){
    SDL_DisplayMode current;
    int i;
    for(i = 0; i < SDL_GetNumVideoDisplays(); i++){
        int result = SDL_GetCurrentDisplayMode(i,&current);
        if(result == 0){
            *display_mode = current;
            return 0;
        }
    }
    return -1;
}
Ejemplo n.º 27
0
	static int lua_SDL_GetCurrentDisplayMode(lutok::state& state){
		Lua_SDL_DisplayMode & dm = LOBJECT_INSTANCE(Lua_SDL_DisplayMode);
		SDL_DisplayMode * mode = new SDL_DisplayMode;

		if (SDL_GetCurrentDisplayMode(state.to_integer(1), mode) == 0){
			dm.push(mode);
			return 1;
		}else{
			delete mode;
			return 0;
		}
	}
Ejemplo n.º 28
0
	void InfiLInitDisplays() {
		uint32 sz = SDL_GetNumVideoDisplays();
		disp_list.resize( sz );
		for ( uint32 i=0;i<sz;i++ ) {
			SDL_DisplayMode md;
			SDL_GetCurrentDisplayMode( i, &md );
			disp_list[i].format = md.format;
			disp_list[i].width = md.w;
			disp_list[i].height = md.h;
			disp_list[i].refresh_rate = md.refresh_rate;
			disp_list[i].driver = md.driverdata;
		}
	}
Ejemplo n.º 29
0
static void video_check_fullscreen_sanity(void) {
	SDL_DisplayMode mode;

	if(SDL_GetCurrentDisplayMode(SDL_GetWindowDisplayIndex(video.window), &mode)) {
		log_warn("SDL_GetCurrentDisplayMode failed: %s", SDL_GetError());
		return;
	}

	if(video.current.width != mode.w || video.current.height != mode.h) {
		log_warn("BUG: window is not actually fullscreen after modesetting. Video mode: %ix%i, window size: %ix%i",
			mode.w, mode.h, video.current.width, video.current.height);
	}
}
Ejemplo n.º 30
0
      Boolean Surface::create(String name, vec4 const& viewport, Boolean fullscreen)
      {
#       ifdef GLES
          SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
          SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, GLES);

          // MSAA
          SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
          SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 16);
#       else
          SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
          SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, GL);

          SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
#       endif

        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

        IntU flags=SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN;

#       ifdef TARGET_OS_IPHONE
          flags|=SDL_WINDOW_FULLSCREEN;
          flags|=SDL_WINDOW_BORDERLESS;
          flags|=SDL_WINDOW_RESIZABLE;

          SDL_DisplayMode displayMode;
          SDL_GetCurrentDisplayMode(0, &displayMode);

          m_viewport.z=displayMode.w;
          m_viewport.w=displayMode.h;
#       else
          if(fullscreen)
            flags|=SDL_WINDOW_FULLSCREEN;

          m_viewport=viewport;
#       endif

        m_window=SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_viewport.z, m_viewport.w, flags);

        if(!m_window)
        {
          dbge3("Failed to initialize window [" << SDL_GetError() << "]");

          return false;
        }

        createContext(name);

        return true;
      }