From 6bc81dd151c94ad72a9560761a9964e066cc53e6 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 13 Sep 2015 14:02:55 -0400 Subject: added text using freetype2 --- src/UIClass.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 5 +++++ 2 files changed, 64 insertions(+) (limited to 'src') diff --git a/src/UIClass.cpp b/src/UIClass.cpp index 1376d10..b0e0206 100644 --- a/src/UIClass.cpp +++ b/src/UIClass.cpp @@ -1,8 +1,67 @@ #include +#include +#include FT_FREETYPE_H + extern Player player; extern World *currentWorld; +static FT_Library ftl; +static FT_Face ftf; +static GLuint ftex; + +void UIClass::init(const char *ttf){ + if(FT_Init_FreeType(&ftl)){ + std::cout<<"Error! Couldn't initialize freetype."<glyph->bitmap.width*ftf->glyph->bitmap.rows*4); + for(j=0;jglyph->bitmap.width*ftf->glyph->bitmap.rows;j++){ + buf[j*4]=255; + buf[j*4+1]=255; + buf[j*4+2]=255; + buf[j*4+3]=ftf->glyph->bitmap.buffer[j]?255:0; + } + glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,ftf->glyph->bitmap.width,ftf->glyph->bitmap.rows,0,GL_RGBA,GL_UNSIGNED_BYTE,buf); + w=ftf->glyph->bitmap.width*(2.0/SCREEN_WIDTH); + h=ftf->glyph->bitmap.rows *(2.0/SCREEN_HEIGHT); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D,ftex); + glBegin(GL_QUADS); + glColor3ub(255,255,255); + glTexCoord2f(0,1);glVertex2f(xo,yo); + glTexCoord2f(1,1);glVertex2f(xo+w,yo); + glTexCoord2f(1,0);glVertex2f(xo+w,yo+h); + glTexCoord2f(0,0);glVertex2f(xo,yo+h); + glEnd(); + glDisable(GL_TEXTURE_2D); + xo+=w+.01; + free(buf); + }while(s[i++]); +} + void UIClass::handleEvents(){ static bool space=false; float thing; diff --git a/src/main.cpp b/src/main.cpp index 88c08ef..6c53a75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,6 +67,9 @@ int main(int argc,char **argv){ **** GAMELOOP **** **************************/ + ui.init("ttf/VCR_OSD_MONO_1.001.ttf"); + ui.setFontSize(100); + irand(time(NULL)); entPlay = &player; entPlay->spawn(0, 0); @@ -176,6 +179,8 @@ void render(){ glRectf(build.loc.x, build.loc.y, build.loc.x + build.width, build.loc.y + build.height); ///BWAHHHHHHHHHHHH + ui.putText(0,0,"Hello"); + /************************** **** CLOSE THE LOOP **** **************************/ -- cgit v1.2.3