rudimentary FTGL text working
git-svn-id: svn://anubis/anaglym/trunk@162 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
8425807f99
commit
f9c3bcfcc7
55
Engine.cc
55
Engine.cc
@ -17,7 +17,6 @@
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#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<int, SDL_Surface *>::iterator it = m_textboxes.begin();
|
||||
for (std::map<int, FTFont *>::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);
|
||||
}
|
||||
}
|
||||
|
||||
|
6
Engine.h
6
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<int, Object *> m_objects;
|
||||
int m_next_object_index;
|
||||
std::map<int, SDL_Surface *> m_textboxes;
|
||||
std::map<int, FTFont *> 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;
|
||||
|
9
Makefile
9
Makefile
@ -23,8 +23,11 @@ ifeq ($(strip $(LUALIBS)),)
|
||||
LUALIBS := -llua5.1
|
||||
endif
|
||||
|
||||
FTGLINCLUDE := $(shell pkg-config --cflags ftgl)
|
||||
FTGLLIBS := $(shell pkg-config --libs ftgl)
|
||||
|
||||
SDLINCLUDE := $(shell sdl-config --cflags)
|
||||
SDLLIBS := $(shell sdl-config --libs) -lSDL_image -lSDL_ttf
|
||||
SDLLIBS := $(shell sdl-config --libs) -lSDL_image
|
||||
|
||||
ODEINCLUDE := $(shell ode-config --cflags)
|
||||
ODELIBS := $(shell ode-config --libs)
|
||||
@ -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
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "anaglym.h"
|
||||
#include "Engine.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_ttf.h"
|
||||
#include <stdlib.h> /* exit(), srand() */
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user