private static final char alphabet[] = {'A','B','C','D','E','F','G','H','I','J',
'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b',
'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0'};
private static final char others[] = {'!','@','#','$','%','^','&','*','(',')','-',
'_','+','=','[',']','{','}',';',':','\"',',','.','?','\'','<','>','/',' '};
// text search variables
private int letterIndex;
private boolean letterFound; // checks if letter is found
private boolean otherFound;
private char letterThis;
// letter draw tools
private FileInputStream letterFile;
private Texture letterTex;
// letter position
private int letterX;
private int letterY;
private int letterWidth;
private int letterScale;
// letter color and opacity variables
private float red;
private float green;
private float blue;
private float opacity;
// creates a letter texture for drawing
public LetterList(char letter) {
letterWidth = 0;
initOpenGL();
/************************************************
* search alphabet
***********************************************/
letterFound = false;
for (int c = 0; c < alphabet.length; ++c) {
if (alphabet[c] == letter) {
letterFound = true;
letterIndex = c;
letterThis = alphabet[c];
letterWidth = 17+letterScale;
// if the letter is wider
if (letter == 'M' || letter == 'N' || letter == 'W' || letter == 'w' || letter == '4')
letterWidth = 19+letterScale;
break;
} // if
} // for loop
if (letterFound) {
try {
// checks if letter is a capital
if (letterIndex < 26) {
letterFile = new FileInputStream("textfonts/cap" + alphabet[letterIndex] + ".png");
} else {
letterFile = new FileInputStream("textfonts/" + alphabet[letterIndex] + ".png");
} // if - else character search
// loads texture
letterTex = TextureLoader.getTexture("PNG",letterFile);
} catch (FileNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} // try - catch FileNotFoundException
catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} //
} // if letter was found
else {
/******************************************************************
* if alphabet is not found, search for special characters
******************************************************************/
otherFound = false;
for (int c = 0; c < others.length; ++c) {
if (others[c] == letter) {
otherFound = true;
letterIndex = c;
letterThis = others[c];
letterWidth = 17+letterScale;
break;
} // if
} // for loop
if (otherFound) {
searchSpecialCharacters(others[letterIndex]);
} else {
// throws an exception if character is not in list
try {
throw new IllegalCharacterException(letter);
} catch (IllegalCharacterException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} // try - catch IllegalCharacterException
} // else IllegalCharacterException(char)
} // else if letter was not found
} // LetterList() constructor
/***********************************************************************************
*
* @param letter
* checks for characters that are not found in the alphabet array
*
**********************************************************************************/
private void searchSpecialCharacters(char letter) {
try {
switch (letter) {
/* goes through case statements to find special characters */
} // switch (letter)
// loads texture
letterTex = TextureLoader.getTexture("PNG",letterFile);
} catch (FileNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} // try - catch FileNotFoundException
catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} // try - catch IOException
} // searchSpecialCharacters(char)
public void drawLetter(int x, int y,int color, int fontScale) {
letterX = x;
letterY = y;
letterScale = fontScale;
setColor(color);
keepDrawingLetters(); // draws letter on creation
} // drawLetter()
// draws constantly in TextBoxRect after letter is created
public void keepDrawingLetters() {
GL11.glColor4f(red, green, blue, opacity);
// bind logo image to screen
letterTex.bind();
// draw quad screen
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0); // standard texture position
GL11.glVertex2f(letterX, letterY);
GL11.glTexCoord2f(1, 0); // standard texture position
GL11.glVertex2f(letterX+16+letterScale, letterY);
GL11.glTexCoord2f(1,1); // standard texture position
GL11.glVertex2f(letterX+16+letterScale, letterY+32+letterScale);
GL11.glTexCoord2f(0, 1); // standard texture position
GL11.glVertex2f(letterX, letterY + 32 + letterScale);
GL11.glEnd();
} // keepDrawingLetter()
private void initOpenGL() {
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 800, 0, 600, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
// enable texture mode in 2D
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
} // initOpenGL()
} // Letter class