Sticky tape technology and OpenGL fonts

It is very interesting that graphene can be isolated with tape and that fingerprints can be lifted with tape and the other unusual things that can be done with just something sticky. I noticed some long time ago that taking tape off a roll produced light. Graphene sheets are quite the interesting object. The strangest thing about it is that this could have been done any time in the history of people. It is such a low tech thing with such a strange and useful product.

The code below is to index a file of Xfonts that are listed with:

xlsfonts>fontlist
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>

int main(int argc, char * argv[]){
uint32_t arf[10000];
void *arfp=&arf;
FILE *fi;
FILE *fo;
int arfi=0;
uint32_t fouv=0;
char anyline[1024];
int len;
int telp=0;
int lino=0;
char fname[]="fontlist";
char fnameo[]="fontlistIndex";
fi=fopen(fname,"rb");
fo=fopen(fnameo,"wb");
fseek(fi,0,SEEK_END);
len=ftell(fi);
fseek(fi,0,SEEK_SET);
while ( feof(fi) == 0 ) {
//printf ("At %d %d %d %s",telp,lino,strlen(anyline),anyline);
fgets(anyline,1000,fi);
arf[arfi]=(uint32_t)telp;
arf[arfi+1]=(uint32_t)(strlen(anyline) -1);
arfi++;
arfi++;
telp=ftell(fi);
lino++;
}
fwrite (arfp,sizeof(uint32_t),2*lino-2,fo);
printf ("Size is %d %d\n",len,lino*8);
printf ("Lines is %d \n",lino);
printf ("Average is %d\n",len/lino);
fclose(fi);
fclose(fo);
return 0;
}

I used uint32_t so that the data was portable between systems that use different "int" sizes due to the processor architecture. The fonts are actually used in OpenGL somewhat like this:

#include "Ants_Common.h"
extern int fontstat;
extern GLuint base;


extern unsigned int  Screenwidth;
extern unsigned int  Screenheight;

void drawBoxText(float x,float y,float cdepth,int w){
//return;
float depthZ;
float boxHeight;
float boxWidth;
float borderWidth=0.009;
float borderHeight=0.009;

boxHeight=0.04f*(768.0/(float)Screenheight);
y=y-boxHeight/4.0;
boxWidth=0.022f*(float)w*(768/(float)Screenheight);
x=x-(0.021f*(768/(float)Screenheight)/2.0);
depthZ=cdepth;
borderWidth=0.0059;
borderHeight=boxHeight/10.0;

glColor4f(0.50f, 0.50f, 0.50f,01.0f);
glBegin(GL_QUADS);
 glVertex3f(x+borderHeight, y+borderWidth, depthZ);
 glVertex3f(x+borderHeight, y+boxHeight+borderWidth, depthZ);
 glVertex3f(x+boxWidth+borderHeight, y+boxHeight+borderWidth, depthZ);
 glVertex3f(x+boxWidth+borderHeight, y+borderWidth, depthZ);
glEnd();

glColor4f(0.20f, 0.20f, 0.40f,01.0f);

glBegin(GL_QUADS);
 glVertex3f(x, y, depthZ);
 glVertex3f(x, y+boxHeight, depthZ);
 glVertex3f(x+boxWidth, y+boxHeight, depthZ);
 glVertex3f(x+boxWidth, y, depthZ);
glEnd();
glColor4f(1.0f, 1.0f, 1.0f,01.0f);
}

int makeRasterFont(Display *dpy)
{
    XFontStruct *fontInfo;
    Font id;
    unsigned int first, last;
    fontInfo = XLoadQueryFont(dpy,       
"-val-free courier-medium-r-normal--0-0-0-0--0-iso8859-1");
/*
$> fc-list 
$>xlsfonts
4,514 fonts
*/

if (fontInfo == NULL) {
        printf ("no font found\n");
 return 1;
}

    id = fontInfo->fid;
    first = fontInfo->min_char_or_byte2;
    last = fontInfo->max_char_or_byte2;

    base = glGenLists(last+1);
    if (base == 0) {
        printf ("out of display lists\n");
return 2;
    }
    glXUseXFont(id, first, last-first+1, base+first);
return 0;
}

void printString(char *s) {
 if ( fontstat==0){
  glListBase(base);
  glCallLists(strlen(s), GL_UNSIGNED_BYTE, (unsigned char *)s);
 }
}
void printStringAt(char *s,float x,float  y){
float cdepth=-1.11f;
glPushMatrix();
drawBoxText(x,y,cdepth,strlen(s));
glRasterPos3f(x,y,cdepth);
    printString(s);
glPopMatrix();
}

The code is a little dated and does not take into account projections and the scale of the specific font. They show up quite well in the OpenGL space as they are a fixed size. A bit mapped font is better for messages on the cave wall, as they grow as approached and do not block backgrounds.

0 comments:

Automated Intelligence

Automated Intelligence
Auftrag der unendlichen LOL katzen