diff --git a/Engine.cc b/Engine.cc index 8cf80db..14cdf44 100644 --- a/Engine.cc +++ b/Engine.cc @@ -17,7 +17,6 @@ #include #include #include "SDL.h" -#include "SDL_ttf.h" using namespace std; #define AG_EVENT_PREFIX "__ag_event_" @@ -128,15 +127,15 @@ Engine::~Engine() { delete it->second; } - for (std::map::iterator it = m_textboxes.begin(); + for (std::map::iterator it = m_textboxes.begin(); it != m_textboxes.end(); it++) { - SDL_FreeSurface(it->second); + delete it->second; } delete m_fileLoader; if (m_font != NULL) - TTF_CloseFont(m_font); + delete m_font; } bool Engine::load(const char * program) @@ -154,9 +153,15 @@ bool Engine::load(const char * program) } else { - m_font = TTF_OpenFont(path.c_str(), 16); - if (m_font == NULL) - cerr << "Error loading " FONT_NAME "!" << endl; + m_font = new FTBufferFont(path.c_str()); + if (m_font->Error() != 0) + { + cerr << "Error loading font '" << path << "'" << endl; + } + else + { + m_font->FaceSize(20); + } } int s = luaL_loadfile(m_luaState, program); @@ -473,28 +478,18 @@ int Engine::createTextBox(const char * text, int mode, Uint8 r, Uint8 g, Uint8 b, Uint8 br, Uint8 bg, Uint8 bb) { - SDL_Surface * surf = NULL; - SDL_Color color = {r, g, b}; - SDL_Color bgcolor = {br, bg, bb}; - switch (mode) - { - case 0: - surf = TTF_RenderText_Solid(m_font, text, color); - break; - case 1: - surf = TTF_RenderText_Shaded(m_font, text, color, bgcolor); - break; - case 2: - surf = TTF_RenderText_Blended(m_font, text, color); - break; - } - if (surf != NULL) - { - int id = m_next_text_index++; - m_textboxes[id] = surf; - return id; - } - return 0; + GLfloat color[] = {1.0, 0.7, 0.1, 0.5}; + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color); + glPushMatrix(); + glTranslatef(-10, 0, 6); + glRotatef(90, 1, 0, 0); + glPushAttrib(GL_ENABLE_BIT); + glEnable(GL_NORMALIZE); + glScalef(0.1, 0.1, 0.1); + m_font->Render(text); + glPopAttrib(); + glPopMatrix(); + return 1; } void Engine::getScreenSize(int * width, int * height) @@ -507,8 +502,6 @@ void Engine::drawText(int id, int x, int y) { if (m_textboxes.find(id) != m_textboxes.end()) { - SDL_Rect dstrect = {x, y, 0, 0}; - SDL_BlitSurface(m_textboxes[id], NULL, m_video.getSurface(), &dstrect); } } diff --git a/Engine.h b/Engine.h index 131d991..edc4ae6 100644 --- a/Engine.h +++ b/Engine.h @@ -12,7 +12,7 @@ #include "wfobj/WFObj.h" #include "Video.h" #include "refptr/refptr.h" -#include "SDL_ttf.h" +#include "ftgl.h" class Engine { @@ -173,7 +173,7 @@ class Engine OdeWorld m_world; std::map m_objects; int m_next_object_index; - std::map m_textboxes; + std::map m_textboxes; int m_next_text_index; GLdouble m_eye[3]; GLdouble m_center[3]; @@ -187,7 +187,7 @@ class Engine SDL_Event m_updateEvent; SDL_Event m_exitEvent; Uint32 m_event_time; - TTF_Font * m_font; + FTFont * m_font; bool m_event_update_present; bool m_event_key_down_present; diff --git a/Makefile b/Makefile index 0291900..be64bf0 100644 --- a/Makefile +++ b/Makefile @@ -23,11 +23,14 @@ ifeq ($(strip $(LUALIBS)),) LUALIBS := -llua5.1 endif -SDLINCLUDE := $(shell sdl-config --cflags) -SDLLIBS := $(shell sdl-config --libs) -lSDL_image -lSDL_ttf +FTGLINCLUDE := $(shell pkg-config --cflags ftgl) +FTGLLIBS := $(shell pkg-config --libs ftgl) -ODEINCLUDE := $(shell ode-config --cflags) -ODELIBS := $(shell ode-config --libs) +SDLINCLUDE := $(shell sdl-config --cflags) +SDLLIBS := $(shell sdl-config --libs) -lSDL_image + +ODEINCLUDE := $(shell ode-config --cflags) +ODELIBS := $(shell ode-config --libs) TOPLEVEL := $(shell pwd) @@ -39,10 +42,10 @@ else GLLIBS := -lGL -lGLU endif -export CPPFLAGS := $(LUAINCLUDE) $(SDLINCLUDE) $(ODEINCLUDE) -I$(TOPLEVEL) +export CPPFLAGS := $(LUAINCLUDE) $(SDLINCLUDE) $(ODEINCLUDE) $(FTGLINCLUDE) -I$(TOPLEVEL) export CFLAGS := $(CPPFLAGS) -O2 -Wall export CXXFLAGS := $(CFLAGS) -export LDFLAGS := $(LUALIBS) $(ODELIBS) $(GLLIBS) $(WINDOWSLIBS) $(SDLLIBS) +export LDFLAGS := $(LUALIBS) $(ODELIBS) $(GLLIBS) $(WINDOWSLIBS) $(SDLLIBS) $(FTGLLIBS) ifdef DEBUG CFLAGS += -g diff --git a/anaglym.cc b/anaglym.cc index 16c94b9..620631b 100644 --- a/anaglym.cc +++ b/anaglym.cc @@ -3,7 +3,6 @@ #include "anaglym.h" #include "Engine.h" #include "SDL.h" -#include "SDL_ttf.h" #include /* exit(), srand() */ #include #include @@ -74,11 +73,6 @@ int main(int argc, char * argv[]) Video video; video.start(width, height, fullscreen, grab_input); - if (TTF_Init() != 0) - { - cerr << "TTF_Init() error" << endl; - exit(3); - } dInitODE(); g_engine = new Engine(argv[0], video); @@ -87,7 +81,6 @@ int main(int argc, char * argv[]) delete g_engine; video.stop(); dCloseODE(); - TTF_Quit(); return 0; } diff --git a/tests/cratestack.lua b/tests/cratestack.lua index 2b2e8f7..299d859 100644 --- a/tests/cratestack.lua +++ b/tests/cratestack.lua @@ -42,3 +42,7 @@ end function mouse_moves(x, y, xrel, yrel) ag.println("mouse_moves ", x, ", ", y) end + +function update_event() + ag.createSolidTextBox("Hi there everyone!", 0, 0, 0) +end