glut-helper.cpp

00001 /*
00002     GLICT - Graphics Library Interface Creation Toolkit
00003     Copyright (C) 2006-2007 OBJECT Networks
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 
00021 
00022 
00023 
00024 /* This file is now used only to support examples. Its functionality is now
00025    superseded by fonts.cpp which offers a wider variety of font support and
00026    extensibility. */
00027 
00028 
00029 // Glut-helper.h
00030 // contains glut helper
00031 
00032 // objnet glut helper
00033 // (c) 2005 object networks
00034 //
00035 // contains some helper code for glut
00036 // e.g. entire string printing
00037 
00038 #include <GL/glut.h>
00039 #include <string.h>
00040 
00041 void DEBUGPRINT(char* txt, ...);
00042 
00043 char* glutxStrokeStringExpert(const char* txt, const void* font) {
00044 
00045     glPushMatrix();
00046     char *p;
00047     for (p = (char*)txt; *p && *p!='\n' && *p!='\r'; p++) {
00048         glutStrokeCharacter((void*)font,*p);
00049     }
00050     glPopMatrix();
00051     return p;
00052 }
00053 #include <stdio.h>
00054 void glutxStrokeString(const char* txt, const void* font, float x, float y) {
00055 
00056 
00057                 glRotatef(180.0, 1.0, 0.0, 0.0);
00058                 //glTranslatef(0, -5,0);
00059 
00060         printf("%s %g %g\n", txt, x, y);
00061         char* fromwhere=(char*)txt;
00062     do {
00063         if (fromwhere!=txt) fromwhere++;
00064 
00065                 glTranslatef(x,-y-1,0);
00066         //if (font==GLUT_STROKE_ROMAN)
00067         //    glScalef(0.1,0.075,0.075);
00068         //else
00069         //    glScalef(0.075,0.075,0.075);
00070         glScalef(.0075, .0075, .0075);
00071 
00072         fromwhere = glutxStrokeStringExpert(fromwhere,font);
00073 
00074         glScalef(1./.0075, 1./.0075, 1./.0075);
00075                 glTranslatef(-x,y+1,0);
00076         y += 1;
00077     } while (*fromwhere);
00078 
00079     //printf("Rendered %s\n", txt);
00080 
00081                 //glTranslatef(0, 10,0);
00082                 glRotatef(180.0, -1.0, 0.0, 0.0);
00083 
00084 }
00085 
00086 void glutxBitmapString(char* txt, void* font,int x,int y) {
00087     int len, i;
00088 
00089 
00090 
00091     glRasterPos2f(x, y);
00092     len = (int) strlen(txt);
00093     for (i = 0; i < len; i++) {
00094       glutBitmapCharacter(font, txt[i]);
00095     }
00096 
00097 }
00098 float glutxBitmapSize(char* txt, void* font) {
00099     int size=0, len=strlen(txt);
00100     for (int i=0;i<len;i++) {
00101         size+=glutBitmapWidth(font,txt[i]);
00102     }
00103     return (float)size;
00104 }
00105 
00106 
00107 float glutxStrokeSize(const char* txt, const void* font) {
00108 
00109 
00110 //    printf(" SIZE OF %s\n", txt);
00111 
00112     int size=0, len=strlen(txt);
00113     int maxsize=0;
00114     for (int i=0;i<len;i++) {
00115         size+=glutStrokeWidth((void*)font,txt[i]);
00116         if (txt[i]=='\n' || txt[i]=='\r') {
00117             if (size>maxsize) maxsize=size;
00118             if (i < len && (txt[i]=='\n' && txt[i+1]=='\r' || txt[i]=='\r' && txt[i+1]=='\n')) i++;
00119             size=0;
00120         }
00121 
00122     }
00123     if (size>maxsize) maxsize=size;
00124     size = maxsize;
00125 
00126 
00127     // scale it down appropriately (like we've done before)
00128     //if (font != GLUT_STROKE_ROMAN)
00129     //    return (float)size*0.075;
00130     //else
00131     //    return (float)size*0.1;//0.12
00132     return (float)size * .0075;
00133 
00134 }
00135 int glutxNumberOfLines(const char* txt) {
00136     int count=1; // at least 1 line
00137     //DEBUGPRINT("NUMBEROFLINES: ");
00138     for (unsigned int i=0;i<strlen(txt);i++) {
00139         if (txt[i]=='\n') {
00140             count++;
00141         } //else DEBUGPRINT("%d ",txt[i]);
00142     }
00143 
00144     return count;
00145 }

SourceForge.net Logo
generated with doxygen 1.5.3 on Mon Oct 29 18:09:26 2007