-int checkError(int line, char *file)
-{
- if((errCode = glGetError()) != GL_NO_ERROR) {
- errString = (GLubyte *)gluErrorString(errCode);
- fprintf(stderr, "OpenGL error: %s detected at line %d in file %s\n", errString, line, file);
- exit(1);
- }
- return 0;
-}
-
-
-void FPS_Setup(void)
-{
- Display *Dpy;
- XFontStruct *fontInfo;
- Font id;
- int first=0, last=255;
-
- Dpy = XOpenDisplay(NULL);
- fontInfo = XLoadQueryFont(Dpy, FONT);
- if (fontInfo == NULL)
- {
- fprintf(stderr, "Failed to load font %s\n", FONT);
- exit(1);
- }
-
- id = fontInfo->fid;
- first = fontInfo->min_char_or_byte2;
- last = fontInfo->max_char_or_byte2;
-
- base = glGenLists((GLuint) last+1);
- if (base == 0) {
- fprintf (stderr, "out of display lists\n");
- exit(1);
- }
- glXUseXFont(id, first, last-first+1, base+first);
-
-}
-
-void PrintString(float x, float y, char *string)
-{
- int len, i;
-
- /* save the current state */
- /* note: could be expensive! */
- glPushAttrib(GL_ALL_ATTRIB_BITS);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(0, global_width, 0, global_height);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- /* disable lighting and texturing when drawing bitmaps! */
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_LIGHTING);
- glDisable(GL_BLEND);
-
- /* draw a black background */
-
- /* draw the text */
- glColor3f(1,1,1);
- glRasterPos2f( x, y);
- len = (int) strlen(string);
- for (i = 0; i < len; i++) {
- if (glIsList(base+string[i]))
- glCallList(base+string[i]);
- else
- fprintf(stderr, "%d+string[%d] is not a display list!\n", base, i);
- }
-
- /* clean up after our state changes */
- glPopAttrib();
-}
-
-double gettime(void)
-{
- struct timeval now;
-#ifdef GETTIMEOFDAY_TWO_ARGS
- struct timezone tzp;
- gettimeofday(&now, &tzp);
-#else
- gettimeofday(&now);
-#endif
- return (double) (now.tv_sec + (((double) now.tv_usec) * 0.000001));
-}
-
-void DoFPS(void)
-{
- /* every SAMPLE_FRAMES frames, get the time and use it to get the
- frames per second */
- if (!(FrameCounter % SAMPLE_FRAMES)) {
- oldtime = newtime;
- newtime = gettime();
- sprintf(FPSstring, "FPS: %.02f", SAMPLE_FRAMES/(newtime-oldtime));
- }
-
- PrintString(x_pos,y_pos,FPSstring);
-
- FrameCounter++;
-}
-