rudimentary FTGL text working

git-svn-id: svn://anubis/anaglym/trunk@162 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-11-13 02:35:02 +00:00
parent 8425807f99
commit f9c3bcfcc7
5 changed files with 40 additions and 47 deletions

View File

@ -17,7 +17,6 @@
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
#include "SDL.h" #include "SDL.h"
#include "SDL_ttf.h"
using namespace std; using namespace std;
#define AG_EVENT_PREFIX "__ag_event_" #define AG_EVENT_PREFIX "__ag_event_"
@ -128,15 +127,15 @@ Engine::~Engine()
{ {
delete it->second; delete it->second;
} }
for (std::map<int, SDL_Surface *>::iterator it = m_textboxes.begin(); for (std::map<int, FTFont *>::iterator it = m_textboxes.begin();
it != m_textboxes.end(); it != m_textboxes.end();
it++) it++)
{ {
SDL_FreeSurface(it->second); delete it->second;
} }
delete m_fileLoader; delete m_fileLoader;
if (m_font != NULL) if (m_font != NULL)
TTF_CloseFont(m_font); delete m_font;
} }
bool Engine::load(const char * program) bool Engine::load(const char * program)
@ -154,9 +153,15 @@ bool Engine::load(const char * program)
} }
else else
{ {
m_font = TTF_OpenFont(path.c_str(), 16); m_font = new FTBufferFont(path.c_str());
if (m_font == NULL) if (m_font->Error() != 0)
cerr << "Error loading " FONT_NAME "!" << endl; {
cerr << "Error loading font '" << path << "'" << endl;
}
else
{
m_font->FaceSize(20);
}
} }
int s = luaL_loadfile(m_luaState, program); 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 r, Uint8 g, Uint8 b,
Uint8 br, Uint8 bg, Uint8 bb) Uint8 br, Uint8 bg, Uint8 bb)
{ {
SDL_Surface * surf = NULL; GLfloat color[] = {1.0, 0.7, 0.1, 0.5};
SDL_Color color = {r, g, b}; glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);
SDL_Color bgcolor = {br, bg, bb}; glPushMatrix();
switch (mode) glTranslatef(-10, 0, 6);
{ glRotatef(90, 1, 0, 0);
case 0: glPushAttrib(GL_ENABLE_BIT);
surf = TTF_RenderText_Solid(m_font, text, color); glEnable(GL_NORMALIZE);
break; glScalef(0.1, 0.1, 0.1);
case 1: m_font->Render(text);
surf = TTF_RenderText_Shaded(m_font, text, color, bgcolor); glPopAttrib();
break; glPopMatrix();
case 2: return 1;
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;
} }
void Engine::getScreenSize(int * width, int * height) 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()) 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);
} }
} }

View File

@ -12,7 +12,7 @@
#include "wfobj/WFObj.h" #include "wfobj/WFObj.h"
#include "Video.h" #include "Video.h"
#include "refptr/refptr.h" #include "refptr/refptr.h"
#include "SDL_ttf.h" #include "ftgl.h"
class Engine class Engine
{ {
@ -173,7 +173,7 @@ class Engine
OdeWorld m_world; OdeWorld m_world;
std::map<int, Object *> m_objects; std::map<int, Object *> m_objects;
int m_next_object_index; int m_next_object_index;
std::map<int, SDL_Surface *> m_textboxes; std::map<int, FTFont *> m_textboxes;
int m_next_text_index; int m_next_text_index;
GLdouble m_eye[3]; GLdouble m_eye[3];
GLdouble m_center[3]; GLdouble m_center[3];
@ -187,7 +187,7 @@ class Engine
SDL_Event m_updateEvent; SDL_Event m_updateEvent;
SDL_Event m_exitEvent; SDL_Event m_exitEvent;
Uint32 m_event_time; Uint32 m_event_time;
TTF_Font * m_font; FTFont * m_font;
bool m_event_update_present; bool m_event_update_present;
bool m_event_key_down_present; bool m_event_key_down_present;

View File

@ -23,11 +23,14 @@ ifeq ($(strip $(LUALIBS)),)
LUALIBS := -llua5.1 LUALIBS := -llua5.1
endif endif
SDLINCLUDE := $(shell sdl-config --cflags) FTGLINCLUDE := $(shell pkg-config --cflags ftgl)
SDLLIBS := $(shell sdl-config --libs) -lSDL_image -lSDL_ttf FTGLLIBS := $(shell pkg-config --libs ftgl)
ODEINCLUDE := $(shell ode-config --cflags) SDLINCLUDE := $(shell sdl-config --cflags)
ODELIBS := $(shell ode-config --libs) SDLLIBS := $(shell sdl-config --libs) -lSDL_image
ODEINCLUDE := $(shell ode-config --cflags)
ODELIBS := $(shell ode-config --libs)
TOPLEVEL := $(shell pwd) TOPLEVEL := $(shell pwd)
@ -39,10 +42,10 @@ else
GLLIBS := -lGL -lGLU GLLIBS := -lGL -lGLU
endif endif
export CPPFLAGS := $(LUAINCLUDE) $(SDLINCLUDE) $(ODEINCLUDE) -I$(TOPLEVEL) export CPPFLAGS := $(LUAINCLUDE) $(SDLINCLUDE) $(ODEINCLUDE) $(FTGLINCLUDE) -I$(TOPLEVEL)
export CFLAGS := $(CPPFLAGS) -O2 -Wall export CFLAGS := $(CPPFLAGS) -O2 -Wall
export CXXFLAGS := $(CFLAGS) export CXXFLAGS := $(CFLAGS)
export LDFLAGS := $(LUALIBS) $(ODELIBS) $(GLLIBS) $(WINDOWSLIBS) $(SDLLIBS) export LDFLAGS := $(LUALIBS) $(ODELIBS) $(GLLIBS) $(WINDOWSLIBS) $(SDLLIBS) $(FTGLLIBS)
ifdef DEBUG ifdef DEBUG
CFLAGS += -g CFLAGS += -g

View File

@ -3,7 +3,6 @@
#include "anaglym.h" #include "anaglym.h"
#include "Engine.h" #include "Engine.h"
#include "SDL.h" #include "SDL.h"
#include "SDL_ttf.h"
#include <stdlib.h> /* exit(), srand() */ #include <stdlib.h> /* exit(), srand() */
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -74,11 +73,6 @@ int main(int argc, char * argv[])
Video video; Video video;
video.start(width, height, fullscreen, grab_input); video.start(width, height, fullscreen, grab_input);
if (TTF_Init() != 0)
{
cerr << "TTF_Init() error" << endl;
exit(3);
}
dInitODE(); dInitODE();
g_engine = new Engine(argv[0], video); g_engine = new Engine(argv[0], video);
@ -87,7 +81,6 @@ int main(int argc, char * argv[])
delete g_engine; delete g_engine;
video.stop(); video.stop();
dCloseODE(); dCloseODE();
TTF_Quit();
return 0; return 0;
} }

View File

@ -42,3 +42,7 @@ end
function mouse_moves(x, y, xrel, yrel) function mouse_moves(x, y, xrel, yrel)
ag.println("mouse_moves ", x, ", ", y) ag.println("mouse_moves ", x, ", ", y)
end end
function update_event()
ag.createSolidTextBox("Hi there everyone!", 0, 0, 0)
end