/* Spencer Shimko * HW4: This code is not compilable as-is. However it is utilized by my project to * select a valid X font and display text in a SDL/GL window. SDL does not offer * the same built-in support for fonts that glut does, so this is a hackish work- * around. */ #include #include #include void initFont(GLuint base, char* f) { Display* display; XFontStruct* font_info; int first; int last; // Need an X Display before calling any Xlib routines. display = XOpenDisplay(0); if (display == 0) { fprintf(stderr, "XOpenDisplay() failed. Exiting.\n"); exit(-1); } else { // Load the font. font_info = XLoadQueryFont(display, f); if (!font_info) { fprintf(stderr, "XLoadQueryFont() failed - Exiting.\n"); exit(-1); } else { // Tell GLX which font & glyphs to use. first = font_info->min_char_or_byte2; last = font_info->max_char_or_byte2; glXUseXFont(font_info->fid, first, last-first+1, base+first); } XCloseDisplay(display); display = 0; } } //void drawText(GLfloat x, GLfloat y, char * msg){ void drawText(GLuint base, char* s) { if (!glIsList(font_base)) { fprintf(stderr, "print_string(): Bad display list. - Exiting.\n"); } else if (s && strlen(s)) { glPushAttrib(GL_LIST_BIT); glListBase(base); glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *)s); glPopAttrib(); } }