examples/memory/glut-helper.cpp

00001 /*
00002     GLICT - Graphics Library Interface Creation Toolkit
00003     Copyright (C) 2006 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 
00025 /* This file is now used only to support examples. Its functionality is now
00026    superseded by fonts.cpp which offers a wider variety of font support and
00027    extensibility. */
00028 
00029 
00030 // Glut-helper.h
00031 // contains glut helper
00032 
00033 // objnet glut helper
00034 // (c) 2005 object networks
00035 //
00036 // contains some helper code for glut
00037 // e.g. entire string printing
00038 
00039 #include <GL/glut.h>
00040 #include <string.h>
00041 
00042 void DEBUGPRINT(char* txt, ...);
00043 
00044 char* glutxStrokeStringExpert(const char* txt, const void* font) {
00045     glPushMatrix();
00046     char *p;
00047     for (p = (char*)txt; *p && *p!='\n'; 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     char* fromwhere=(char*)txt;
00056     do {
00057         if (fromwhere!=txt) fromwhere++;
00058         glPushMatrix();
00059         glTranslatef(x,y,0);
00060         //if (font==GLUT_STROKE_ROMAN)
00061         //    glScalef(0.1,0.075,0.075);
00062         //else
00063         //    glScalef(0.075,0.075,0.075);
00064         glScalef(.0075, .0075, .0075);
00065         fromwhere = glutxStrokeStringExpert(fromwhere,font);
00066         glPopMatrix();
00067         y -= 1;
00068     } while (*fromwhere);
00069     printf("Rendered %s\n", txt);
00070 }
00071 
00072 void glutxBitmapString(char* txt, void* font,int x,int y) {
00073     int len, i;
00074 
00075 
00076 
00077     glRasterPos2f(x, y);
00078     len = (int) strlen(txt);
00079     for (i = 0; i < len; i++) {
00080       glutBitmapCharacter(font, txt[i]);
00081     }
00082 
00083 }
00084 float glutxBitmapSize(char* txt, void* font) {
00085     int size=0, len=strlen(txt);
00086     for (int i=0;i<len;i++) {
00087         size+=glutBitmapWidth(font,txt[i]);
00088     }
00089     return (float)size;
00090 }
00091 
00092 
00093 float glutxStrokeSize(const char* txt, const void* font) {
00094 
00095 
00096     printf(" SIZE OF %s\n", txt);
00097 
00098     int size=0, len=strlen(txt);
00099     int maxsize=0;
00100     for (int i=0;i<len;i++) {
00101         size+=glutStrokeWidth((void*)font,txt[i]);
00102         if (txt[i]=='\n') {
00103             if (size>maxsize) maxsize=size;
00104             size=0;
00105         }
00106     }
00107     if (size>maxsize) maxsize=size;
00108     size = maxsize;
00109 
00110 
00111     // scale it down appropriately (like we've done before)
00112     //if (font != GLUT_STROKE_ROMAN)
00113     //    return (float)size*0.075;
00114     //else
00115     //    return (float)size*0.1;//0.12
00116     return (float)size * .0075;
00117 
00118 }
00119 int glutxNumberOfLines(const char* txt) {
00120     int count=1; // at least 1 line
00121     //DEBUGPRINT("NUMBEROFLINES: ");
00122     for (unsigned int i=0;i<strlen(txt);i++) {
00123         if (txt[i]=='\n') {
00124             count++;
00125         } //else DEBUGPRINT("%d ",txt[i]);
00126     }
00127 
00128     return count;
00129 }

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