53 const int BUFSIZE = 1024;
72 for (j = 0; j < 4; j++) {
82 glutSetCursor(GLUT_CURSOR_NONE);
140 glDisable(GL_DEPTH_TEST);
141 glDisable(GL_LIGHTING);
142 glDisable(GL_TEXTURE_2D);
143 glDisable(GL_CULL_FACE);
144 glDisable(GL_ALPHA_TEST);
146 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
151 glMatrixMode(GL_PROJECTION);
154 glMatrixMode(GL_MODELVIEW);
162 glClear(GL_COLOR_BUFFER_BIT);
166 GLfloat tx1 = 0.0f, tx2 = 1.0f, ty1 = 0.0f, ty2 = 1.0f;
172 if (rfactor >= 1.0f) {
174 tdble tdx = (1.0f-1.0f/rfactor)/2.0f;
179 tdble tdy = (1.0f-rfactor)/2.0f;
185 glEnable(GL_TEXTURE_2D);
186 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
187 glColor3f(0.0, 0.0, 1.0);
190 glTexCoord2f(tx1, ty1); glVertex3f(0.0, 0.0, 0.0);
195 glDisable(GL_TEXTURE_2D);
202 curObj = curObj->
next;
253 modifier = glutGetModifiers();
264 curKey = curKey->
next;
265 if ((curKey->
key == key) && ((curKey->
modifier == 0) || (curKey->
modifier & modifier) != 0)) {
290 modifier = glutGetModifiers();
301 curKey = curKey->
next;
326 modifier = glutGetModifiers();
337 curKey = curKey->
next;
338 if ((curKey->
key == key) && ((curKey->
modifier == 0) || (curKey->
modifier & modifier) != 0)) {
354 modifier = glutGetModifiers();
365 curKey = curKey->
next;
393 glutWarpPointer(x,
y);
401 if (button > -1 && button < 3) {
409 if (state == GLUT_DOWN) {
410 if (button == GLUT_RIGHT_BUTTON) {
422 if (button != GLUT_RIGHT_BUTTON) {
480 glutIdleFunc((
void(*)(
void))NULL);
526 glutKeyboardFunc((
void(*)(
unsigned char,
int,
int))NULL);
527 glutSpecialFunc((
void(*)(
int,
int,
int))NULL);
528 glutKeyboardUpFunc((
void(*)(
unsigned char,
int,
int))NULL);
529 glutSpecialUpFunc((
void(*)(
int,
int,
int))NULL);
530 glutMouseFunc((
void(*)(
int,
int,
int,
int))NULL);
531 glutMotionFunc((
void(*)(
int,
int))NULL);
532 glutPassiveMotionFunc((
void(*)(
int,
int))NULL);
533 glutIdleFunc((
void(*)(
void))NULL);
549 screen->
width = 640.0;
552 screen->
bgColor = (
float*)calloc(4,
sizeof(
float));
554 for(i = 0; i < 4; i++) {
562 return (
void*)screen;
588 screen->
width = 640.0;
591 screen->
bgColor = (
float*)calloc(4,
sizeof(
float));
592 for(i = 0; i < 4; i++) {
593 if (bgColor != NULL) {
594 screen->
bgColor[i] = bgColor[i];
609 return (
void*)screen;
630 if (glIsTexture(screen->
bgImage) == GL_TRUE) {
631 glDeleteTextures(1, &screen->
bgImage);
640 if (curObject != NULL) {
642 nextObject = curObject->
next;
644 curObject = nextObject;
645 }
while (curObject != screen->
objects);
649 if (curKey != NULL) {
651 nextKey = curKey->
next;
656 }
while (curKey != screen->
userKeys);
659 if (curKey != NULL) {
661 nextKey = curKey->
next;
688 return (
void*)screen;
746 const int BUFSIZE = 16;
752 curKey->
onPress = onKeyPressed;
755 curKey->
descr = strdup(
"");
757 curKey->
descr = strdup(descr);
762 curKey->
name = strdup(
"backspace");
765 curKey->
name = strdup(
"tab");
768 curKey->
name = strdup(
"enter");
771 curKey->
name = strdup(
"esc");
774 curKey->
name = strdup(
"space");
777 snprintf(buf, BUFSIZE,
"%c", key);
778 curKey->
name = strdup(buf);
784 curKey->
next = curKey;
824 curKey->
onPress = onKeyPressed;
827 curKey->
descr = strdup(
"");
829 curKey->
descr = strdup(descr);
834 curKey->
name = strdup(
"F1");
837 curKey->
name = strdup(
"F2");
840 curKey->
name = strdup(
"F3");
843 curKey->
name = strdup(
"F4");
846 curKey->
name = strdup(
"F5");
849 curKey->
name = strdup(
"F6");
852 curKey->
name = strdup(
"F7");
855 curKey->
name = strdup(
"F8");
858 curKey->
name = strdup(
"F9");
861 curKey->
name = strdup(
"F10");
864 curKey->
name = strdup(
"F11");
867 curKey->
name = strdup(
"F12");
870 curKey->
name = strdup(
"Left Arrow");
873 curKey->
name = strdup(
"Up Arrow");
876 curKey->
name = strdup(
"Right Arrow");
879 curKey->
name = strdup(
"Down Arrow");
881 case GLUT_KEY_PAGE_UP:
882 curKey->
name = strdup(
"Page Up");
884 case GLUT_KEY_PAGE_DOWN:
885 curKey->
name = strdup(
"Page Down");
888 curKey->
name = strdup(
"Home");
891 curKey->
name = strdup(
"End");
893 case GLUT_KEY_INSERT:
894 curKey->
name = strdup(
"Insert");
901 curKey->
next = curKey;
916 const int BUFSIZE = 1024;
923 snprintf(path, BUFSIZE,
"%sscreenshots",
GetLocalDir());
928 img = (
unsigned char*)malloc(vw * vh * 3);
933 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
934 glPixelStorei(GL_PACK_ALIGNMENT, 1);
935 glReadBuffer(GL_FRONT);
936 glReadPixels((sw-vw)/2, (sh-vh)/2, vw, vh, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)img);
940 snprintf(buf, BUFSIZE,
"%s/torcs-%4d%02d%02d%02d%02d%02d.png",
968 const int BUFSIZE = 1024;
971 if (glIsTexture(screen->
bgImage) == GL_TRUE) {
972 glDeleteTextures(1, &screen->
bgImage);
978 tex = (GLbyte*)
GfImgReadPng(filename, &w, &h, screen_gamma);
984 glGenTextures(1, &screen->
bgImage);
985 glBindTexture(GL_TEXTURE_2D, screen->
bgImage);
986 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
987 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
988 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)(tex));
#define GFSCR_SECT_MENUCOL
#define GFSCR_ELT_BTNDISABLED
void GfuiMouseShow(void)
Show the mouse cursor.
#define GFSCR_ELT_HELPCOLOR2
void GfuiScreenReplace(void *screen)
Activate a screen and make it current plus release the current screen.
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
int GfImgWritePng(unsigned char *img, const char *filename, int width, int height)
Write a buffer to a png image on disk.
static void gfuiKeyboardUp(unsigned char key, int, int)
static void gfuiPassiveMotion(int x, int y)
#define GFPARM_RMODE_STD
if handle already openned return it
void GfuiMouseSetPos(int x, int y)
Set the mouse position.
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
void GfuiKeyEventRegisterCurrent(tfuiKeyCallback onKeyAction)
void GfuiAddKey(void *scr, unsigned char key, const char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased)
Add a Keyboard callback to a screen.
int GfCreateDir(char *path)
Create directory for given path recursively, so all missing parent directories are created as well...
void GfuiDisplay(void)
Display function for the GUI to be called during redisplay of glut.
void GfuiScreenRelease(void *scr)
Release the given screen.
int(* tfuiSKeyCallback)(int key, int modifier, int state)
return 1 to prevent normal key computing
void gfuiObjectInit(void)
void GfuiScreenAddBgImg(void *scr, const char *filename)
Add an image background to a screen.
#define GFSCR_ELT_BGSCROLLIST
#define GFSCR_ELT_BGBTNFOCUS
void gfuiEditboxKey(tGfuiObject *obj, int key, int modifier)
static void gfuiMouse(int button, int state, int x, int y)
int(* tfuiKeyCallback)(unsigned char key, int modifier, int state)
return 1 to prevent normal key computing
void GfuiIdle(void)
Idle function for the GUI to be called during Idle loop of glut.
static void gfuiKeyboard(unsigned char key, int, int)
void GfuiSKeyEventRegister(void *scr, tfuiSKeyCallback onSKeyAction)
#define GFSCR_LIST_COLORS
void GfuiSKeyEventRegisterCurrent(tfuiSKeyCallback onSKeyAction)
The Gaming Framework API (client part).
void GfuiKeyEventRegister(void *scr, tfuiKeyCallback onKeyAction)
#define GFSCR_ELT_BGBTNDISABLED
void GfuiRegisterKey(unsigned char key, char *descr, void *userData, tfuiCallback onKeyPressed, tfuiCallback onKeyReleased)
Add a Keyboard callback to the current screen.
#define GFSCR_ELT_MOUSECOLOR1
#define GFSCR_ELT_MOUSECOLOR2
void GfuiDisplayNothing(void)
Dummy display function for glut.
void GfuiMouseSetHWPresent(void)
Force the hardware mouse pointer.
void * GfuiScreenCreateEx(float *bgColor, void *userDataOnActivate, tfuiCallback onActivate, void *userDataOnDeactivate, tfuiCallback onDeactivate, int mouseAllowed)
Create a screen.
void gfuiReleaseObject(tGfuiObject *curObject)
static void gfuiSpecial(int key, int, int)
#define GFSCR_ELT_EDITCURSORCLR
float tdble
Floating point type used in TORCS.
static void onActivate(void *)
unsigned char * GfImgReadPng(const char *filename, int *widthp, int *heightp, float screen_gamma)
Load an image from disk to a buffer in RGBA mode.
static double LastTimeClick
tfuiKeyCallback onKeyAction
tMouseInfo * GfuiMouseInfo(void)
Get the mouse information (position and buttons)
#define GFSCR_ELT_TIPCOLOR
static int GfuiMouseVisible
int GfuiScreenIsActive(void *screen)
Tell if the screen is active or not.
tfuiSKeyCallback onSKeyAction
void gfuiButtonInit(void)
#define GFSCR_ELT_LABELCOLOR
void * GfuiHookCreate(void *userDataOnActivate, tfuiCallback onActivate)
Create a callback hook.
#define GFSCR_ELT_HELPCOLOR1
void(* tfuiCallback)(void *)
void GfuiMouseHide(void)
Hide the mouse cursor.
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 void gfuiMotion(int x, int y)
void GfuiDraw(tGfuiObject *obj)
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.
double GfTimeClock(void)
Get the time in seconds.
float GfuiColor[GFUI_COLORNB][4]
#define GFSCR_ELT_BGCOLOR
#define GFSCR_ELT_BTNCLICK
void GfuiScreenShot(void *)
Save a screen shot in png format.
#define GFSCR_ELT_BTNFOCUS
#define GFSCR_ELT_BGBTNCLICK
#define GFSCR_ELT_SELSCROLLIST
void * GfuiScreenCreate(void)
Create a new screen.
tfuiCallback onDeactivate
static void gfuiColorInit(void)
static int onKeyAction(unsigned char key, int, int state)
void gfuiMouseAction(void *action)
#define GFSCR_ELT_BGSELSCROLLIST
#define GFSCR_ELT_SCROLLIST
void GfuiHookRelease(void *hook)
Release the given hook.
#define GFSCR_ELT_BGBTNENABLED
#define GFSCR_ELT_BTNENABLED
void GfuiScreenDeactivate(void)
Deactivate the current screen.
#define GFPARM_RMODE_CREAT
Create the file if doesn't exist.
static void gfuiSpecialUp(int key, int, int)
static int onSKeyAction(int key, int, int state)
void gfuiSelectNext(void *)
#define GFSCR_ELT_TITLECOLOR