//Computes a scaling value so that the strings
float computeScale(const char* strs[4]) {
float maxWidth = 0;
for(int i = 0; i < 4; i++) {
float width = t3dDrawWidth(strs[i]);
if (width > maxWidth) {
maxWidth = width;
}
}
return 2.6f / maxWidth;
}
float _angle = -30.0f;
float _scale;
//The four strings that are drawn
const char* STRS[4] = {"Video", "Tutorials", "Rock", ".com"};
void cleanup() {
t3dCleanup();
}
void handleKeypress(unsigned char key, int x, int y) {
switch (key) {
case 27: //Escape key
cleanup();
exit(0);
}
}
class T3DFont {
private:
float spaceWidth;
float widths[94];
GLuint displayListId2D;
GLuint displayListId3D;
public:
//Loads the specified font file into a new T3DFont object
T3DFont(ifstream &input) {
char buffer[8];
input.read(buffer, 8);
if (input.fail()) {
throw T3DLoadException("Invalid font file");
}
const char header[9] = "VTR\0FNT\0";
for(int i = 0; i < 8; i++) {
if (buffer[i] != header[i]) {
throw T3DLoadException("Invalid font file");
}
}
if (input.fail()) {
throw T3DLoadException("Invalid font file");
}
input.read(buffer, 1);
if (!input.eof()) {
throw T3DLoadException("Invalid font file");
}
}
void draw2D(char c) {
if (c >= 33 && c <= 126) {
glCallList(displayListId2D + c - '!');
}
}
void draw3D(char c) {
if (c >= 33 && c <= 126) {
glCallList(displayListId3D + c - '!');
}
}
float width(char c) {
if (c >= 33 && c <= 126) {
return widths[c - 33];
}
else {
return spaceWidth;
}
}
};
//Initializes 3D text. Must be called before other functions in this header.
void t3dInit();
//Frees memory allocated for 3D text. No other functions in this header may be
//called after this one.
void t3dCleanup();
void t3dDraw2D(std::string str,
int hAlign, int vAlign,
float lineHeight = 1.5f);
void t3dDraw3D(std::string str,
int hAlign, int vAlign,
float depth,
float lineHeight = 1.5f);
//Indicates that an exception occurred when setting up 3D text
class T3DLoadException {
private:
std::string message0;
public:
T3DLoadException(std::string message1);
std::string message() const;
};