// interprets the instructions from the array // for that letter and prints the translation offsets segments. void hersheyPrintLetterInfo(char ch) { const char *cp = hersheyFontData[ch % 128]; float lm = h2float(cp[0]); float rm = h2float(cp[1]); printf("hershey char: '%c'\n", ch); printf("hershey cmds: '%s'\n", cp); printf("lm: %f\n", lm); printf("rm: %f\n", rm); #if 0 printf("pretranslate(%f, %f, %f)\n", -lm, 0.0, 0.0); for (const char* p=cp+2 ; *p ; p+=2) { if ( p[0] == ' ' && p[1] == 'R' ) { printf("\nlinestrip: "); } else { float x = h2float( p[0] ); float y = -h2float( p[1] ); printf("(%f,%f) ", x, y); } } printf("\nposttranslate(%f, %f, %f)\n", rm, 0.0, 0.0); #endif printf("\n"); }
// font drawing for non-OpenGL renderers void hersheyDrawInitLetter(hersheyhandle *hh, const char ch, float *lm, float *rm) { // note: we map same set of glyphs twice here (using modulo operator) const char *cp = hersheyFontData[ch % 128]; hh->lm = h2float(cp[0]); *lm = hh->lm; hh->rm = h2float(cp[1]); *rm = hh->rm; hh->p=cp+2; }
int hersheyDrawNextLine(hersheyhandle *hh, int *draw, float *x, float *y) { if (*(hh->p)) { hh->p += 2; if ( hh->p[0] == ' ' && hh->p[1] == 'R' ) { *draw = 0; } else { *draw = 1; *x = h2float( hh->p[0] ); *y = -h2float( hh->p[1] ); } return 0; } else { return 1; } }
// hersheyDrawLetter() interprets the instructions from the array // for that letter and renders the letter with line segments. void hersheyDrawLetter(const char* cp) { float lm = h2float(cp[0]); float rm = h2float(cp[1]); glTranslatef(-lm,0,0); glBegin(GL_LINE_STRIP); for (const char* p=cp+2 ; *p ; p+=2) { if ( p[0] == ' ' && p[1] == 'R' ) { glEnd(); glBegin(GL_LINE_STRIP); } else { float x = h2float( p[0] ); float y = -h2float( p[1] ); glVertex2f(x,y); } } glEnd(); glTranslatef(rm,0,0); } /* drawLetter */
// hersheyDrawLetter() interprets the instructions from the array // for that letter and renders the letter with line segments. void hersheyDrawLetterOpenGL(unsigned char ch, int drawendpoints) { #if defined(VMDOPENGL) || defined(VMDOPENGLPBUFFER) // note: we map same set of glyphs twice here (using modulo operator) const char *cp = hersheyFontData[ch % 128]; float lm = h2float(cp[0]); float rm = h2float(cp[1]); const char *p; glTranslatef(-lm,0,0); // draw font vectors for this glyph glBegin(GL_LINE_STRIP); for (p=cp+2; (*p); p+=2) { if (p[0] == ' ' && p[1] == 'R') { glEnd(); glBegin(GL_LINE_STRIP); } else { float x = h2float( p[0] ); float y = -h2float( p[1] ); glVertex2f(x,y); } } glEnd(); // Draw points at each vector endpoint for this glyph, so // that we don't get "cracks" between the vectors when // rendering with much larger line widths. This is a // significant improvement for antialiased line/point // widths >= 2.0, but non-antialiased lines of width 1.0 or // 2.0 often look better without the end points drawn. if (drawendpoints) { glBegin(GL_POINTS); for (p=cp+2; (*p); p+=2) { if (p[0] == ' ' && p[1] == 'R') { glEnd(); glBegin(GL_POINTS); } else { float x = h2float( p[0] ); float y = -h2float( p[1] ); glVertex2f(x,y); } } glEnd(); } glTranslatef(rm,0,0); #endif } /* drawLetter */
// font drawing for non-OpenGL renderers void hersheyDrawInitLetter(hersheyhandle *hh, const char ch, float *lm, float *rm) { const char *cp = hersheyFontData[ch % 128]; hh->lm = h2float(cp[0]); hh->rm = h2float(cp[1]); hh->p=cp+2; }