#include #include #include #include FT_FREETYPE_H #define SDL_KEY e.key.keysym.sym extern Player *player; extern World *currentWorld; static FT_Library ftl; static FT_Face ftf; static GLuint ftex; static unsigned int fontSize; namespace ui { void initFonts(void){ 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; h=ftf->glyph->bitmap.rows; 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; free(buf); glDeleteTextures(1,&ftex); }while(s[i++]); } void putText(const float x,const float y,const char *str,...){ va_list args; char *buf; buf=(char *)calloc(128,sizeof(char)); va_start(args,str); vsnprintf(buf,128,str,args); va_end(args); putString(x,y,buf); free(buf); } void handleEvents(void){ SDL_Event e; while(SDL_PollEvent(&e)){ switch(e.type){ case SDL_QUIT: gameRunning=false; break; case SDL_KEYDOWN: if(SDL_KEY==SDLK_ESCAPE)gameRunning=false; if(SDL_KEY==SDLK_a){ player->vel.x=-.15; currentWorld=currentWorld->goWorldLeft(&player->loc,player->width); } if(SDL_KEY==SDLK_d){ player->vel.x=.15; currentWorld=currentWorld->goWorldRight(&player->loc,player->width); } if(SDL_KEY==SDLK_SPACE)player->vel.y=.25; if(SDL_KEY==SDLK_i)currentWorld=currentWorld->goWorldBack(&player->loc,player->width); if(SDL_KEY==SDLK_k)currentWorld=currentWorld->goWorldFront(&player->loc,player->width); break; case SDL_KEYUP: if(SDL_KEY==SDLK_a)player->vel.x=0; if(SDL_KEY==SDLK_d)player->vel.x=0; break; default: break; } } } }