PDA

View Full Version : Trouble with making custom font library



blessman11
03-11-2011, 02:56 AM
I'm having trouble trying to adapt (the red book font tutorial) and create my own font. So far the issue I'm having is that my makeFont Function doesn't appear to store my "pseudo fonts" for display.

I don't quite understand why the polygons I put aren't being displayed.


void makeFont(void)
{
GLuint i;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
fontOffset = glGenLists (128);
for (i = 32; i < 58; i++) {
glNewList(i+fontOffset, GL_COMPILE);
draw_ball();
glEndList();
}

for (i = 58; i < 96; i++) {
glNewList(i+fontOffset, GL_COMPILE);
draw_ball2();
glEndList();
}
for (i = 96; i < 127; i++) {
glNewList(i+fontOffset, GL_COMPILE);
draw_ball3();
glEndList();
}
}

void Init(void)
{
glShadeModel (GL_FLAT);//this can be flat or smooth
makeFont();
}

void printString(char *s)
{
glPushAttrib (GL_LIST_BIT);
glListBase(fontOffset);
glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s);
glPopAttrib ();
}

void display(void)
{
GLfloat white[3] = { 1.0, 0.0, 0.0 };//colour change
int i, j;
char teststring[33];

glClear(GL_COLOR_BUFFER_BIT);
glColor3fv(white);
for (i = 32; i < 127; i += 32) {
glRasterPos2i(20, 200 - 18*i/32);
for (j = 0; j < 32; j++)
teststring[j] = (char) (i+j);
teststring[32] = 0;
printString(teststring);
}

printString("The quick brown fox jumps");

printString("over a lazy dog.");
glEnd();
glFlush ();
glutSwapBuffers();
}

Header file

#ifndef _FONTS_H_H
#define _FONTS_H_H

#define PI 3.1415926535898
GLint circle_points = 145445;
void MyCircle2f(GLfloat centerx, GLfloat centery, GLfloat radius){
GLint i;
GLdouble angle;
glBegin(GL_POLYGON);
for (i = 0; i < circle_points; i++) {
angle = 2*PI*i/circle_points;
glVertex2f(centerx+radius*cos(angle), centery+radius*sin(angle));
}
glEnd();
}

GLfloat RadiusOfBall = 15.;
// Draw the ball, centered at the origin
static void draw_ball() {
glColor3f(0.6,0.3,0.);
MyCircle2f(0.,0.,RadiusOfBall);
}

static void draw_ball2() {
glColor3f(0.0,0.0,1.0);
MyCircle2f(0.,0.,RadiusOfBall);
}

static void draw_ball3() {
glColor3f(0.0,1.0,0.);
MyCircle2f(0.,0.,RadiusOfBall);
}

static void draw_ball4() {
glColor3f(1.0,0.0,0.);
MyCircle2f(0.,0.,RadiusOfBall);
}
#endif