Re #195 (Problems with Display configuration menu) : Use SDL to detect supported color depths and screen sizes, may be different in Windowed and Full-screen mode, hard-coded list as a fallback + tgf/tgfclient API consistency improvements

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@2831 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: c258e69db3ed6abef61ffaad14da4ad644026677
Former-commit-id: 4661d482f43df57e9ad6c2a5a79d00d808af1e2a
This commit is contained in:
pouillot 2010-10-03 13:30:22 +00:00
parent 67356061a3
commit b6f55cba4f
15 changed files with 622 additions and 525 deletions

View file

@ -2,6 +2,8 @@ INCLUDE(../../../cmake/macros.cmake)
#PROJECT(tgf)
ADD_SDL_INCLUDEDIR()
ADD_OSSPEC_INCLUDEDIR()
ADD_SDLIB_INCLUDEDIR(txml portability)
@ -27,6 +29,8 @@ ENDIF(CMAKE_SKIP_RPATH OR CMAKE_SKIP_BUILD_RPATH)
ADD_SDLIB_LIBRARY(tgf txml)
ADD_SDL_LIBRARY(tgf)
IF(WIN32)
SD_INSTALL_FILES(BIN TARGETS tgf)
ELSE(WIN32)

View file

@ -30,6 +30,8 @@
#include <ctime>
#include <cstring>
#include <SDL/SDL.h>
#include "tgf.h"
#include "portability.h"
@ -410,7 +412,29 @@ char * _tgf_win_strdup(const char * str)
}
#endif // WIN32
// Build a new path string compatible with current OS and usable as a command line arg.
static char* gfPathBuildCommandLineArg(const char *path)
{
#ifdef WIN32
char *osPath = (char*)malloc(strlen(path)+3);
sprintf(osPath, "\"%s", path);
if (osPath[strlen(osPath)-1] == '/')
osPath[strlen(osPath)-1] = 0; // Remove trailing '/' for command line
strcat(osPath, "\"");
#else
char *osPath = strdup(path);
#endif //WIN32
GfPathMakeOSCompatible(osPath);
return osPath;
}
/** Initialize the gaming framework.
@ingroup tgf
@return None
*/
void GfInit(void)
{
gfTraceInit();
@ -418,9 +442,112 @@ void GfInit(void)
gfModInit();
gfOsInit();
gfParamInit();
// Initialize SDL subsystems usefull for TGF.
if (SDL_Init(SDL_INIT_TIMER) < 0)
GfLogFatal("Couldn't initialize SDL(timer) (%s)\n", SDL_GetError());
}
/** Restart the gaming framework (restart the current process).
@ingroup tgf
@param sec Time to convert
@param plus String to display as the positive sign (+) for positive values of time.
@return None
@warning Never returns (retart the process).
*/
void GfRestart(bool bHardwareMouse, bool bMultiTexturing)
{
int retcode = 0;
static const int CMDSIZE = 1024;
char cmd[CMDSIZE];
char** args;
int i, nArgs;
int argInd;
// Command name.
sprintf(cmd, "%sspeed-dreams", GetBinDir());
#ifdef WIN32
strcat(cmd, ".exe");
#endif
GfPathMakeOSCompatible(cmd);
// Compute number of args.
nArgs = 1; // Executable is always the first arg.
if (bHardwareMouse)
nArgs += 1;
if (!bMultiTexturing)
nArgs += 1;
if (GetLocalDir() && strlen(GetLocalDir()))
nArgs += 2;
if (GetBinDir() && strlen(GetBinDir()))
nArgs += 2;
if (GetLibDir() && strlen(GetLibDir()))
nArgs += 2;
if (GetDataDir() && strlen(GetDataDir()))
nArgs += 2;
nArgs++; // Last arg must be a null pointer.
// Allocate args array.
args = (char**)malloc(sizeof(char*)*nArgs);
// First arg is the executable path-name.
argInd = 0;
args[argInd++] = gfPathBuildCommandLineArg(cmd);
// Then add subsequent args.
if (bHardwareMouse)
args[argInd++] = strdup("-m");
if (!bMultiTexturing)
args[argInd++] = strdup("-s");
if (GetLocalDir() && strlen(GetLocalDir()))
{
args[argInd++] = strdup("-l");
args[argInd++] = gfPathBuildCommandLineArg(GetLocalDir());
}
if (GetBinDir() && strlen(GetBinDir()))
{
args[argInd++] = strdup("-B");
args[argInd++] = gfPathBuildCommandLineArg(GetBinDir());
}
if (GetLibDir() && strlen(GetLibDir()))
{
args[argInd++] = strdup("-L");
args[argInd++] = gfPathBuildCommandLineArg(GetLibDir());
}
if (GetDataDir() && strlen(GetDataDir()))
{
args[argInd++] = strdup("-D");
args[argInd++] = gfPathBuildCommandLineArg(GetDataDir ());
}
// Finally, last null arg.
args[argInd] = 0;
// Exec the command : restart the game (simply replacing current process)
GfLogInfo("Restarting ");
for (i = 0; args[i]; i++)
GfLogInfo("%s ", args[i]);
GfLogInfo("...\n");
retcode = execvp(cmd, args);
// If successfull, we never get here ... but if failed ...
GfLogError("Failed to restart (exit code %d, %s)\n", retcode, strerror(errno));
for (i = 0; args[i]; i++)
free(args[i]);
free(args);
exit(1);
}
void gfMeanReset(tdble v, tMeanVal *pvt)
{
int i;
@ -460,7 +587,7 @@ tdble gfMean(tdble v, tMeanVal *pvt, int n, int w)
/** Convert a time in seconds (float) to an ascii string.
@ingroup screen
@ingroup tgf
@param sec Time to convert
@param plus String to display as the positive sign (+) for positive values of time.
@param zeros Flag to indicate if heading zeros are to be displayed or not.
@ -505,6 +632,23 @@ char* GfTime2Str(double sec, const char* plus, bool zeros, int prec)
return buf;
}
/** In-place convert internal file or dir path to an OS compatible path
@ingroup tgf
@param path The path to convert
@return The converted path.
*/
// In-place convert internal file or dir path to an OS compatible path
char* GfPathMakeOSCompatible(char* path)
{
#ifdef WIN32
size_t i;
for (i = 0; i < strlen(path); i++)
if (path[i] == '/')
path[i] = '\\';
#endif //WIN32
return path;
}
// Determine if a dir or file path is absolute or not.
bool GfPathIsAbsolute(const char *pszPath)
{
@ -733,21 +877,6 @@ const char* SetBinDir(const char *pszPath)
}
static int singleTextureMode = 0;
int GetSingleTextureMode (void)
{
return singleTextureMode;
}
void SetSingleTextureMode (void)
{
singleTextureMode = 1;
}
// Nearest power of 2 integer
int GfNearestPow2 (int x)
{

View file

@ -164,10 +164,12 @@ typedef struct
t3Dd M; /**< Moments */
} tForces;
/***********************************
* Gaming framework initialization *
***********************************/
/******************************
* Gaming framework managment *
******************************/
TGF_API void GfInit(void);
TGF_API void GfRestart(bool bHardwareMouse = false, bool bSingleTexturing = false);
/************************************************************************
* Memory pools *
@ -262,6 +264,7 @@ TGF_API void GfDirFreeList(tFList *list, tfDirfreeUserData freeUserData, bool fr
TGF_API bool GfPathIsAbsolute(const char *pszPath);
TGF_API char* GfPathNormalizeDir(char* pszPath, size_t nMaxPathLen);
TGF_API char* GfPathMakeOSCompatible(char* path);
/**********************************
* Interface For Parameter Files *
@ -420,6 +423,11 @@ static inline void GfLogMessage(int nLevel, const char *pszFmt, ...) {};
TGF_API double GfTimeClock(void);
TGF_API char *GfTime2Str(double sec, const char* plus="", bool zeros=true, int prec=3);
/******************
* Miscellaneous. *
******************/
TGF_API int GfNearestPow2(int x);
/* Mean values */
#define GF_MEAN_MAX_VAL 5
@ -456,13 +464,9 @@ TGF_API const char *SetDataDir(const char *pszPath);
TGF_API const char *GetBinDir();
TGF_API const char *SetBinDir(const char *pszPath);
/* MISC */
TGF_API int GetSingleTextureMode();
TGF_API void SetSingleTextureMode();
TGF_API int GfNearestPow2(int x);
/* Settings files run-time setup */
/************************************************
* User settings files run-time update/install. *
************************************************/
TGF_API void GfFileSetup();

View file

@ -14,9 +14,10 @@ ADD_PLIB_INCLUDEDIR()
SET(TGFCLIENT_SOURCES control.cpp glfeatures.cpp guibutton.cpp guifont.cpp
guiimage.cpp guimenu.cpp guiscrollbar.cpp guitexture.cpp
tgfclient.cpp gui.cpp guiedit.cpp guihelp.cpp
guilabel.cpp guiobject.cpp guiscrollist.cpp guicombobox.cpp guicheckbox.cpp guiprogresbar.cpp
screen.cpp guieventloop.cpp glfeatures.h gui.h screen_properties.h
guimenu.h tgfclient.h guifont.h )
guilabel.cpp guiobject.cpp guiscrollist.cpp
guicombobox.cpp guicheckbox.cpp guiprogresbar.cpp
guiscreen.cpp guieventloop.cpp
glfeatures.h gui.h guiscreen.h guimenu.h tgfclient.h guifont.h )
#disable developer warning
IF (COMMAND CMAKE_POLICY)
@ -71,5 +72,5 @@ ENDIF(UNIX)
SD_INSTALL_FILES(DATA config USER config FILES screen.xml)
SD_INSTALL_FILES(INCLUDE FILES glfeatures.h screen_properties.h tgfclient.h)
SD_INSTALL_FILES(INCLUDE FILES glfeatures.h guiscreen.h tgfclient.h)

View file

@ -190,6 +190,24 @@ int GfglGetUserTextureMaxSize(void)
}
/*
----------------------- Multi-texturing (anti-aliasing) support.
*/
static bool bMultiTexturingEnabled = true;
bool GfglIsMultiTexturingEnabled()
{
return bMultiTexturingEnabled;
}
void GfglEnableMultiTexturing(bool bEnable)
{
bMultiTexturingEnabled = bEnable;
}
/*
----------------------- Non-power of 2 size texture support.
*/

View file

@ -382,8 +382,6 @@ extern void gfuiScrollListPrevElt (tGfuiObject *object);
extern void gfuiReleaseImage(tGfuiObject *obj);
extern void gfuiDrawImage(tGfuiObject *obj);
extern SDL_Surface* gfScrGetScreenSurface();
#endif /* _GUI_H__ */

View file

@ -28,6 +28,7 @@ typedef struct
} tMnuCallbackInfo;
extern void gfMenuInit(void);
#endif /* __MENU__H__ */

View file

@ -42,18 +42,6 @@
#include <process.h>
#endif /* WIN32 */
#if defined(WIN32) || defined(__APPLE__)
#undef USE_RANDR_EXT
#endif // WIN32
#ifdef USE_RANDR_EXT
#include <GL/glx.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/extensions/Xrandr.h>
#endif // USE_RANDR_EXT
#include <SDL/SDL.h>
#include <portability.h>
@ -75,213 +63,247 @@ static int GfScrCenY;
SDL_Surface *ScreenSurface = NULL;
static void *scrHandle = NULL;
static char buf[1024];
/* Default list of resolutions in case no RANDR_EXT (Windows)
or something went wrong during resolution detection */
static const char *DefRes[] =
{ "320x200",
"320x240",
"400x300",
"416x312",
"480x360",
"512x384",
"576x384",
"576x432",
"640x384",
"640x400",
"640x480",
"640x512",
"700x525",
"720x450",
"800x512",
"800x512",
"800x600",
"832x624",
"840x525",
"896x672",
"928x696",
"960x600",
"960x720",
"960x1200",
"1024x768",
"1152x768",
"1152x864",
"1280x720",
"1280x768",
"1280x800",
"1280x960",
"1280x1024",
"1400x1050",
"1440x900",
"1600x900",
"1600x1024",
"1680x1050",
"1792x1344",
"1800x1440",
"1920x1200" };
static const int NbDefRes = sizeof(DefRes) / sizeof(DefRes[0]);
/* Default list of screen sizes ("resolutions") in case
something went wrong during hardware / driver capabilities detection */
static tScreenSize ADefScreenSizes[] =
{
{ 320, 200 },
{ 320, 240 },
{ 400, 300 },
{ 416, 312 },
{ 480, 360 },
{ 512, 384 },
{ 576, 384 },
{ 576, 432 },
{ 640, 384 },
{ 640, 400 },
{ 640, 480 },
{ 640, 512 },
{ 700, 525 },
{ 720, 450 },
{ 800, 512 },
{ 800, 600 },
{ 832, 624 },
{ 840, 525 },
{ 896, 672 },
{ 928, 696 },
{ 960, 600 },
{ 960, 720 },
{ 960, 1200 },
{ 1024, 768 },
{ 1152, 768 },
{ 1152, 864 },
{ 1280, 720 },
{ 1280, 768 },
{ 1280, 800 },
{ 1280, 960 },
{ 1280, 1024 },
{ 1400, 1050 },
{ 1440, 900 },
{ 1600, 900 },
{ 1600, 1024 },
{ 1680, 1050 },
{ 1792, 1344 },
{ 1800, 1440 },
{ 1920, 1080 },
{ 1920, 1200 },
};
static const int NDefScreenSizes = sizeof(ADefScreenSizes) / sizeof(ADefScreenSizes[0]);
#ifdef USE_RANDR_EXT
static char **Res = NULL;
static int nbRes = 0;
#else // USE_RANDR_EXT
static const char **Res = DefRes;
static int nbRes = NbDefRes;
#endif // USE_RANDR_EXT
static tScreenSize* AScreenSizes = 0;
static int NScreenSizes = 0;
static const char *Mode[] = {"Full-screen mode", "Window mode"};
static const char *VInit[] = {GFSCR_VAL_VINIT_COMPATIBLE, GFSCR_VAL_VINIT_BEST};
static const char *Depthlist[] = {"24", "32", "16"};
static const char* ADisplayModes[] = { "Full-screen", "Windowed" };
static const int NDisplayModes = sizeof(ADisplayModes) / sizeof(ADisplayModes[0]);
static const int nbMode = sizeof(Mode) / sizeof(Mode[0]);
static const int nbVInit = sizeof(VInit) / sizeof(VInit[0]);
static const int nbDepth = sizeof(Depthlist) / sizeof(Depthlist[0]);
static const char* AVideoInitModes[] = { "Compatible", "Best possible" };
static const int NVideoInitModes = sizeof(AVideoInitModes) / sizeof(AVideoInitModes[0]);
static int curRes = 0;
static int curMode = 0;
static int curDepth = 0;
static int curVInit = 0;
static int* AColorDepths = 0;
static int NColorDepths = 0;
static int curMaxFreq = 75;
static int NCurScreenSize = 0;
static int NCurDisplayMode = 0;
static int NCurColorDepth = 0;
static int NCurVideoInitMode = 0;
static int NCurMaxFreq = 75;
static int ScreenSizeLabelId;
static int ColorDepthLabelId;
static int DisplayModeLabelId;
static int VideoInitModeLabelId;
#ifdef WIN32
static int MaxFreqId;
static int MaxFreqEditId;
#endif
static int ResLabelId;
static int DepthLabelId;
static int ModeLabelId;
static int VInitLabelId;
static void *paramHdle;
void
gfScreenInit(void)
/** Get the possible screen / windows sizes (pixels) for the given color depth and display mode.
@ingroup screen
@param nColorDepth Requested color depth (bits)
@param bFullScreen Requested display mode : full-screeen mode if true, windowed otherwise.
@param pnSizes Address of number of detected possible sizes (output) (-1 if any size is possible).
@return Array of detected possible sizes (allocated on the heap, must use free at the end), or 0 if no detected possible size, or -1 if any size is possible.
*/
tScreenSize* GfScrGetPossibleSizes(int nColorDepth, bool bFullScreen, int* pnSizes)
{
#ifdef USE_RANDR_EXT
// Get display, screen and root window handles.
const char *displayname = getenv("DISPLAY");
if (displayname == 0) {
displayname = ":0.0";
}
Display *display = XOpenDisplay(displayname);
if( display) {
// If we have a display fill in the resolutions advertised by Xrandr.
int screen = DefaultScreen(display);
Window root = RootWindow(display, screen);
XRRScreenConfiguration *screenconfig = XRRGetScreenInfo (display, root);
if (screenconfig) {
int i, j, nsize;
XRRScreenSize *sizes = XRRConfigSizes(screenconfig, &nsize);
GfOut("X Supported resolutions :");
if (nsize > 0) {
// Force 320x200, 640x480, 800x600 to be available to the user,
// even if X did not report about.
int check_resx[] = {320, 640, 800};
int check_resy[] = {240, 480, 600};
bool mode_in_list[] = {false, false, false};
int add_modes = sizeof(check_resx)/sizeof(check_resx[0]);
for (i = 0; i < nsize; i++) {
GfOut(" %dx%d", sizes[i].width, sizes[i].height);
for (j = 0; j < 3; j++) {
if (!mode_in_list[j] && sizes[i].width == check_resx[j]) {
if (sizes[i].height == check_resy[j]) {
// Mode already in list.
mode_in_list[j] = true;
add_modes--;
}
}
}
}
GfOut("\n");
// Build the mode list, adding "forced" resolutions at the end if necessary.
const int bufsize = 20;
char buffer[bufsize];
Res = (char**) malloc(sizeof(char *)*(nsize+add_modes));
int resx[nsize+add_modes];
int resy[nsize+add_modes];
GfOut("Available resolutions :\n");
for (i = 0; i < nsize+add_modes; i++) {
if (i < nsize) {
// Add mode from screenconfig (system).
snprintf(buffer, bufsize, "%dx%d", sizes[i].width, sizes[i].height);
Res[i] = strndup(buffer, bufsize);
resx[i] = sizes[i].width;
resy[i] = sizes[i].height;
GfOut(" %dx%d \t(detected)\n", resx[i], resy[i]);
} else {
// Add mode from wish list.
unsigned int j;
for (j = 0; j < sizeof(check_resx)/sizeof(check_resx[0]); j++) {
if (mode_in_list[j] == false) {
mode_in_list[j] = true;
snprintf(buffer, bufsize, "%dx%d", check_resx[j], check_resy[j]);
Res[i] = strndup(buffer, bufsize);
resx[i] = check_resx[j];
resy[i] = check_resy[j];
GfOut(" %dx%d \t(forced)\n", resx[i], resy[i]);
break;
}
}
}
// Stupid sorting (not much elements, don't worry).
int j;
for (j = i; j > 0; j--) {
if (resx[j] < resx[j-1]
|| (resx[j] == resx[j-1] && resy[j] < resy[j-1]))
// Query system video capabilities.
const SDL_VideoInfo* sdlVideoInfo = SDL_GetVideoInfo();
if (!sdlVideoInfo)
{
int tx, ty;
char *tc;
tx = resx[j-1];
ty = resy[j-1];
resx[j-1] = resx[j];
resy[j-1] = resy[j];
resx[j] = tx;
resy[j] = ty;
tc = Res[j-1];
Res[j-1] = Res[j];
Res[j] = tc;
} else {
break;
GfLogWarning("Could not SDL_GetVideoInfo (%s)\n", SDL_GetError());
*pnSizes = 0;
return 0;
}
// Get best supported pixel format.
SDL_PixelFormat sdlPixelFormat;
memcpy(&sdlPixelFormat, &(sdlVideoInfo->vfmt), sizeof(SDL_PixelFormat));
//sdlPixelFormat.palette = 0;
//sdlPixelFormat.BitsPerPixel = ;
//sdlPixelFormat.BytesPerPixel = ;
//sdlPixelFormat.Rloss = ;
//sdlPixelFormat.Gloss = ;
//sdlPixelFormat.Bloss = ;
//sdlPixelFormat.Aloss = ;
//sdlPixelFormat.Rshift = ;
//sdlPixelFormat.Gshift = ;
//sdlPixelFormat.Bshift = ;
//sdlPixelFormat.Ashift = ;
//sdlPixelFormat.Rmask = ;
//sdlPixelFormat.Gmask = ;
//sdlPixelFormat.Bmask = ;
//sdlPixelFormat.Amask = ;
//sdlPixelFormat.colorkey = ;
//sdlPixelFormat.alpha = ;
// Update the pixel format to match the requested color depth.
sdlPixelFormat.BitsPerPixel = nColorDepth;
sdlPixelFormat.BytesPerPixel = nColorDepth / 8;
// Select the requested display mode.
Uint32 sdlDisplayMode = SDL_OPENGL;
if (bFullScreen)
sdlDisplayMode |= SDL_FULLSCREEN;
// Get the possible sizes for this pixel format.
SDL_Rect **asdlPossSizes = SDL_ListModes(&sdlPixelFormat, sdlDisplayMode);
GfLogTrace("Available %u-bit %s video sizes :",
sdlPixelFormat.BitsPerPixel, bFullScreen ? "full-screen" : "windowed");
tScreenSize* aPossSizes;
if (asdlPossSizes == (SDL_Rect**)0)
{
GfLogInfo(" None.\n");
aPossSizes = (tScreenSize*)0;
*pnSizes = 0;
}
else if (asdlPossSizes == (SDL_Rect**)-1)
{
GfLogInfo(" Any.\n");
aPossSizes = (tScreenSize*)-1;
*pnSizes = -1;
}
else
{
// Count the possible sizes.
*pnSizes = 0;
while (asdlPossSizes[*pnSizes])
(*pnSizes)++;
// Copy them into the output array.
aPossSizes = (tScreenSize*)malloc((*pnSizes)*sizeof(tScreenSize));
for (int nSizeInd = 0; nSizeInd < *pnSizes; nSizeInd++)
{
aPossSizes[nSizeInd].width = asdlPossSizes[*pnSizes - 1 - nSizeInd]->w;
aPossSizes[nSizeInd].height = asdlPossSizes[*pnSizes - 1 - nSizeInd]->h;
GfLogInfo(" %dx%d,", aPossSizes[nSizeInd].width, aPossSizes[nSizeInd].height);
}
GfLogInfo("\n");
}
return aPossSizes;
}
/** Get the possible color depths as supported bythe underlying hardware/driver.
@ingroup screen
@param pnDepths Address of number of detected color depths (output)
@return Array of detected possible color depths (allocated on the heap, must use free at the end)
*/
int* GfScrGetPossibleColorDepths(int* pnDepths)
{
// Determine the maximum supported color depth (default to 24 in any case).
const SDL_VideoInfo* sdlVideoInfo = SDL_GetVideoInfo();
int nMaxColorDepth = 24;
if (sdlVideoInfo)
{
nMaxColorDepth = sdlVideoInfo->vfmt->BitsPerPixel;
if (nMaxColorDepth > 32)
nMaxColorDepth = 32;
}
else
GfLogWarning("Could not SDL_GetVideoInfo (%s)\n", SDL_GetError());
// We support a minimum color depth of 16 bits.
const int nMinColorDepth = 16;
// So we can't have more than ... supported color depths.
const int nMaxColorDepths = 1 + (nMaxColorDepth - nMinColorDepth) / 8;
// Check video backend capabilities for each color depth between min and max,
// and store in target array if OK.
int nPossSizes;
tScreenSize* aPossSizes;
int* aPossDepths = (int*)malloc(nMaxColorDepths*sizeof(int));
*pnDepths = 0;
for (int nDepthInd = 0; nDepthInd < nMaxColorDepths; nDepthInd++)
{
const int nCheckedColorDepth = nMinColorDepth + 8 * nDepthInd;
// Windowed mode.
aPossSizes = GfScrGetPossibleSizes(nCheckedColorDepth, false, &nPossSizes);
const bool bWindowedOK = (aPossSizes != 0);
if (aPossSizes && aPossSizes != (tScreenSize*)-1)
free(aPossSizes);
// Full-screen mode
aPossSizes = GfScrGetPossibleSizes(nCheckedColorDepth, true, &nPossSizes);
const bool bFullScreenOK = (aPossSizes != 0);
if (aPossSizes && aPossSizes != (tScreenSize*)-1)
free(aPossSizes);
// Keep this color depth if one of the display modes work
// TODO: Shouldn't we use "and" here ?
if (bWindowedOK || bFullScreenOK)
{
aPossDepths[*pnDepths] = nCheckedColorDepth;
(*pnDepths)++;
}
}
nbRes = nsize + add_modes;
} else {
GfOut(" None !");
}
GfOut("\n");
XRRFreeScreenConfigInfo(screenconfig);
}
XCloseDisplay(display);
// Fallback : assume at least 24 bit depth is supported.
if (*pnDepths == 0)
{
GfLogWarning("SDL reports no supported color depth : assuming 24 bit is OK");
aPossDepths[*pnDepths] = 24;
(*pnDepths)++;
}
if (Res == NULL || nbRes == 0) {
// We failed to get a handle to the display, so fill in some defaults.
GfOut("Failed to initialize resolutions for display '%s' ; using defaults",
XDisplayName(displayname));
nbRes = NbDefRes;
Res = (char **) malloc(sizeof(char *)*nbRes);
int i;
for (i = 0; i < nbRes; i++) {
Res[i] = strdup(DefRes[i]);
}
}
#endif // USE_RANDR_EXT
// Report supported depths.
GfLogInfo("Supported color depths (bits) :");
for (int nDepthInd = 0; nDepthInd < *pnDepths; nDepthInd++)
GfLogInfo(" %d,", aPossDepths[nDepthInd]);
GfLogInfo("\n");
return aPossDepths;
}
static void Reshape(int width, int height)
static void gfScrReshape(int width, int height)
{
glViewport( (width-GfViewWidth)/2, (height-GfViewHeight)/2, GfViewWidth, GfViewHeight);
glMatrixMode( GL_PROJECTION );
@ -298,6 +320,7 @@ static void Reshape(int width, int height)
void GfScrInit(int argc, char *argv[])
{
char buf[512];
int xw, yw;
int winX, winY;
void *handle;
@ -308,6 +331,45 @@ void GfScrInit(int argc, char *argv[])
int maxfreq;
int depth;
// Initialize SDL video subsystem (and exit if not possible).
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
GfLogFatal("Couldn't initialize SDL video sub-system (%s)\n", SDL_GetError());
// Query system video capabilities.
// Note: Does not work very well as long as you don't force SDL to use
// a special hardware driver ... which we don't want at all (the default is the one).
//typedef struct{
// Uint32 hw_available:1;
// Uint32 wm_available:1;
// Uint32 blit_hw:1;
// Uint32 blit_hw_CC:1;
// Uint32 blit_hw_A:1;
// Uint32 blit_sw:1;
// Uint32 blit_sw_CC:1;
// Uint32 blit_sw_A:1;
// Uint32 blit_fill;
// Uint32 video_mem;
// SDL_PixelFormat *vfmt;
//} SDL_VideoInfo;
const SDL_VideoInfo* sdlVideoInfo = SDL_GetVideoInfo();
if (!sdlVideoInfo)
{
GfLogWarning("Could not SDL_GetVideoInfo (%s)\n", SDL_GetError());
return;
}
char pszDriverName[32];
GfLogTrace("SDL video driver : '%s'\n", SDL_VideoDriverName(pszDriverName, 32));
//GfLogTrace(" Hardware acceleration : %s\n", sdlVideoInfo->hw_available ? "true" : "false");
//GfLogTrace(" Total video memory : %u Kb\n", sdlVideoInfo->video_mem);
GfLogTrace("Maximum pixel depth : %d bits\n", sdlVideoInfo->vfmt->BitsPerPixel);
// Query supported color depths.
if (AColorDepths)
free(AColorDepths);
AColorDepths = GfScrGetPossibleColorDepths(&NColorDepths);
// Get graphical settings from config file.
sprintf(buf, "%s%s", GetLocalDir(), GFSCR_CONF_FILE);
handle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
@ -322,12 +384,6 @@ void GfScrInit(int argc, char *argv[])
vinit = GfParmGetStr(handle, GFSCR_SECT_PROP, GFSCR_ATT_VINIT, GFSCR_VAL_VINIT_COMPATIBLE);
// Initialize SDL.
if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0 ) {
printf("Couldn't initialize SDL: %s\n", SDL_GetError());
return;
}
// Initialize game interface to SDL.
GfelInitialize();
atexit(SDL_Quit);
@ -444,7 +500,8 @@ void GfScrInit(int argc, char *argv[])
if (!ScreenSurface)
{
GfError("Unable to get compatible video mode with requested resolution\n\n");
sscanf(DefRes[0], "%dx%d", &winX, &winY);
winX = ADefScreenSizes[0].width;
winY = ADefScreenSizes[0].height;
GfTrace("Trying generic video initialization with fallback resolution %dx%d.\n\n",
winX, winY);
ScreenSurface = SDL_SetVideoMode( winX, winY, depth, videomode);
@ -486,8 +543,8 @@ void GfScrInit(int argc, char *argv[])
GfelPostRedisplay();
GfuiInitWindowPosition(0, 0);
GfuiInitWindowSize(winX, winY);
Reshape(winX,winY);
GfelSetReshapeCB( Reshape );
gfScrReshape(winX,winY);
GfelSetReshapeCB(gfScrReshape);
GfParmReleaseHandle(handle);
@ -500,13 +557,17 @@ void GfScrInit(int argc, char *argv[])
*/
void GfScrShutdown(void)
{
#ifdef USE_RANDR_EXT
int i;
for (i = 0; i < nbRes; i++) {
free(Res[i]);
if (AColorDepths)
{
free(AColorDepths);
AColorDepths = 0;
}
if (AScreenSizes && AScreenSizes != ADefScreenSizes)
{
free(AScreenSizes);
AScreenSizes = 0;
}
free(Res);
#endif // USE_RANDR_EXT
}
@ -598,56 +659,25 @@ SDL_Surface* gfScrGetScreenSurface()
static void
saveParams(void)
{
int x, y, bpp;
const int w = AScreenSizes[NCurScreenSize].width;
const int h = AScreenSizes[NCurScreenSize].height;
sscanf(Res[curRes], "%dx%d", &x, &y);
sscanf(Depthlist[curDepth], "%d", &bpp);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_X, (char*)NULL, w);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_Y, (char*)NULL, h);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_WIN_X, (char*)NULL, w);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_WIN_Y, (char*)NULL, h);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_BPP, (char*)NULL, AColorDepths[NCurColorDepth]);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_MAXREFRESH, (char*)NULL, NCurMaxFreq);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_X, (char*)NULL, x);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_Y, (char*)NULL, y);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_WIN_X, (char*)NULL, x);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_WIN_Y, (char*)NULL, y);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_BPP, (char*)NULL, bpp);
GfParmSetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_MAXREFRESH, (char*)NULL, curMaxFreq);
const char* pszVInitMode =
(NCurVideoInitMode == 0) ? GFSCR_VAL_VINIT_COMPATIBLE : GFSCR_VAL_VINIT_BEST;
GfParmSetStr(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_VINIT, pszVInitMode);
GfParmSetStr(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_VINIT, (char*)VInit[curVInit]);
GfParmSetStr(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_FSCR, NCurDisplayMode == 0 ? "yes" : "no");
if (curMode == 0) {
GfParmSetStr(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_FSCR, "yes");
} else {
GfParmSetStr(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_FSCR, "no");
}
GfParmWriteFile(NULL, paramHdle, "Screen");
}
// In-place convert internal file or dir path to an OS compatible path
void makeOSPath(char* path)
{
#ifdef WIN32
size_t i;
for (i = 0; i < strlen(path); i++)
if (path[i] == '/')
path[i] = '\\';
#endif //WIN32
}
// Build a new path string compatible with current OS and usable as a command line arg.
char* buildPathArg(const char *path)
{
#ifdef WIN32
char *osPath = (char*)malloc(strlen(path)+3);
sprintf(osPath, "\"%s", path);
if (osPath[strlen(osPath)-1] == '/')
osPath[strlen(osPath)-1] = 0; // Remove trailing '/' for command line
strcat(osPath, "\"");
#else
char *osPath = strdup(path);
#endif //WIN32
makeOSPath(osPath);
return osPath;
}
// Re-init screen to take new graphical settings into account (implies process restart).
void
GfScrReinit(void * /* dummy */)
@ -669,145 +699,104 @@ GfScrReinit(void * /* dummy */)
// Release screen allocated resources.
GfScrShutdown();
// Command name.
sprintf(cmd, "%sspeed-dreams", GetBinDir());
#ifdef WIN32
strcat(cmd, ".exe");
#endif
makeOSPath(cmd);
// Compute number of args.
nArgs = 1; // Executable is always the first arg.
if (GfuiMouseHW)
nArgs += 1;
if (GetLocalDir() && strlen(GetLocalDir()))
nArgs += 2;
if (GetBinDir() && strlen(GetBinDir()))
nArgs += 2;
if (GetLibDir() && strlen(GetLibDir()))
nArgs += 2;
if (GetDataDir() && strlen(GetDataDir()))
nArgs += 2;
nArgs++; // Last arg must be a null pointer.
// Allocate args array.
args = (char**)malloc(sizeof(char*)*nArgs);
// First arg is the executable path-name.
argInd = 0;
args[argInd++] = buildPathArg(cmd);
// Then add subsequent args.
if (GfuiMouseHW)
args[argInd++] = strdup("-m");
if (GetLocalDir() && strlen(GetLocalDir()))
{
args[argInd++] = strdup("-l");
args[argInd++] = buildPathArg(GetLocalDir());
}
if (GetBinDir() && strlen(GetBinDir()))
{
args[argInd++] = strdup("-B");
args[argInd++] = buildPathArg(GetBinDir());
}
if (GetLibDir() && strlen(GetLibDir()))
{
args[argInd++] = strdup("-L");
args[argInd++] = buildPathArg(GetLibDir());
}
if (GetDataDir() && strlen(GetDataDir()))
{
args[argInd++] = strdup("-D");
args[argInd++] = buildPathArg(GetDataDir ());
}
// Finally, last null arg.
args[argInd++] = 0;
// Exec the command : restart the game (simply replacing current process)
GfOut("Restarting ");
for (i = 0; i < nArgs && args[i]; i++)
printf("%s%s ", args[i], nArgs < nArgs-2 ? " " : "");
GfOut(" ...\n\n");
retcode = execvp (cmd, args);
// If successfull, we never get here ... but if failed ...
GfOut("Failed to restart Speed Dreams through command line '");
for (i = 0; i < nArgs && args[i]; i++)
{
GfOut("%s%s ", args[i], nArgs < nArgs-2 ? " " : "");
free(args[i]);
}
GfOut("' (exit code %d)\n", retcode);
free(args);
perror("Speed Dreams");
exit(1);
// Restart the game.
GfRestart(GfuiMouseHW != 0, GfglIsMultiTexturingEnabled());
}
static void
updateLabelText(void)
{
GfuiLabelSetText (scrHandle, ResLabelId, Res[curRes]);
GfuiLabelSetText (scrHandle, DepthLabelId, Depthlist[curDepth]);
GfuiLabelSetText (scrHandle, ModeLabelId, Mode[curMode]);
char buf[32];
sprintf(buf, "%dx%d", AScreenSizes[NCurScreenSize].width, AScreenSizes[NCurScreenSize].height);
GfuiLabelSetText(scrHandle, ScreenSizeLabelId, buf);
sprintf(buf, "%d", AColorDepths[NCurColorDepth]);
GfuiLabelSetText(scrHandle, ColorDepthLabelId, buf);
GfuiLabelSetText(scrHandle, DisplayModeLabelId, ADisplayModes[NCurDisplayMode]);
#ifdef WIN32
sprintf(buf, "%d", curMaxFreq);
GfuiEditboxSetString(scrHandle, MaxFreqId, buf);
sprintf(buf, "%d", NCurMaxFreq);
GfuiEditboxSetString(scrHandle, MaxFreqEditId, buf);
#endif
GfuiLabelSetText(scrHandle, VInitLabelId, VInit[curVInit]);
GfuiLabelSetText(scrHandle, VideoInitModeLabelId, AVideoInitModes[NCurVideoInitMode]);
}
static void
ResPrevNext(void *vdelta)
{
long delta = (long)vdelta;
curRes += (int)delta;
if (curRes < 0) {
curRes = nbRes - 1;
} else {
if (curRes >= nbRes) {
curRes = 0;
}
}
NCurScreenSize = (NCurScreenSize + (int)(long)vdelta + NScreenSizes) % NScreenSizes;
updateLabelText();
}
static void
updateScreenSizes(int nCurrWidth, int nCurrHeight)
{
// Query possible screen sizes for the current display mode and color depth.
if (AScreenSizes && AScreenSizes != ADefScreenSizes)
free(AScreenSizes);
AScreenSizes = GfScrGetPossibleSizes(AColorDepths[NCurColorDepth],
NCurDisplayMode == 0, &NScreenSizes);
// If any size is possible :-) or none :-(, use default hard coded list (temporary).
if (AScreenSizes == (tScreenSize*)-1 || AScreenSizes == 0)
{
AScreenSizes = ADefScreenSizes;
NScreenSizes = NDefScreenSizes;
}
// Try and find the closest screen size to the current choice in the new list.
// 1) Is there an exact match ?
NCurScreenSize = -1;
for (int nSizeInd = 0; nSizeInd < NScreenSizes; nSizeInd++)
{
if (nCurrWidth == AScreenSizes[nSizeInd].width
&& nCurrHeight == AScreenSizes[nSizeInd].height)
{
NCurScreenSize = nSizeInd;
break;
}
}
// 2) Is there an approximative match ?
if (NCurScreenSize < 0)
{
for (int nSizeInd = 0; nSizeInd < NScreenSizes; nSizeInd++)
{
if (nCurrWidth <= AScreenSizes[nSizeInd].width
&& nCurrHeight <= AScreenSizes[nSizeInd].height)
{
NCurScreenSize = nSizeInd;
break;
}
}
}
// 3) Not found : the closest is the biggest.
if (NCurScreenSize < 0)
NCurScreenSize = NScreenSizes - 1;
}
static void
DepthPrevNext(void *vdelta)
{
long delta = (long)vdelta;
NCurColorDepth = (NCurColorDepth + (int)(long)vdelta + NColorDepths) % NColorDepths;
updateScreenSizes(AScreenSizes[NCurScreenSize].width, AScreenSizes[NCurScreenSize].height);
curDepth += (int)delta;
if (curDepth < 0) {
curDepth = nbDepth - 1;
} else {
if (curDepth >= nbDepth) {
curDepth = 0;
}
}
updateLabelText();
}
static void
ModePrevNext(void *vdelta)
{
long delta = (long)vdelta;
NCurDisplayMode = (NCurDisplayMode + (int)(long)vdelta + NDisplayModes) % NDisplayModes;
updateScreenSizes(AScreenSizes[NCurScreenSize].width, AScreenSizes[NCurScreenSize].height);
curMode += (int)delta;
if (curMode < 0) {
curMode = nbMode - 1;
} else {
if (curMode >= nbMode) {
curMode = 0;
}
}
updateLabelText();
}
@ -815,81 +804,72 @@ ModePrevNext(void *vdelta)
static void
VInitPrevNext(void *vdelta)
{
long delta = (long)vdelta;
NCurVideoInitMode = (NCurVideoInitMode + (int)(long)vdelta + NVideoInitModes) % NVideoInitModes;
curVInit += (int)delta;
if (curVInit < 0) {
curVInit = nbVInit - 1;
} else {
if (curVInit >= nbVInit) {
curVInit = 0;
}
}
updateLabelText();
}
static void
initFromConf(void)
loadParams(void)
{
int x, y, bpp;
int w, h, bpp;
int i;
x = (int)GfParmGetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_X, NULL, 640);
y = (int)GfParmGetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_Y, NULL, 480);
sprintf(buf, "%dx%d", x, y);
for (i = 0; i < nbRes; i++) {
if (!strcmp(buf, Res[i])) {
curRes = i;
// Color depth (bits per pixel).
bpp = (int)GfParmGetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_BPP, NULL, AColorDepths[NColorDepths-1]);
NCurColorDepth = NColorDepths-1; // Defaults to max possible supported value.
for (i = 0; i < NColorDepths; i++) {
if (bpp <= AColorDepths[i]) {
NCurColorDepth = i;
break;
}
}
if (!strcmp("yes", GfParmGetStr(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_FSCR, "yes"))) {
curMode = 0;
// Display mode : Full-screen or Windowed.
if (!strcmp("yes", GfParmGetStr(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_FSCR, "no"))) {
NCurDisplayMode = 0;
} else {
curMode = 1;
NCurDisplayMode = 1;
}
curVInit = 0;
// Screen / window size.
w = (int)GfParmGetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_X, NULL, 640);
h = (int)GfParmGetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_Y, NULL, 480);
updateScreenSizes(w, h);
// Video initialization mode : Compatible or Best.
NCurVideoInitMode = 0;
const char *tmp = GfParmGetStr(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_VINIT, GFSCR_VAL_VINIT_COMPATIBLE);
for (i = 0; i < nbVInit; i++) {
if (strcmp(VInit[i], tmp) == 0) {
curVInit = i;
break;
}
if (strcmp(GFSCR_VAL_VINIT_COMPATIBLE, tmp) == 0) {
NCurVideoInitMode = 0;
} else {
NCurVideoInitMode = 1;
}
bpp = (int)GfParmGetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_BPP, NULL, 24);
sprintf(buf, "%d", bpp);
for (i = 0; i < nbDepth; i++) {
if (!strcmp(buf, Depthlist[i])) {
curDepth = i;
break;
}
}
curMaxFreq = (int)GfParmGetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_MAXREFRESH, NULL, curMaxFreq);
// Max. refresh rate (Hz).
NCurMaxFreq = (int)GfParmGetNum(paramHdle, GFSCR_SECT_PROP, GFSCR_ATT_MAXREFRESH, NULL, NCurMaxFreq);
}
#ifdef WIN32
static void
ChangeMaxFreq(void * /* dummy */)
{
char buf[32];
char *val;
val = GfuiEditboxGetString(scrHandle, MaxFreqId);
curMaxFreq = (int)strtol(val, (char **)NULL, 0);
sprintf(buf, "%d", curMaxFreq);
GfuiEditboxSetString(scrHandle, MaxFreqId, buf);
val = GfuiEditboxGetString(scrHandle, MaxFreqEditId);
NCurMaxFreq = (int)strtol(val, (char **)NULL, 0);
sprintf(buf, "%d", NCurMaxFreq);
GfuiEditboxSetString(scrHandle, MaxFreqEditId, buf);
}
#endif
static void
onActivate(void * /* dummy */)
{
initFromConf();
loadParams();
updateLabelText();
}
@ -901,6 +881,8 @@ onActivate(void * /* dummy */)
void *
GfScrMenuInit(void *prevMenu)
{
char buf[512];
sprintf(buf, "%s%s", GetLocalDir(), GFSCR_CONF_FILE);
paramHdle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
@ -913,27 +895,27 @@ GfScrMenuInit(void *prevMenu)
CreateButtonControl(scrHandle,param,"resleftarrow",(void*)-1,ResPrevNext);
CreateButtonControl(scrHandle,param,"resrightarrow",(void*)1,ResPrevNext);
ResLabelId = CreateLabelControl(scrHandle,param,"reslabel");
ScreenSizeLabelId = CreateLabelControl(scrHandle,param,"reslabel");
CreateButtonControl(scrHandle, param, "accept", NULL, GfScrReinit);
CreateButtonControl(scrHandle, param, "cancel", prevMenu, GfuiScreenActivate);
CreateButtonControl(scrHandle,param,"depthleftarrow",(void*)-1,DepthPrevNext);
CreateButtonControl(scrHandle,param,"depthrightarrow",(void*)1,DepthPrevNext);
DepthLabelId = CreateLabelControl(scrHandle,param,"depthlabel");
ColorDepthLabelId = CreateLabelControl(scrHandle,param,"depthlabel");
CreateButtonControl(scrHandle,param,"displeftarrow",(void*)-1,ModePrevNext);
CreateButtonControl(scrHandle,param,"disprightarrow",(void*)1,ModePrevNext);
ModeLabelId = CreateLabelControl(scrHandle,param,"displabel");
DisplayModeLabelId = CreateLabelControl(scrHandle,param,"displabel");
#ifdef WIN32
CreateLabelControl(scrHandle,param,"maxfreqlabel");
MaxFreqId = CreateEditControl(scrHandle,param,"freqedit",NULL,NULL,ChangeMaxFreq);
MaxFreqEditId = CreateEditControl(scrHandle,param,"freqedit",NULL,NULL,ChangeMaxFreq);
#endif
CreateButtonControl(scrHandle,param,"vmleftarrow",(void*)-1, VInitPrevNext);
CreateButtonControl(scrHandle,param,"vmrightarrow",(void*)1, VInitPrevNext);
VInitLabelId = CreateLabelControl(scrHandle,param,"vmlabel");
VideoInitModeLabelId = CreateLabelControl(scrHandle,param,"vmlabel");
GfParmReleaseHandle(param);
GfuiAddKey(scrHandle, GFUIK_RETURN, "Accept", NULL, GfScrReinit, NULL);

View file

@ -1,10 +1,10 @@
/***************************************************************************
file : screen_properties.h
file : guiscreen.h
created : Sat Apr 19 23:37:41 CEST 2003
copyright : (C) 2003 by Eric Espi<EFBFBD>
copyright : (C) 2003 by Eric Espie
email : eric.espie@torcs.org
version : $Id: screen_properties.h,v 1.4 2005/02/01 15:55:55 berniw Exp $
version : $Id$
***************************************************************************/
@ -20,11 +20,14 @@
/** @file
@author <a href=mailto:torcs@free.fr>Eric Espie</a>
@version $Id: screen_properties.h,v 1.4 2005/02/01 15:55:55 berniw Exp $
@version $Id$
*/
#ifndef _SCREEN_PROPERTIES_H_
#define _SCREEN_PROPERTIES_H_
#ifndef _GUISCREEN_H_
#define _GUISCREEN_H_
#include <SDL/SDL_video.h>
#define GFSCR_CONF_FILE "config/screen.xml"
@ -83,7 +86,9 @@
#define GFSCR_ATTR_ALPHA "alpha"
#endif /* _SCREEN_PROPERTIES_H_ */
SDL_Surface* gfScrGetScreenSurface();
#endif /* _GUISCREEN_H_ */

View file

@ -17,15 +17,10 @@
***************************************************************************/
#include "gui.h"
#include "tgfclient.h"
#include "guimenu.h"
extern void gfScreenInit(void);
extern void gfMenuInit(void);
void
GfInitClient(void)
void GfInitClient(void)
{
gfuiInit();
gfMenuInit();
gfScreenInit();
}

View file

@ -22,13 +22,12 @@
@version $Id$
*/
#ifndef __TGFCLIENT__H__
#define __TGFCLIENT__H__
#include <string>
#include <vector>
#ifndef __TGFCLIENT__H__
#define __TGFCLIENT__H__
#ifdef WIN32
# include <windows.h>
//Disable some MSVC warnings
@ -47,11 +46,10 @@
# include <plib/js.h>
#endif
#include <SDL/SDL_keysym.h>
#include <SDL/SDL_video.h>
#include <tgf.h>
#include "screen_properties.h"
#include "guiscreen.h"
// DLL exported symbols declarator for Windows.
@ -77,15 +75,23 @@ TGFCLIENT_API void GfInitClient(void);
* Screen Interface *
********************/
typedef struct ScreenSize
{
int width; // Width in pixels.
int height; // Height in pixels.
} tScreenSize;
TGFCLIENT_API void GfScrInit(int argc, char *argv[]);
TGFCLIENT_API void GfScrShutdown(void);
TGFCLIENT_API void *GfScrMenuInit(void *precMenu);
TGFCLIENT_API void GfScrGetSize(int *scrW, int *scrH, int *viewW, int *viewH);
SDL_Surface* gfScrGetScreenSurface();
TGFCLIENT_API unsigned char* GfScrCaptureAsImage(int* viewW, int *viewH);
TGFCLIENT_API int GfScrCaptureAsPNG(const char *filename);
TGFCLIENT_API void GfScrReinit(void*);
TGFCLIENT_API int* GfScrGetPossibleColorDepths(int* pnDepths);
TGFCLIENT_API tScreenSize* GfScrGetPossibleSizes(int nColorDepth, bool bFullScreen, int* pnSizes);
/*****************************
* GUI interface (low-level) *
*****************************/
@ -593,6 +599,11 @@ TGFCLIENT_API void GfglUpdateUserTextureMaxSize(void);
TGFCLIENT_API bool GfglIsTextureRectangleARBAvailable(void); // In case mipmapping NOT needed.
TGFCLIENT_API bool GfglIsTextureNonPowerOf2ARBAvailable(void); // In case mipmapping needed.
// Multi-texturing support
TGFCLIENT_API bool GfglIsMultiTexturingEnabled();
TGFCLIENT_API void GfglEnableMultiTexturing(bool bEnable = true);
#endif /* __TGFCLIENT__H__ */

View file

@ -70,7 +70,7 @@ init_args(int argc, char **argv)
// -s option : Single texture mode (= disable multi-texturing)
else if (!strncmp(argv[i], "-s", 2))
{
SetSingleTextureMode ();
GfglEnableMultiTexturing(false);
}
// -m option : Allow the hardware mouse cursor
else if (!strncmp(argv[i], "-m", 2))

View file

@ -86,7 +86,7 @@ PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB = NULL;
// desc: sets up OpenGL for multitexturing support
bool InitMultiTex(void)
{
if (GetSingleTextureMode ()) {
if (!GfglIsMultiTexturingEnabled()) {
maxTextureUnits = 1;
return true;
} else {

View file

@ -53,56 +53,6 @@ init_args(int argc, char **argv)
GfInitInstallDir(argv[0]);
// Parse command line args.
#ifdef WIN32
int i = 1;
while (i < argc)
{
// -l or /l option : User settings dir (named "local dir")
if (!strncmp(argv[i], "-l", 2) || !strncmp(argv[i], "/l", 2))
{
if (++i < argc)
localdir = SetLocalDir(argv[i]);
}
// -L or /L option : Libraries dir (root dir of the tree where loadable modules are installed)
else if (!strncmp(argv[i], "-L", 2) || !strncmp(argv[i], "/L", 2))
{
if (++i < argc)
libdir = SetLibDir(argv[i]);
}
// -D or /D option : Data dir (root dir of the data tree)
else if (!strncmp(argv[i], "-D", 2) || !strncmp(argv[i], "/D", 2))
{
if (++i < argc)
datadir = SetDataDir(argv[i]);
}
// -B or /B option : Binaries dir (the dir where Speed Dreams exe and DLLs are installed)
else if (!strncmp(argv[i], "-B", 2) || !strncmp(argv[i], "/B", 2))
{
if (++i < argc)
bindir = SetBinDir(argv[i]);
}
// -s or /s option : Single texture mode (= disable multi-texturing)
else if (!strncmp(argv[i], "-s", 2) || !strncmp(argv[i], "/s", 2))
{
SetSingleTextureMode ();
}
// -m or /m option : Allow the hardware mouse cursor
else if (!strncmp(argv[i], "-m", 2) || !strncmp(argv[i], "/m", 2))
{
GfuiMouseSetHWPresent();
}
else
{
g_strMenuFile = argv[i];
}
// Next arg (even if current not recognized).
i++;
}
#else
int i = 1;
while (i < argc)
{
@ -133,7 +83,7 @@ init_args(int argc, char **argv)
// -s option : Single texture mode (= disable multi-texturing)
else if (!strncmp(argv[i], "-s", 2))
{
SetSingleTextureMode ();
GfglEnableMultiTexturing(false);
}
// -m option : Allow the hardware mouse cursor
else if (!strncmp(argv[i], "-m", 2))
@ -148,7 +98,6 @@ init_args(int argc, char **argv)
// Next arg (even if current not recognized).
i++;
}
#endif
// If any of the Speed-Dreams dirs not run-time specified / empty,
// use associated compile-time variable SD_XXDIR to get default value

View file

@ -70,7 +70,7 @@ init_args(int argc, char **argv)
// -s or /s option : Single texture mode (= disable multi-texturing)
else if (!strncmp(argv[i], "-s", 2) || !strncmp(argv[i], "/s", 2))
{
SetSingleTextureMode ();
GfglEnableMultiTexturing(false);
}
// -m or /m option : Allow the hardware mouse cursor
else if (!strncmp(argv[i], "-m", 2) || !strncmp(argv[i], "/m", 2))