51 #include <X11/Xatom.h> 52 #include <X11/keysym.h> 53 #include <X11/extensions/Xrandr.h> 54 #endif // USE_RANDR_EXT 66 #if !defined(FREEGLUT) && !defined(WIN32) 71 static char **
Res = NULL;
73 #else // USE_RANDR_EXT 74 static char *
Res[] = {
101 #endif // USE_RANDR_EXT 103 static const char *
Mode[] = {
"Full-screen mode",
"Window mode"};
119 static int MaxFreqId;
135 const char *displayname = getenv(
"DISPLAY");
136 if (displayname == NULL) {
137 displayname = strdup(
":0.0");
140 Display *display = XOpenDisplay(displayname);
142 if( display != NULL) {
144 int screen = DefaultScreen(display);
145 Window root = RootWindow(display, screen);
147 XRRScreenConfiguration *screenconfig = XRRGetScreenInfo (display, root);
148 if (screenconfig != NULL) {
150 XRRScreenSize *sizes = XRRConfigSizes(screenconfig, &nsize);
154 int check_resx[] = {320, 640, 800};
155 int check_resy[] = {240, 480, 600};
156 bool mode_in_list[] = {
false,
false,
false};
157 int add_modes =
sizeof(check_resx)/
sizeof(check_resx[0]);
159 for (i = 0; i < nsize; i++) {
160 for (j = 0; j < 3; j++) {
161 if ((mode_in_list[j] ==
false) && (sizes[i].width == check_resx[j])) {
162 if (sizes[i].height == check_resy[j]) {
164 mode_in_list[j] =
true;
171 const int bufsize = 20;
172 char buffer[bufsize];
173 Res = (
char**) malloc(
sizeof(
char *)*(nsize+add_modes));
174 int resx[nsize+add_modes];
175 int resy[nsize+add_modes];
176 for (i = 0; i < nsize+add_modes; i++) {
179 snprintf(buffer, bufsize,
"%dx%d", sizes[i].width, sizes[i].height);
181 resx[i] = sizes[i].width;
182 resy[i] = sizes[i].height;
186 for (j = 0; j <
sizeof(check_resx)/
sizeof(check_resx[0]); j++) {
187 if (mode_in_list[j] ==
false) {
188 mode_in_list[j] =
true;
189 snprintf(buffer, bufsize,
"%dx%d", check_resx[j], check_resy[j]);
191 resx[i] = check_resx[j];
192 resy[i] = check_resy[j];
200 for (j = i; j > 0; j--) {
201 if ((resx[j] < resx[j-1]) ||
202 (resx[j] == resx[j-1] && resy[j] < resy[j-1]))
221 nbRes = nsize + add_modes;
224 XRRFreeScreenConfigInfo(screenconfig);
226 XCloseDisplay(display);
231 GfOut(
"Failed to initialize resolutions for display '%s'", XDisplayName(displayname));
233 Res = (
char **) malloc(
sizeof(
char *)*
nbRes);
234 Res[0] = strdup(
"640x480");
235 Res[1] = strdup(
"800x600");
236 Res[2] = strdup(
"1024x768");
237 Res[3] = strdup(
"1152x864");
238 Res[4] = strdup(
"1200x960");
239 Res[5] = strdup(
"1280x1024");
240 Res[6] = strdup(
"1600x1200");
241 Res[7] = strdup(
"320x200");
243 #endif // USE_RANDR_EXT 249 glMatrixMode( GL_PROJECTION );
251 glOrtho( 0.0, 640.0, 0.0, 480.0, -1.0, 1.0 );
252 glMatrixMode( GL_MODELVIEW );
270 const int BUFSIZE = 1024;
289 #if !defined(FREEGLUT) && !defined(WIN32) 291 GfOut (
"Freeglut not detected...\n");
292 for (i = maxfreq; i > 59; i--) {
293 snprintf(buf, BUFSIZE,
"%dx%d:%d@%d", winX, winY, depth, i);
294 GfOut(
"Trying %s mode\n", buf);
297 GfOut(
"OK done for %s\n", buf);
307 glutInit(&argc, argv);
317 int visualDepthBits = 24;
318 bool visualSupportsMultisample =
true;
319 bool visualSupportsAlpha =
true;
321 glutInitDisplayString(
"rgba double depth>=24 samples alpha");
323 if (!glutGet(GLUT_DISPLAY_MODE_POSSIBLE)) {
325 visualDepthBits = 24;
326 visualSupportsMultisample =
false;
327 visualSupportsAlpha =
true;
328 glutInitDisplayString(
"rgba double depth>=24 alpha");
331 if (!glutGet(GLUT_DISPLAY_MODE_POSSIBLE)) {
333 visualDepthBits = 24;
334 visualSupportsMultisample =
true;
335 visualSupportsAlpha =
false;
336 glutInitDisplayString(
"rgb double depth>=24 samples");
339 if (!glutGet(GLUT_DISPLAY_MODE_POSSIBLE)) {
341 visualDepthBits = 24;
342 visualSupportsMultisample =
false;
343 visualSupportsAlpha =
false;
344 glutInitDisplayString(
"rgb double depth>=24");
347 if (!glutGet(GLUT_DISPLAY_MODE_POSSIBLE)) {
349 visualDepthBits = 16;
350 visualSupportsMultisample =
false;
351 visualSupportsAlpha =
true;
352 glutInitDisplayString(
"rgba double depth>=16 alpha");
355 if (!glutGet(GLUT_DISPLAY_MODE_POSSIBLE)) {
357 visualDepthBits = 16;
358 visualSupportsMultisample =
false;
359 visualSupportsAlpha =
false;
360 glutInitDisplayString(
"rgb double depth>=16");
363 printf(
"Visual Properties Report\n");
364 printf(
"------------------------\n");
366 if (!glutGet(GLUT_DISPLAY_MODE_POSSIBLE)) {
368 printf(
"The minimum display requirements are not fulfilled.\n");
369 printf(
"We need a double buffered RGB visual with a 16 bit depth buffer at least.\n");
371 printf(
"Trying generic initialization, fallback.\n");
372 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
375 printf(
"z-buffer depth: %d (%s)\n", visualDepthBits, visualDepthBits < 24 ?
"bad" :
"good");
376 printf(
"multisampling : %s\n", visualSupportsMultisample ?
"available" :
"no");
377 printf(
"alpha bits : %s\n", visualSupportsAlpha ?
"available" :
"no");
378 if (visualDepthBits < 24) {
380 printf(
"The z-buffer resolution is below 24 bit, you will experience rendering\n");
381 printf(
"artefacts. Try to improve the setup of your graphics board or look\n");
382 printf(
"for an alternate driver.\n");
387 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
388 printf(
"Visual Properties Report\n");
389 printf(
"------------------------\n");
390 printf(
"Compatibility mode, properties unknown.\n");
395 for (i = maxfreq; i > 59; i--) {
396 snprintf(buf, BUFSIZE,
"%dx%d:%d@%d", winX, winY, depth, i);
397 glutGameModeString(buf);
398 GfOut(
"2 - Trying %s mode\n", buf);
399 if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
400 GfOut(
"2- %s mode Possible\n", buf);
402 if (glutGameModeGet(GLUT_GAME_MODE_DISPLAY_CHANGED)) {
403 GfOut(
"Use GameMode %s\n", buf);
416 glutInitWindowPosition(0, 0);
417 glutInitWindowSize(winX, winY);
418 Window = glutCreateWindow(argv[0]);
420 printf(
"Error, couldn't open window\n");
447 #if !defined(FREEGLUT) && !defined(WIN32) 455 for (i = 0; i <
nbRes; i++) {
459 #endif // USE_RANDR_EXT 487 const int BUFSIZE = 1024;
515 static const int CMDSIZE = 1024;
528 snprintf(cmd, CMDSIZE,
"%swtorcs.exe",
GetLibDir());
530 for (i = 0; i < CMDSIZE && cmd[i] != NULL; i++) {
536 char cmdarg[CMDSIZE];
537 snprintf(cmdarg, CMDSIZE,
"\"%swtorcs.exe\"",
GetLibDir());
538 for (i = 0; i < CMDSIZE && cmdarg[i] != NULL; i++) {
539 if (cmdarg[i] ==
'/') {
544 retcode = execlp(cmd, cmdarg, (
const char *)NULL);
548 snprintf (cmd, CMDSIZE,
"%storcs-bin",
GetLibDir ());
549 memset (arg, 0,
sizeof (arg));
552 arg[curArg++] =
"-m";
556 arg[curArg++] =
"-l";
561 arg[curArg++] =
"-L";
566 arg[curArg++] =
"-D";
572 retcode = execlp (cmd, cmd, (
const char *)NULL);
575 retcode = execlp (cmd, cmd, arg[0], (
const char *)NULL);
578 retcode = execlp (cmd, cmd, arg[0], arg[1], (
const char *)NULL);
581 retcode = execlp (cmd, cmd, arg[0], arg[1], arg[2], (
const char *)NULL);
584 retcode = execlp (cmd, cmd, arg[0], arg[1], arg[2], arg[3], (
const char *)NULL);
587 retcode = execlp (cmd, cmd, arg[0], arg[1], arg[2], arg[3], arg[4], (
const char *)NULL);
590 retcode = execlp (cmd, cmd, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], (
const char *)NULL);
593 retcode = execlp (cmd, cmd, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], (
const char *)NULL);
596 retcode = execlp (cmd, cmd, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7], (
const char *)NULL);
615 const int BUFSIZE = 1024;
627 long delta = (long)vdelta;
642 long delta = (long)vdelta;
658 long delta = (long)vdelta;
675 long delta = (long)vdelta;
694 const int BUFSIZE = 1024;
703 snprintf(buf, BUFSIZE,
"%dx%d", x,
y);
704 for (i = 0; i <
nbRes; i++) {
705 if (!strcmp(buf,
Res[i])) {
719 for (i = 0; i <
nbVInit; i++) {
720 if (strcmp(
VInit[i], tmp) == 0) {
727 snprintf(buf, BUFSIZE,
"%d", bpp);
728 for (i = 0; i <
nbDepth; i++) {
741 ChangeMaxFreq(
void * )
744 const int BUFSIZE = 1024;
748 curMaxFreq = (int)strtol(val, (
char **)NULL, 0);
772 const int yoffset1 = 30, yoffset2 = 60;
774 const int yoffset1 = 30, yoffset2 = 40;
794 "data/img/arrow-left.png",
795 "data/img/arrow-left.png",
796 "data/img/arrow-left.png",
797 "data/img/arrow-left-pushed.png",
811 "data/img/arrow-right.png",
812 "data/img/arrow-right.png",
813 "data/img/arrow-right.png",
814 "data/img/arrow-right-pushed.png",
828 "data/img/arrow-left.png",
829 "data/img/arrow-left.png",
830 "data/img/arrow-left.png",
831 "data/img/arrow-left-pushed.png",
844 "data/img/arrow-right.png",
845 "data/img/arrow-right.png",
846 "data/img/arrow-right.png",
847 "data/img/arrow-right-pushed.png",
861 "data/img/arrow-left.png",
862 "data/img/arrow-left.png",
863 "data/img/arrow-left.png",
864 "data/img/arrow-left-pushed.png",
877 "data/img/arrow-right.png",
878 "data/img/arrow-right.png",
879 "data/img/arrow-right.png",
880 "data/img/arrow-right-pushed.png",
900 "Video Mode Initialization",
906 "data/img/arrow-left.png",
907 "data/img/arrow-left.png",
908 "data/img/arrow-left.png",
909 "data/img/arrow-left-pushed.png",
922 "data/img/arrow-right.png",
923 "data/img/arrow-right.png",
924 "data/img/arrow-right.png",
925 "data/img/arrow-right-pushed.png",
946 return glutExtensionSupported(str);
int GfParmSetStr(void *handle, const char *path, const char *key, const char *val)
Set a string parameter in the parameter set handle.
static void DepthPrevNext(void *vdelta)
char * GfuiEditboxGetString(void *scr, int id)
Get the string.
void * GfScrMenuInit(void *precMenu)
Create and activate the video options menu screen.
void fglutLeaveGameMode(void)
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
int GfuiButtonCreate(void *scr, const char *text, int font, int x, int y, int width, int align, int mouse, void *userDataOnPush, tfuiCallback onPush, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost)
Add a button to a screen.
#define GFPARM_RMODE_STD
if handle already openned return it
static void updateLabelText(void)
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
void GfuiAddKey(void *scr, unsigned char key, const char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased)
Add a Keyboard callback to a screen.
int GfuiLabelCreate(void *scr, const char *text, int font, int x, int y, int align, int maxlen)
Add a label to a screen.
static void onActivate(void *)
int GfuiEditboxCreate(void *scr, const char *text, int font, int x, int y, int width, int maxlen, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost, int margin)
Add a editbox to a screen.
void GfuiScreenAddBgImg(void *scr, const char *filename)
Add an image background to a screen.
void checkGLFeatures(void)
int GfParmWriteFile(const char *file, void *parmHandle, const char *name)
Write parameter set into file.
static void ResPrevNext(void *vdelta)
#define GFSCR_VAL_VINIT_BEST
const char * GfParmGetStr(void *parmHandle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
#define GFUI_FONT_LARGE_C
static void saveParams(void)
#define GFSCR_ATT_MAXREFRESH
The Gaming Framework API (client part).
static char * strndup(const char *str, int len)
#define GFSCR_VAL_VINIT_COMPATIBLE
void fglutGameModeString(const char *string)
void * GfuiScreenCreateEx(float *bgColor, void *userDataOnActivate, tfuiCallback onActivate, void *userDataOnDeactivate, tfuiCallback onDeactivate, int mouseAllowed)
Create a screen.
static const char * Mode[]
void GfuiEditboxSetString(void *scr, int id, const char *text)
Set a new string.
void GfuiLabelSetText(void *scr, int id, const char *text)
Change the text of a label.
static const char * VInit[]
static void initFromConf(void)
int fglutEnterGameMode(void)
void GfuiLabelSetColor(void *scr, int id, float *color)
Change the color of a label.
static void ModePrevNext(void *vdelta)
void(* tfuiCallback)(void *)
void GfScrInit(int argc, char *argv[])
void GfuiScreenActivate(void *screen)
Activate a screen and make it current.
void GfuiAddSKey(void *scr, int key, const char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased)
Add a Special Keyboard shortcut to the screen.
static float LabelColor[]
int GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, tdble val)
Set a numerical parameter in the parameter set handle.
void GfScrGetSize(int *scrw, int *scrh, int *vieww, int *viewh)
Get the screen and viewport sizes.
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
int GfuiTitleCreate(void *scr, const char *text, int maxlen)
Add a Title to the screen.
static void Reshape(int width, int height)
int GfuiGrButtonCreate(void *scr, const char *disabled, const char *enabled, const char *focused, const char *pushed, int x, int y, int align, int mouse, void *userDataOnPush, tfuiCallback onPush, void *userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost)
Add a graphical button to a screen.
#define GFUI_FONT_MEDIUM_C
void GfScrShutdown(void)
Shutdown the screen.
static const char * Depthlist[]
int GfuiGlutExtensionSupported(const char *str)
#define GFPARM_RMODE_CREAT
Create the file if doesn't exist.
static void VInitPrevNext(void *vdelta)