# Support alt+enter to toggle fullscreen mode. Make game window resizable.

Refactor the video mode setting logic to cope better with dynamic
changes.

This was SVN commit r7606.
This commit is contained in:
Ykkrosh 2010-06-03 19:07:59 +00:00
parent 310f3466a8
commit 0f611042b1
22 changed files with 444 additions and 121 deletions

View File

@ -13,13 +13,17 @@
; * *
; **************************************************************
; Enable/disable windowed mode.
; Enable/disable windowed mode by default. (Use Alt+Enter to toggle in the game.)
windowed = true
; Force a particular resolution. (If these are unspecified, the
; default is keeping the current desktop resolution.)
xres = 1024
yres = 768
; Force a particular resolution. (If these are 0, the default is
; to keep the current desktop resolution in fullscreen mode or to
; use 1024x768 in windowed mode.)
xres = 0
yres = 0
; Force a non-standard bit depth (if 0 then use the current desktop bit depth)
bpp = 0
; System settings:
@ -91,6 +95,7 @@ hotkey.leave = Escape ;End current game or Exit.
hotkey.pause = Pause ; Pause/unpause game.
hotkey.screenshot = F2 ; Take PNG screenshot.
hotkey.bigscreenshot = "Ctrl+Alt+F2" ; Take large BMP screenshot.
hotkey.togglefullscreen = "Alt+Return" ; Toggle fullscreen/windowed mode
hotkey.screenshot.watermark = "K" ; Toggle product/company watermark for official
hotkey.wireframe = "Alt+W" ; Toggle wireframe mode.

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2010 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -127,12 +127,12 @@ void CCamera::UpdateFrustum ()
m_ViewFrustum.m_aPlanes[5].m_Dist = MatFinal._44+MatFinal._34;
}
void CCamera::SetViewPort (SViewPort *viewport)
void CCamera::SetViewPort (const SViewPort& viewport)
{
m_ViewPort.m_X = viewport->m_X;
m_ViewPort.m_Y = viewport->m_Y;
m_ViewPort.m_Width = viewport->m_Width;
m_ViewPort.m_Height = viewport->m_Height;
m_ViewPort.m_X = viewport.m_X;
m_ViewPort.m_Y = viewport.m_Y;
m_ViewPort.m_Width = viewport.m_Width;
m_ViewPort.m_Height = viewport.m_Height;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2010 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -57,7 +57,7 @@ class CCamera
void UpdateFrustum ();
const CFrustum& GetFrustum () { return m_ViewFrustum; }
void SetViewPort (SViewPort *viewport);
void SetViewPort (const SViewPort& viewport);
const SViewPort& GetViewPort () const { return m_ViewPort; }
// getters

View File

@ -180,9 +180,9 @@ CGameView::CGameView(CGame *pGame):
vp.m_Y=0;
vp.m_Width=g_xres;
vp.m_Height=g_yres;
m->ViewCamera.SetViewPort(&vp);
m->ViewCamera.SetViewPort(vp);
m->ViewCamera.SetProjection (defaultNear, defaultFar, defaultFOV);
m->ViewCamera.SetProjection(defaultNear, defaultFar, defaultFOV);
m->ViewCamera.m_Orientation.SetXRotation(DEGTORAD(30));
m->ViewCamera.m_Orientation.RotateY(DEGTORAD(0));
m->ViewCamera.m_Orientation.Translate (100, 150, -100);
@ -197,6 +197,12 @@ CGameView::~CGameView()
delete m;
}
void CGameView::SetViewport(const SViewPort& vp)
{
m->ViewCamera.SetViewPort(vp);
m->ViewCamera.SetProjection(defaultNear, defaultFar, defaultFOV);
}
CObjectManager& CGameView::GetObjectManager() const
{
return m->ObjectManager;

View File

@ -32,6 +32,7 @@ class CObjectManager;
class CCamera;
class CCinemaManager;
class CVector3D;
struct SViewPort;
struct JSObject;
@ -64,6 +65,8 @@ public:
CGameView(CGame *pGame);
~CGameView();
void SetViewport(const SViewPort& vp);
void RegisterInit(CGameAttributes *pAttribs);
int Initialize(CGameAttributes *pGameAttributes);

View File

@ -76,7 +76,7 @@ LibError gfx_get_video_mode(int* xres, int* yres, int* bpp, int* freq)
*/
if(xres)
*xres = XDisplayWidth (disp, screen);
*xres = XDisplayWidth(disp, screen);
if(yres)
*yres = XDisplayHeight(disp, screen);
if(bpp)

View File

@ -53,6 +53,7 @@ that of Atlas depending on commandline parameters.
#include "ps/Game.h"
#include "ps/Hotkey.h"
#include "ps/Globals.h"
#include "ps/VideoMode.h"
#include "ps/XML/Xeromyces.h"
#include "network/NetClient.h"
#include "network/NetServer.h"
@ -81,6 +82,10 @@ static InReaction MainInputHandler(const SDL_Event_* ev)
kill_mainloop();
break;
case SDL_VIDEORESIZE:
g_VideoMode.ResizeWindow(ev->ev.resize.w, ev->ev.resize.h);
break;
case SDL_HOTKEYDOWN:
switch(ev->ev.user.code)
{
@ -96,6 +101,10 @@ static InReaction MainInputHandler(const SDL_Event_* ev)
WriteBigScreenshot(L".bmp", 10);
return IN_HANDLED;
case HOTKEY_TOGGLEFULLSCREEN:
g_VideoMode.ToggleFullscreen();
return IN_HANDLED;
default:
break;
}

View File

@ -17,7 +17,6 @@
#include "precompiled.h"
#include "ps/CLogger.h"
#include "ps/ConfigDB.h"
#include "ps/CConsole.h"
#include "ps/GameSetup/CmdLineArgs.h"
@ -26,8 +25,6 @@
#include "lib/res/sound/snd_mgr.h"
#include "Config.h"
#define LOG_CATEGORY L"config"
// (these variables are documented in the header.)
@ -49,8 +46,6 @@ bool g_EntGraph = false;
CStr g_RenderPath = "default";
int g_xres, g_yres;
int g_bpp;
int g_freq;
bool g_VSync = false;
bool g_Quickstart = false;
@ -93,8 +88,6 @@ static void LoadGlobals()
LoadProfile( g_ActiveProfile );
CFG_GET_USER_VAL("xres", Int, g_xres);
CFG_GET_USER_VAL("yres", Int, g_yres);
CFG_GET_USER_VAL("vsync", Bool, g_VSync);
CFG_GET_USER_VAL("nos3tc", Bool, g_NoGLS3TC);
@ -111,9 +104,6 @@ static void LoadGlobals()
CFG_GET_USER_VAL("sound.mastergain", Float, gain);
if(gain > 0.0f)
WARN_ERR(snd_set_master_gain(gain));
LOG(CLogger::Normal, LOG_CATEGORY, L"g_x/yres is %dx%d", g_xres, g_yres);
LOG(CLogger::Normal, LOG_CATEGORY, L"Active profile is %hs", g_ActiveProfile.c_str());
}

View File

@ -57,8 +57,6 @@ extern bool g_EntGraph;
extern CStr g_RenderPath;
extern int g_xres, g_yres;
extern int g_bpp;
extern int g_freq;
extern bool g_VSync;
extern bool g_Quickstart;

View File

@ -45,6 +45,7 @@
#include "ps/ProfileViewer.h"
#include "ps/StringConvert.h"
#include "ps/Util.h"
#include "ps/VideoMode.h"
#include "ps/World.h"
#include "ps/i18n.h"
@ -107,37 +108,6 @@ ERROR_TYPE(System, RequiredExtensionsMissing);
bool g_DoRenderGui = true;
static int SetVideoMode(int w, int h, int bpp, bool fullscreen)
{
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
Uint32 flags = SDL_OPENGL;
if(fullscreen)
flags |= SDL_FULLSCREEN;
if(!SDL_SetVideoMode(w, h, bpp, flags))
return -1;
// Work around a bug in the proprietary Linux ATI driver (at least versions 8.16.20 and 8.14.13).
// The driver appears to register its own atexit hook on context creation.
// If this atexit hook is called before SDL_Quit destroys the OpenGL context,
// some kind of double-free problem causes a crash and lockup in the driver.
// Calling SDL_Quit twice appears to be harmless, though, and avoids the problem
// by destroying the context *before* the driver's atexit hook is called.
// (Note that atexit hooks are guaranteed to be called in reverse order of their registration.)
atexit(SDL_Quit);
// End work around.
glViewport(0, 0, w, h);
ogl_Init(); // required after each mode change
if(SDL_SetGamma(g_Gamma, g_Gamma, g_Gamma) < 0)
LOGWARNING(L"SDL_SetGamma failed");
return 0;
}
static const int SANE_TEX_QUALITY_DEFAULT = 5; // keep in sync with code
static void SetTextureQuality(int quality)
@ -567,7 +537,7 @@ static void InitRenderer()
new CMaterialManager;
MICROLOG(L"init renderer");
g_Renderer.Open(g_xres,g_yres,g_bpp);
g_Renderer.Open(g_xres,g_yres);
// Setup lighting environment. Since the Renderer accesses the
// lighting environment through a pointer, this has to be done before
@ -760,10 +730,6 @@ void Init(const CmdLineArgs& args, int flags)
if(setup_vmode)
InitSDL();
// preferred video mode = current desktop settings
// (command line params may override these)
gfx_get_video_mode(&g_xres, &g_yres, &g_bpp, &g_freq);
new CProfileViewer;
new CProfileManager; // before any script code
@ -773,25 +739,10 @@ void Init(const CmdLineArgs& args, int flags)
// g_ConfigDB, command line args, globals
CONFIG_Init(args);
// setup_gui must be set after CONFIG_Init, so command-line parameters can disable it
const bool setup_gui = ((flags & INIT_NO_GUI) == 0);
// GUI is notified in SetVideoMode, so this must come before that.
g_GUI = new CGUIManager(g_ScriptingHost.GetScriptInterface());
// default to windowed, so users don't get stuck if e.g. half the
// filesystem is missing and the config files aren't loaded
bool windowed = true;
CFG_GET_SYS_VAL("windowed", Bool, windowed);
if(setup_vmode)
if (setup_vmode)
{
MICROLOG(L"SetVideoMode");
if(SetVideoMode(g_xres, g_yres, 32, !windowed) < 0)
{
LOG(CLogger::Error, LOG_CATEGORY, L"Could not set %dx%d graphics mode: %hs", g_xres, g_yres, SDL_GetError());
throw PSERROR_System_VmodeFailed();
}
if (!g_VideoMode.InitSDL())
throw PSERROR_System_VmodeFailed(); // abort startup
SDL_WM_SetCaption("0 A.D.", "0 A.D.");
}
@ -822,6 +773,8 @@ void Init(const CmdLineArgs& args, int flags)
snd_disable(true);
}
g_GUI = new CGUIManager(g_ScriptingHost.GetScriptInterface());
// (must come after SetVideoMode, since it calls ogl_Init)
const char* missing = ogl_HaveExtensions(0,
"GL_ARB_multitexture",
@ -875,6 +828,7 @@ void Init(const CmdLineArgs& args, int flags)
if (!Autostart(args))
{
const bool setup_gui = ((flags & INIT_NO_GUI) == 0);
InitPs(setup_gui, L"page_pregame.xml");
}
}

View File

@ -22,17 +22,10 @@
// GUI integration
//
extern void GUI_Init();
extern void GUI_Shutdown();
extern void GUI_ShowMainMenu();
// display progress / description in loading screen
extern void GUI_DisplayLoadProgress(int percent, const wchar_t* pending_task);
extern void Render();
extern void RenderActor();
/**
* initialize global modules that are be needed before Init.
@ -56,7 +49,10 @@ enum InitFlags
INIT_NO_SIM = 4
};
void RenderGui(bool RenderingState);
/**
* enable/disable rendering of the GUI (intended mainly for screenshots)
*/
extern void RenderGui(bool RenderingState);
class CmdLineArgs;
extern void Init(const CmdLineArgs& args, int flags);

View File

@ -72,6 +72,7 @@ static SHotkeyInfo hotkeyInfo[] =
{ HOTKEY_SCREENSHOT, "screenshot", SDLK_PRINT, 0 },
{ HOTKEY_BIGSCREENSHOT, "bigscreenshot", 0, 0 },
{ HOTKEY_WIREFRAME, "wireframe", SDLK_w, 0 },
{ HOTKEY_TOGGLEFULLSCREEN, "togglefullscreen", 0, 0 },
{ HOTKEY_CAMERA_RESET, "camera.reset", 0, 0 },
{ HOTKEY_CAMERA_RESET_ORIGIN, "camera.reset.origin", SDLK_h, 0 },
{ HOTKEY_CAMERA_ZOOM_IN, "camera.zoom.in", SDLK_PLUS, SDLK_KP_PLUS },

View File

@ -53,6 +53,7 @@ enum
HOTKEY_SCREENSHOT,
HOTKEY_BIGSCREENSHOT,
HOTKEY_WIREFRAME,
HOTKEY_TOGGLEFULLSCREEN,
HOTKEY_CAMERA_RESET,
HOTKEY_CAMERA_RESET_ORIGIN,
HOTKEY_CAMERA_ZOOM_IN,

View File

@ -37,6 +37,7 @@
#include "ps/GameSetup/GameSetup.h"
#include "ps/Game.h"
#include "ps/Filesystem.h"
#include "ps/VideoMode.h"
#include "renderer/Renderer.h"
#include "maths/MathUtil.h"
#include "graphics/GameView.h"
@ -117,7 +118,7 @@ void WriteSystemInfo()
// graphics
fprintf(f, "Graphics Card : %ls\n", gfx_card);
fprintf(f, "OpenGL Drivers : %s; %ls\n", glGetString(GL_VERSION), gfx_drv_ver);
fprintf(f, "Video Mode : %dx%d:%d@%d\n", g_xres, g_yres, g_bpp, g_freq);
fprintf(f, "Video Mode : %dx%d:%d\n", g_VideoMode.GetXRes(), g_VideoMode.GetYRes(), g_VideoMode.GetBPP());
// sound
fprintf(f, "Sound Card : %ls\n", snd_card);
@ -306,7 +307,7 @@ void WriteBigScreenshot(const std::wstring& extension, int tiles)
{
g_Renderer.Resize(tile_w, tile_h);
SViewPort vp = { 0, 0, tile_w, tile_h };
g_Game->GetView()->GetCamera()->SetViewPort(&vp);
g_Game->GetView()->GetCamera()->SetViewPort(vp);
g_Game->GetView()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
}
@ -358,7 +359,7 @@ void WriteBigScreenshot(const std::wstring& extension, int tiles)
{
g_Renderer.Resize(g_xres, g_yres);
SViewPort vp = { 0, 0, g_xres, g_yres };
g_Game->GetView()->GetCamera()->SetViewPort(&vp);
g_Game->GetView()->GetCamera()->SetViewPort(vp);
g_Game->GetView()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
g_Game->GetView()->GetCamera()->SetProjectionTile(1, 0, 0);

284
source/ps/VideoMode.cpp Normal file
View File

@ -0,0 +1,284 @@
/* Copyright (C) 2010 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#include "precompiled.h"
#include "VideoMode.h"
#include "graphics/Camera.h"
#include "graphics/GameView.h"
#include "gui/GUIManager.h"
#include "lib/ogl.h"
#include "lib/external_libraries/sdl.h"
#include "lib/sysdep/gfx.h"
#include "ps/CConsole.h"
#include "ps/CLogger.h"
#include "ps/ConfigDB.h"
#include "ps/Game.h"
#include "ps/GameSetup/Config.h"
#include "renderer/Renderer.h"
static int DEFAULT_WINDOW_W = 1024;
static int DEFAULT_WINDOW_H = 768;
static int DEFAULT_FULLSCREEN_W = 1024;
static int DEFAULT_FULLSCREEN_H = 768;
CVideoMode g_VideoMode;
CVideoMode::CVideoMode() :
m_IsInitialised(false),
m_PreferredW(0), m_PreferredH(0), m_PreferredBPP(0), m_PreferredFreq(0),
m_ConfigW(0), m_ConfigH(0), m_ConfigBPP(0), m_ConfigFullscreen(false),
m_WindowedW(DEFAULT_WINDOW_W), m_WindowedH(DEFAULT_WINDOW_H)
{
// (m_ConfigFullscreen defaults to false, so users don't get stuck if
// e.g. half the filesystem is missing and the config files aren't loaded)
}
void CVideoMode::ReadConfig()
{
bool windowed = !m_ConfigFullscreen;
CFG_GET_USER_VAL("windowed", Bool, windowed);
m_ConfigFullscreen = !windowed;
CFG_GET_USER_VAL("xres", Int, m_ConfigW);
CFG_GET_USER_VAL("yres", Int, m_ConfigH);
CFG_GET_USER_VAL("bpp", Int, m_ConfigBPP);
}
bool CVideoMode::SetVideoMode(int w, int h, int bpp, bool fullscreen)
{
Uint32 flags = SDL_OPENGL;
if (fullscreen)
flags |= SDL_FULLSCREEN;
else
flags |= SDL_RESIZABLE;
if (!SDL_SetVideoMode(w, h, bpp, flags))
{
LOGERROR(L"SetVideoMode failed: %dx%d:%d %d (\"%hs\")", w, h, bpp, fullscreen ? 1 : 0, SDL_GetError());
return false;
}
m_IsFullscreen = fullscreen;
m_CurrentW = w;
m_CurrentH = h;
m_CurrentBPP = bpp;
g_xres = w;
g_yres = h;
return true;
}
bool CVideoMode::InitSDL()
{
debug_assert(!m_IsInitialised);
ReadConfig();
// preferred video mode = current desktop settings
// (command line params may override these)
gfx_get_video_mode(&m_PreferredW, &m_PreferredH, &m_PreferredBPP, &m_PreferredFreq);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
int w = m_ConfigW;
int h = m_ConfigH;
if (m_ConfigFullscreen)
{
// If fullscreen and no explicit size set, default to the desktop resolution
if (w == 0 || h == 0)
{
w = m_PreferredW;
h = m_PreferredH;
}
}
// If no size determined, default to something sensible
if (w == 0 || h == 0)
{
w = DEFAULT_WINDOW_W;
h = DEFAULT_WINDOW_H;
}
int bpp = GetBestBPP();
if (!SetVideoMode(w, h, bpp, m_ConfigFullscreen))
return false;
// Work around a bug in the proprietary Linux ATI driver (at least versions 8.16.20 and 8.14.13).
// The driver appears to register its own atexit hook on context creation.
// If this atexit hook is called before SDL_Quit destroys the OpenGL context,
// some kind of double-free problem causes a crash and lockup in the driver.
// Calling SDL_Quit twice appears to be harmless, though, and avoids the problem
// by destroying the context *before* the driver's atexit hook is called.
// (Note that atexit hooks are guaranteed to be called in reverse order of their registration.)
atexit(SDL_Quit);
// End work around.
ogl_Init(); // required after each mode change
// (TODO: does that mean we need to call this when toggling fullscreen later?)
if (SDL_SetGamma(g_Gamma, g_Gamma, g_Gamma) < 0)
LOGWARNING(L"SDL_SetGamma failed");
m_IsInitialised = true;
if (!m_ConfigFullscreen)
{
m_WindowedW = w;
m_WindowedH = h;
}
return true;
}
bool CVideoMode::ResizeWindow(int w, int h)
{
debug_assert(m_IsInitialised);
// Ignore if not windowed
if (m_IsFullscreen)
return true;
int bpp = GetBestBPP();
if (!SetVideoMode(w, h, bpp, false))
return false;
m_WindowedW = w;
m_WindowedH = h;
UpdateRenderer(w, h);
return true;
}
bool CVideoMode::SetFullscreen(bool fullscreen)
{
debug_assert(m_IsInitialised);
// Check whether this is actually a change
if (fullscreen == m_IsFullscreen)
return true;
if (!m_IsFullscreen)
{
// Windowed -> fullscreen:
int w = 0, h = 0;
// If a fullscreen size was configured, use that; else use the desktop size; else use a default
if (m_ConfigFullscreen)
{
w = m_ConfigW;
h = m_ConfigH;
}
if (w == 0 || h == 0)
{
w = m_PreferredW;
h = m_PreferredH;
}
if (w == 0 || h == 0)
{
w = DEFAULT_FULLSCREEN_W;
h = DEFAULT_FULLSCREEN_H;
}
int bpp = GetBestBPP();
if (!SetVideoMode(w, h, bpp, fullscreen))
return false;
UpdateRenderer(w, h);
return true;
}
else
{
// Fullscreen -> windowed:
// Go back to whatever the previous window size was
int w = m_WindowedW, h = m_WindowedH;
int bpp = GetBestBPP();
if (!SetVideoMode(w, h, bpp, fullscreen))
return false;
UpdateRenderer(w, h);
return true;
}
}
bool CVideoMode::ToggleFullscreen()
{
return SetFullscreen(!m_IsFullscreen);
}
void CVideoMode::UpdateRenderer(int w, int h)
{
if (w < 2) w = 2; // avoid GL errors caused by invalid sizes
if (h < 2) h = 2;
g_xres = w;
g_yres = h;
SViewPort vp = { 0, 0, w, h };
g_Renderer.SetViewport(vp);
g_Renderer.Resize(w, h);
g_GUI->UpdateResolution();
g_Console->UpdateScreenSize(w, h);
if (g_Game)
g_Game->GetView()->SetViewport(vp);
}
int CVideoMode::GetBestBPP()
{
if (m_ConfigBPP)
return m_ConfigBPP;
if (m_PreferredBPP)
return m_PreferredBPP;
return 32;
}
int CVideoMode::GetXRes()
{
debug_assert(m_IsInitialised);
return m_CurrentW;
}
int CVideoMode::GetYRes()
{
debug_assert(m_IsInitialised);
return m_CurrentH;
}
int CVideoMode::GetBPP()
{
debug_assert(m_IsInitialised);
return m_CurrentBPP;
}

92
source/ps/VideoMode.h Normal file
View File

@ -0,0 +1,92 @@
/* Copyright (C) 2010 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_VIDEOMODE
#define INCLUDED_VIDEOMODE
class CVideoMode
{
public:
CVideoMode();
/**
* Initialise the video mode, for use in an SDL-using application.
*/
bool InitSDL();
/**
* Resize the SDL window and associated graphics stuff to the new size.
*/
bool ResizeWindow(int w, int h);
/**
* Switch to fullscreen or windowed mode.
*/
bool SetFullscreen(bool fullscreen);
/**
* Switch between fullscreen and windowed mode.
*/
bool ToggleFullscreen();
/**
* Update the graphics code to start drawing to the new size.
* This should be called after the GL context has been resized.
* This can also be used when the GL context is managed externally, not via SDL.
*/
static void UpdateRenderer(int w, int h);
int GetXRes();
int GetYRes();
int GetBPP();
private:
void ReadConfig();
int GetBestBPP();
bool SetVideoMode(int w, int h, int bpp, bool fullscreen);
bool m_IsInitialised;
// Initial desktop settings
int m_PreferredW;
int m_PreferredH;
int m_PreferredBPP;
int m_PreferredFreq;
// Config file settings (0 if unspecified)
int m_ConfigW;
int m_ConfigH;
int m_ConfigBPP;
bool m_ConfigFullscreen;
// If we're fullscreen, size of window when we were last windowed (or the default window size
// if we started fullscreen), to support switching back to the old window size
int m_WindowedW;
int m_WindowedH;
// Whether we're currently being displayed fullscreen
bool m_IsFullscreen;
// The last mode selected
int m_CurrentW;
int m_CurrentH;
int m_CurrentBPP;
};
extern CVideoMode g_VideoMode;
#endif // INCLUDED_VIDEOMODE

View File

@ -351,7 +351,6 @@ CRenderer::CRenderer()
m_Width=0;
m_Height=0;
m_Depth=0;
m_FrameCounter=0;
m_TerrainRenderMode=SOLID;
m_ModelRenderMode=SOLID;
@ -470,7 +469,7 @@ void CRenderer::EnumCaps()
}
bool CRenderer::Open(int width, int height, int depth)
bool CRenderer::Open(int width, int height)
{
m->IsOpen = true;
@ -540,7 +539,6 @@ bool CRenderer::Open(int width, int height, int depth)
// Dimensions
m_Width = width;
m_Height = height;
m_Depth = depth;
// set packing parameters
glPixelStorei(GL_PACK_ALIGNMENT,1);
@ -1075,7 +1073,7 @@ void CRenderer::RenderReflections()
vp.m_Width = wm.m_ReflectionTextureSize;
vp.m_X = 0;
vp.m_Y = 0;
m_ViewCamera.SetViewPort(&vp);
m_ViewCamera.SetViewPort(vp);
m_ViewCamera.SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV*1.05f); // Slightly higher than view FOV
CMatrix3D scaleMat;
scaleMat.SetScaling(m_Height/float(std::max(1, m_Width)), 1.0f, 1.0f);
@ -1147,7 +1145,7 @@ void CRenderer::RenderRefractions()
vp.m_Width = wm.m_RefractionTextureSize;
vp.m_X = 0;
vp.m_Y = 0;
m_ViewCamera.SetViewPort(&vp);
m_ViewCamera.SetViewPort(vp);
m_ViewCamera.SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV*1.05f); // Slightly higher than view FOV
CMatrix3D scaleMat;
scaleMat.SetScaling(m_Height/float(std::max(1, m_Width)), 1.0f, 1.0f);

View File

@ -162,7 +162,7 @@ public:
~CRenderer();
// open up the renderer: performs any necessary initialisation
bool Open(int width,int height,int depth);
bool Open(int width,int height);
// resize renderer view
void Resize(int width,int height);
@ -375,9 +375,7 @@ protected:
// view width
int m_Width;
// view height
int m_Height;
// view depth (bpp)
int m_Depth;
int m_Height;
// frame counter
int m_FrameCounter;
// current terrain rendering mode

View File

@ -48,8 +48,6 @@
#include <algorithm>
extern int g_xres, g_yres;
void CEntity::Render()
{
if( !m_visible ) return;

View File

@ -30,6 +30,7 @@
#include "maths/MathUtil.h"
#include "ps/CConsole.h"
#include "ps/Game.h"
#include "ps/VideoMode.h"
#include "ps/GameSetup/Config.h"
#include "ps/GameSetup/GameSetup.h"
#include "renderer/Renderer.h"
@ -169,19 +170,7 @@ MESSAGEHANDLER(SetCanvas)
MESSAGEHANDLER(ResizeScreen)
{
g_xres = msg->width;
g_yres = msg->height;
if (g_xres <= 2) g_xres = 2; // avoid GL errors caused by invalid sizes
if (g_yres <= 2) g_yres = 2;
SViewPort vp = { 0, 0, g_xres, g_yres };
g_Renderer.SetViewport(vp);
g_Renderer.Resize(g_xres, g_yres);
g_GUI->UpdateResolution();
g_Console->UpdateScreenSize(g_xres, g_yres);
CVideoMode::UpdateRenderer(msg->width, msg->height);
}
//////////////////////////////////////////////////////////////////////////

View File

@ -59,7 +59,7 @@ QUERYHANDLER(CinemaRecord)
{
g_Renderer.Resize(w, h);
SViewPort vp = { 0, 0, w, h };
g_Game->GetView()->GetCamera()->SetViewPort(&vp);
g_Game->GetView()->GetCamera()->SetViewPort(vp);
g_Game->GetView()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
}
@ -112,7 +112,7 @@ QUERYHANDLER(CinemaRecord)
{
g_Renderer.Resize(g_xres, g_yres);
SViewPort vp = { 0, 0, g_xres, g_yres };
g_Game->GetView()->GetCamera()->SetViewPort(&vp);
g_Game->GetView()->GetCamera()->SetViewPort(vp);
g_Game->GetView()->GetCamera()->SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
}

View File

@ -78,7 +78,7 @@ void ViewActor::Render()
{
SViewPort vp = { 0, 0, g_xres, g_yres };
CCamera& camera = GetCamera();
camera.SetViewPort(&vp);
camera.SetViewPort(vp);
camera.SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
camera.UpdateFrustum();
@ -211,7 +211,7 @@ void ViewGame::Render()
{
SViewPort vp = { 0, 0, g_xres, g_yres };
CCamera& camera = GetCamera();
camera.SetViewPort(&vp);
camera.SetViewPort(vp);
camera.SetProjection(CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
camera.UpdateFrustum();