mirror of
https://github.com/glest/glest-source.git
synced 2025-08-10 10:24:01 +02:00
- Some improvements for setting max videomode when AutoMaxFullScreen=true and Windowed=false
- Added better logic to try to restore video when crashing
This commit is contained in:
@@ -57,6 +57,7 @@ public:
|
|||||||
message("An error ocurred and Glest will close.\nError msg = [" + (msg != NULL ? string(msg) : string("?")) + "]\n\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file.");
|
message("An error ocurred and Glest will close.\nError msg = [" + (msg != NULL ? string(msg) : string("?")) + "]\n\nPlease report this bug to "+mailString+", attaching the generated "+getCrashDumpFileName()+" file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restoreVideoMode(true);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +72,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(exitApp == true) {
|
if(exitApp == true) {
|
||||||
|
restoreVideoMode(true);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +205,6 @@ int glestMain(int argc, char** argv){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const exception &e){
|
catch(const exception &e){
|
||||||
restoreVideoMode();
|
|
||||||
//exceptionMessage(e);
|
//exceptionMessage(e);
|
||||||
ExceptionHandler::handleRuntimeError(e.what());
|
ExceptionHandler::handleRuntimeError(e.what());
|
||||||
}
|
}
|
||||||
|
@@ -99,7 +99,7 @@ string extractDirectoryPathFromFile(string filename);
|
|||||||
|
|
||||||
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight);
|
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight);
|
||||||
bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency);
|
bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency);
|
||||||
void restoreVideoMode();
|
void restoreVideoMode(bool exitingApp=false);
|
||||||
|
|
||||||
bool EndsWith(const string &str, const string& key);
|
bool EndsWith(const string &str, const string& key);
|
||||||
void message(string message);
|
void message(string message);
|
||||||
|
@@ -108,7 +108,7 @@ string extractDirectoryPathFromFile(string filename);
|
|||||||
|
|
||||||
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight);
|
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight);
|
||||||
bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency);
|
bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency);
|
||||||
void restoreVideoMode();
|
void restoreVideoMode(bool exitingApp=false);
|
||||||
|
|
||||||
bool EndsWith(const string &str, const string& key);
|
bool EndsWith(const string &str, const string& key);
|
||||||
void message(string message);
|
void message(string message);
|
||||||
|
128
source/shared_lib/sources/platform/sdl/gl_wrap.cpp
Normal file
128
source/shared_lib/sources/platform/sdl/gl_wrap.cpp
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
//This file is part of Glest Shared Library (www.glest.org)
|
||||||
|
//Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||||
|
|
||||||
|
//You can redistribute this code 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.
|
||||||
|
#include "gl_wrap.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#ifdef X11_AVAILABLE
|
||||||
|
#include <GL/glx.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "opengl.h"
|
||||||
|
#include "sdl_private.h"
|
||||||
|
#include "noimpl.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
using namespace Shared::Graphics::Gl;
|
||||||
|
using namespace Shared::Util;
|
||||||
|
|
||||||
|
namespace Shared{ namespace Platform{
|
||||||
|
|
||||||
|
// ======================================
|
||||||
|
// class PlatformContextGl
|
||||||
|
// ======================================
|
||||||
|
|
||||||
|
void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits) {
|
||||||
|
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 1);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 1);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 1);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencilBits);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depthBits);
|
||||||
|
int flags = SDL_OPENGL;
|
||||||
|
if(Private::shouldBeFullscreen)
|
||||||
|
flags |= SDL_FULLSCREEN;
|
||||||
|
|
||||||
|
int resW = Private::ScreenWidth;
|
||||||
|
int resH = Private::ScreenHeight;
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to set resolution: %d x %d, colorBits = %d.\n",__FILE__,__FUNCTION__,__LINE__,resW,resH,colorBits);
|
||||||
|
|
||||||
|
SDL_Surface* screen = SDL_SetVideoMode(resW, resH, colorBits, flags);
|
||||||
|
if(screen == 0) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Couldn't set video mode "
|
||||||
|
<< resW << "x" << resH << " (" << colorBits
|
||||||
|
<< "bpp " << stencilBits << " stencil "
|
||||||
|
<< depthBits << " depth-buffer). SDL Error is: " << SDL_GetError();
|
||||||
|
throw std::runtime_error(msg.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlatformContextGl::end() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlatformContextGl::makeCurrent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlatformContextGl::swapBuffers() {
|
||||||
|
SDL_GL_SwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================================
|
||||||
|
// Global Fcs
|
||||||
|
// ======================================
|
||||||
|
|
||||||
|
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width,
|
||||||
|
int charCount, FontMetrics &metrics) {
|
||||||
|
#ifdef X11_AVAILABLE
|
||||||
|
Display* display = glXGetCurrentDisplay();
|
||||||
|
if(display == 0) {
|
||||||
|
throw std::runtime_error("Couldn't create font: display is 0");
|
||||||
|
}
|
||||||
|
XFontStruct* fontInfo = XLoadQueryFont(display, type.c_str());
|
||||||
|
if(!fontInfo) {
|
||||||
|
throw std::runtime_error("Font not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// we need the height of 'a' which sould ~ be half ascent+descent
|
||||||
|
metrics.setHeight(static_cast<float>
|
||||||
|
(fontInfo->ascent + fontInfo->descent) / 2);
|
||||||
|
for(unsigned int i = 0; i < static_cast<unsigned int> (charCount); ++i) {
|
||||||
|
if(i < fontInfo->min_char_or_byte2 ||
|
||||||
|
i > fontInfo->max_char_or_byte2) {
|
||||||
|
metrics.setWidth(i, static_cast<float>(6));
|
||||||
|
} else {
|
||||||
|
int p = i - fontInfo->min_char_or_byte2;
|
||||||
|
metrics.setWidth(i, static_cast<float> (
|
||||||
|
fontInfo->per_char[p].rbearing
|
||||||
|
- fontInfo->per_char[p].lbearing));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glXUseXFont(fontInfo->fid, 0, charCount, base);
|
||||||
|
XFreeFont(display, fontInfo);
|
||||||
|
#else
|
||||||
|
// we badly need a solution portable to more than just glx
|
||||||
|
NOIMPL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void createGlFontOutlines(uint32 &base, const string &type, int width,
|
||||||
|
float depth, int charCount, FontMetrics &metrics) {
|
||||||
|
NOIMPL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *getPlatformExtensions(const PlatformContextGl *pcgl) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void *getGlProcAddress(const char *procName) {
|
||||||
|
void* proc = SDL_GL_GetProcAddress(procName);
|
||||||
|
assert(proc!=NULL);
|
||||||
|
return proc;
|
||||||
|
}
|
||||||
|
|
||||||
|
}}//end namespace
|
@@ -437,10 +437,60 @@ void createDirectoryPaths(string Path)
|
|||||||
|
|
||||||
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight) {
|
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight) {
|
||||||
// Get the current video hardware information
|
// Get the current video hardware information
|
||||||
const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo();
|
//const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo();
|
||||||
colorBits = vidInfo->vfmt->BitsPerPixel;
|
//colorBits = vidInfo->vfmt->BitsPerPixel;
|
||||||
screenWidth = vidInfo->current_w;
|
//screenWidth = vidInfo->current_w;
|
||||||
screenHeight = vidInfo->current_h;
|
//screenHeight = vidInfo->current_h;
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
/* Get available fullscreen/hardware modes */
|
||||||
|
SDL_Rect**modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
|
||||||
|
|
||||||
|
/* Check if there are any modes available */
|
||||||
|
if (modes == (SDL_Rect**)0) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] no hardware modes available.\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo();
|
||||||
|
colorBits = vidInfo->vfmt->BitsPerPixel;
|
||||||
|
screenWidth = vidInfo->current_w;
|
||||||
|
screenHeight = vidInfo->current_h;
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] using current resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,screenWidth,screenHeight);
|
||||||
|
}
|
||||||
|
/* Check if our resolution is restricted */
|
||||||
|
else if (modes == (SDL_Rect**)-1) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] all resolutions available.\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo();
|
||||||
|
colorBits = vidInfo->vfmt->BitsPerPixel;
|
||||||
|
screenWidth = vidInfo->current_w;
|
||||||
|
screenHeight = vidInfo->current_h;
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] using current resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,screenWidth,screenHeight);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
/* Print valid modes */
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] available Modes are:\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
int bestW = -1;
|
||||||
|
int bestH = -1;
|
||||||
|
for(int i=0; modes[i]; ++i) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%d x %d\n",modes[i]->w, modes[i]->h);
|
||||||
|
|
||||||
|
if(bestW < modes[i]->w) {
|
||||||
|
bestW = modes[i]->w;
|
||||||
|
bestH = modes[i]->h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bestW > screenWidth) {
|
||||||
|
screenWidth = bestW;
|
||||||
|
screenHeight = bestH;
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] using current resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,screenWidth,screenHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool changeVideoMode(int resW, int resH, int colorBits, int ) {
|
bool changeVideoMode(int resW, int resH, int colorBits, int ) {
|
||||||
@@ -448,7 +498,8 @@ bool changeVideoMode(int resW, int resH, int colorBits, int ) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void restoreVideoMode() {
|
void restoreVideoMode(bool exitingApp) {
|
||||||
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void message(string message) {
|
void message(string message) {
|
||||||
|
@@ -535,7 +535,7 @@ bool changeVideoMode(int resW, int resH, int colorBits, int refreshFrequency){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void restoreVideoMode(){
|
void restoreVideoMode(bool exitingApp) {
|
||||||
int dispChangeErr= ChangeDisplaySettings(NULL, 0);
|
int dispChangeErr= ChangeDisplaySettings(NULL, 0);
|
||||||
assert(dispChangeErr==DISP_CHANGE_SUCCESSFUL);
|
assert(dispChangeErr==DISP_CHANGE_SUCCESSFUL);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user