myglFont.cpp myglFont.h OpenArena // //Module:myglFont.cpp //Author:TomHicks //Creation:09-01-2003 //LastEdit:06-19-2005 //Editors:None // //Purpose: // //SummaryofMethods: //Global //-functionname //description //blahClass //-functionname //description // //SummaryofProperties: //blahClass //-propertyname //description // #include"myglFont.h" namespaceOpenArena { Font::Font() { status=0; base=0; texture=0; screenWidth=1; screenHeight=1; } Font::~Font() { FreeFont(); } boolFont::BuildFont(constchar*texName) { FreeFont(); if(LoadGLTexture(texName,texture,GL_NEAREST,GL_NEAREST)) { floatx,y; base=glGenLists(256); glBindTexture(GL_TEXTURE_2D,texture); for(shorti=0;i<256;i++) { x=i%16/16.0f; y=i/16/16.0f; glNewList(base+i,GL_COMPILE); glBegin(GL_QUADS); glTexCoord2f(x,1-y-0.0625f); glVertex2i(0,0); glTexCoord2f(x+0.0625f,1-y-0.0625f); glVertex2i(16,0); glTexCoord2f(x+0.0625f,1-y); glVertex2i(16,16); glTexCoord2f(x,1-y); glVertex2i(0,16); glEnd(); glTranslated(16,0,0); glEndList(); } status=true; } returnstatus; } boolFont::FreeFont() { if(status) { glDeleteLists(base,256); status=false; } returnstatus; } voidFont::Print(intx,inty,constchar*str,unsignedintset) { if(status) { if(set>1) set=1; glBindTexture(GL_TEXTURE_2D,texture); //glDisable(GL_DEPTH_TEST); //glEnable(GL_BLEND); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0,screenWidth,0,screenHeight,-1,1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslated(x,y,0); glListBase(base-32+(128*set)); glCallLists(strlen(str),GL_BYTE,str); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); //glDisable(GL_BLEND); //glEnable(GL_DEPTH_TEST); } } boolFont::Loaded() { returnstatus; } voidFont::SetScreenDimensions(shortx,shorty) { screenWidth=x; screenHeight=y; } voidFont::SetScreenWidth(shortx) { screenWidth=x; } voidFont::SetScreenHeight(shorty) { screenHeight=y; } shortFont::ScreenWidth() { returnscreenWidth; } shortFont::ScreenHeight() { returnscreenHeight; } };