Created
August 1, 2017 01:00
-
-
Save elucent/0569a5b083be5168bdf86eaa1b239f04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void draw_text(const char* txt, int x, int y, float scale, float spacing, bool is_precise, GLuint font){ | |
string s = txt; | |
float tx = 0.0; | |
float ty = 0.0; | |
float letter_offset; | |
if (is_precise){ | |
letter_offset = 0.0; | |
} | |
else { | |
letter_offset = (s.size()/2)*(-spacing*scale); | |
} | |
glBindTexture(GL_TEXTURE_2D,font); | |
glBegin(GL_QUADS); | |
for (int i = 0; i < s.size(); i ++){ | |
if (s.substr(i,1).compare("A") == 0){ | |
tx = 0.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("B") == 0){ | |
tx = 1.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("C") == 0){ | |
tx = 2.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("D") == 0){ | |
tx = 3.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("E") == 0){ | |
tx = 4.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("F") == 0){ | |
tx = 5.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("G") == 0){ | |
tx = 6.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("H") == 0){ | |
tx = 7.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("I") == 0){ | |
tx = 8.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("J") == 0){ | |
tx = 9.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("K") == 0){ | |
tx = 10.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("L") == 0){ | |
tx = 11.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("M") == 0){ | |
tx = 12.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("N") == 0){ | |
tx = 13.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("O") == 0){ | |
tx = 14.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("P") == 0){ | |
tx = 15.0; | |
ty = 0.0; | |
} | |
else if (s.substr(i,1).compare("Q") == 0){ | |
tx = 0.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("R") == 0){ | |
tx = 1.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("S") == 0){ | |
tx = 2.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("T") == 0){ | |
tx = 3.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("U") == 0){ | |
tx = 4.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("V") == 0){ | |
tx = 5.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("W") == 0){ | |
tx = 6.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("X") == 0){ | |
tx = 7.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("Y") == 0){ | |
tx = 8.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("Z") == 0){ | |
tx = 9.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("a") == 0){ | |
tx = 10.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("b") == 0){ | |
tx = 11.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("c") == 0){ | |
tx = 12.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("d") == 0){ | |
tx = 13.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("e") == 0){ | |
tx = 14.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("f") == 0){ | |
tx = 15.0; | |
ty = 1.0; | |
} | |
else if (s.substr(i,1).compare("g") == 0){ | |
tx = 0.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("h") == 0){ | |
tx = 1.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("i") == 0){ | |
tx = 2.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("j") == 0){ | |
tx = 3.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("k") == 0){ | |
tx = 4.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("l") == 0){ | |
tx = 5.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("m") == 0){ | |
tx = 6.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("n") == 0){ | |
tx = 7.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("o") == 0){ | |
tx = 8.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("p") == 0){ | |
tx = 9.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("q") == 0){ | |
tx = 10.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("r") == 0){ | |
tx = 11.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("s") == 0){ | |
tx = 12.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("t") == 0){ | |
tx = 13.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("u") == 0){ | |
tx = 14.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("v") == 0){ | |
tx = 15.0; | |
ty = 2.0; | |
} | |
else if (s.substr(i,1).compare("w") == 0){ | |
tx = 0.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("x") == 0){ | |
tx = 1.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("y") == 0){ | |
tx = 2.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("z") == 0){ | |
tx = 3.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("1") == 0){ | |
tx = 4.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("2") == 0){ | |
tx = 5.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("3") == 0){ | |
tx = 6.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("4") == 0){ | |
tx = 7.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("5") == 0){ | |
tx = 8.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("6") == 0){ | |
tx = 9.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("7") == 0){ | |
tx = 10.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("8") == 0){ | |
tx = 11.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("9") == 0){ | |
tx = 12.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare("0") == 0){ | |
tx = 13.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare(" ") == 0){ | |
tx = 14.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare(".") == 0){ | |
tx = 15.0; | |
ty = 3.0; | |
} | |
else if (s.substr(i,1).compare(",") == 0){ | |
tx = 0.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("!") == 0){ | |
tx = 1.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("?") == 0){ | |
tx = 2.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("(") == 0){ | |
tx = 3.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare(")") == 0){ | |
tx = 4.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("[") == 0){ | |
tx = 5.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("]") == 0){ | |
tx = 6.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("-") == 0){ | |
tx = 7.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("_") == 0){ | |
tx = 8.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("/") == 0){ | |
tx = 9.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("\\") == 0){ | |
tx = 10.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("|") == 0){ | |
tx = 11.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare(":") == 0){ | |
tx = 12.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare(";") == 0){ | |
tx = 13.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("=") == 0){ | |
tx = 14.0; | |
ty = 4.0; | |
} | |
else if (s.substr(i,1).compare("%") == 0){ | |
tx = 15.0; | |
ty = 4.0; | |
} | |
/*glTexCoord2f(((tx+1)/74.0),0.0); glVertex2f(x+letter_offset,y); | |
glTexCoord2f(((tx+1)/74.0),1.0/64.0); glVertex2f(x+8+letter_offset,y); | |
glTexCoord2f(((tx+2)/74.0),1.0/64.0); glVertex2f(x+8+letter_offset,y+8); | |
glTexCoord2f(((tx+2)/74.0),0.0); glVertex2f(x+letter_offset,y+8);*/ | |
/*v2 lettertex = _v2(((int)tx) % 16,(int)round(tx/16)); | |
glTexCoord2f(lettertex.y/16.0,lettertex.x/16.0); glVertex2f(x+letter_offset,y); | |
glTexCoord2f((lettertex.y+1)/16.0,(lettertex.x+1)/16.0); glVertex2f(x+8+letter_offset,y); | |
glTexCoord2f((lettertex.y+1)/16.0,(lettertex.x+1)/16.0); glVertex2f(x+8+letter_offset,y+8); | |
glTexCoord2f(lettertex.y/16.0,lettertex.x/16.0); glVertex2f(x+letter_offset,y+8);*/ | |
glTexCoord2f((ty)/16.0,(tx-(int)floor(tx/16.0))/16.0); glVertex2f(x+letter_offset,y); | |
glTexCoord2f((ty+1.0)/16.0,(tx-(int)floor(tx/16.0))/16.0); glVertex2f(x+letter_offset,y+(8*scale)); | |
glTexCoord2f((ty+1.0)/16.0,((tx-(int)floor(tx/16.0))+1.0)/16.0); glVertex2f(x+(8*scale)+letter_offset,y+(8*scale)); | |
glTexCoord2f((ty)/16.0,((tx-(int)floor(tx/16.0))+1.0)/16.0); glVertex2f(x+(8*scale)+letter_offset,y); | |
letter_offset += spacing*scale; | |
} | |
glEnd(); | |
glBindTexture(GL_TEXTURE_2D,0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment