840 |
}, |
}, |
841 |
|
|
842 |
# Draw horizontal text with origin and scale from one coordsys and |
# Draw horizontal text with origin and scale from one coordsys and |
843 |
# width and height from another |
# width and height from another. |
|
# (XXX ignores w and h so far -> should consider in scaling) |
|
844 |
{ |
{ |
845 |
"Type": "2", |
"Type": "2", |
846 |
"Name": "HorizText2", |
"Name": "HorizText2", |
847 |
"Data": """ |
"Data": """ |
848 |
TextRenderer *r; |
TextRenderer *r; |
849 |
unistring txt; |
unistring txt; |
850 |
ZPt origin; |
float height, ascent, scale; |
|
float h1; |
|
851 |
int magic; |
int magic; |
852 |
""", |
""", |
853 |
"Params" : """ |
"Params" : """ |
854 |
Font f, |
Font f, |
855 |
String text, float x, float y, float z, |
String text, float height, float ascent, |
856 |
float h1, int magic |
float scale, int magic |
857 |
""", |
""", |
858 |
"ParamCode" : """ |
"ParamCode" : """ |
859 |
r = f; |
r = f; |
860 |
txt = text; origin.x = x; origin.y = y; origin.z = z; |
txt = text; |
861 |
this->h1 = h1; |
this->height = height; |
862 |
this->magic = magic; |
this->ascent = ascent; |
863 |
|
this->scale = scale; |
864 |
|
this->magic = magic; |
865 |
""", |
""", |
866 |
"ExtraClass" : """ |
"ExtraClass" : """ |
867 |
template<class Coords> struct Vertexer { |
template<class Coords> struct Vertexer { |
868 |
const Coords &c; |
const Coords &c; |
869 |
float scale; |
float scale; |
870 |
ZPt orig; |
float orig_y; |
871 |
Vertexer(Coords &c, float scale, ZPt orig) : c(c), scale(scale), orig(orig) { } |
Vertexer(Coords &c, float scale, float orig_y) : c(c), scale(scale), orig_y(orig_y) { } |
872 |
template<class T> void operator()(const T &x, const T &y) { |
template<class T> void operator()(const T &x, const T &y) { |
873 |
ZPt tmp(x - orig.x, y - orig.y, 0); |
ZPt tmp(x + 1, y - orig_y + 1, 0); |
874 |
//tmp.x *= scale; tmp.y *= scale; |
tmp.x *= scale; tmp.y *= scale; |
875 |
tmp.x += orig.x; tmp.y += orig.y; |
tmp.x -= 1; tmp.y += orig_y - 1; |
876 |
c.vertex(tmp); |
c.vertex(tmp); |
877 |
} |
} |
878 |
}; |
}; |
879 |
""", |
""", |
880 |
"RenderCode" : """ |
"RenderCode" : """ |
881 |
Vertexer<Coords> v(coords1, h1, origin); |
ZPt box(2,2,0); // compensate for -1/1 coordsys |
882 |
|
box = coords2.transform(box); |
883 |
|
|
884 |
|
float y = box.y/2 - (height-ascent)/4; |
885 |
|
Vertexer<Coords> v(coords1, scale, y); |
886 |
|
|
887 |
|
DBG(dbg_horiztext2) << box << " " << ascent << " " << y << "\\n"; |
888 |
|
|
889 |
glPushAttrib(GL_ENABLE_BIT); |
glPushAttrib(GL_ENABLE_BIT); |
890 |
glEnable(GL_BLEND); |
glEnable(GL_BLEND); |
891 |
switch(magic) { |
switch(magic) { |
892 |
case 0: |
case 0: |
893 |
Text::renderIter(*r, txt.begin(), txt.end(), |
Text::renderIter(*r, txt.begin(), txt.end(), |
894 |
origin.x,origin.y, |
0, y, |
895 |
v |
v |
896 |
); |
); |
897 |
break; |
break; |
900 |
static char buffer[100]; |
static char buffer[100]; |
901 |
sprintf(buffer, "FPS %2.2f", fps); |
sprintf(buffer, "FPS %2.2f", fps); |
902 |
Text::renderIter(*r, buffer, buffer+strlen(buffer), |
Text::renderIter(*r, buffer, buffer+strlen(buffer), |
903 |
origin.x,origin.y, |
0, y, |
904 |
v |
v |
905 |
); |
); |
906 |
break; |
break; |