001 /*
002 *
003 * Created: Jun 7 2006
004 *
005 * Copyright (C) 1999-2000 Fabien Sanglard
006 *
007 * This program is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU General Public License
009 * as published by the Free Software Foundation; either version 2
010 * of the License, or (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with this program; if not, write to the Free Software
019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020 */
021
022 package rtype.entity;
023
024 import org.lwjgl.opengl.GL11;
025
026 import rtype.Prototyp;
027
028 public class Text extends AnimatedEntity
029 {
030 private String string = null;
031 public void setString(String string)
032 {
033 this.string = string;
034 chars = this.string.toCharArray();
035 }
036
037 public static final int LEFT_TO_RIGHT = 0;
038 public static final int RIGHT_TO_LEFT = 1;
039 private int mode = LEFT_TO_RIGHT;
040 public void setMode(int mode)
041 {
042 this.mode = mode;
043 }
044
045 private char[] chars ;
046 public Text(String string)
047 {
048 this.setString(string);
049
050 this.type = FONT;
051 init();
052 setRatio(0.4f);
053 }
054
055 public void draw()
056 {
057 GL11.glLoadIdentity();
058 GL11.glTranslatef(position.x,position.y,Prototyp.DEFAULT_Z); // Translate Into/Out Of The Screen By z
059 GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE);
060
061 if (mode == LEFT_TO_RIGHT)
062 {
063 for (int i=0;i<chars.length;i++)
064 {
065 drawChar(i);
066 GL11.glTranslatef(this.width+1,0,0);
067 }
068 }
069 if (mode == RIGHT_TO_LEFT)
070 {
071 for (int i=chars.length-1; i>=0;i--)
072 {
073 drawChar(i);
074 GL11.glTranslatef(-this.width+1,0,0);
075 }
076 }
077
078 }
079
080 public void update()
081 {
082
083 }
084
085 private void drawChar(int i)
086 {
087
088 GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.animationTextures[chars[i]].getTextureId() );
089 GL11.glBegin(GL11.GL_QUADS);
090 {
091 GL11.glTexCoord2f(textureRight,textureUp); //Upper right
092 GL11.glVertex2f(width, -height);
093
094 GL11.glTexCoord2f(textureLeft,textureUp); //Upper left
095 GL11.glVertex2f(-width, -height);
096
097 GL11.glTexCoord2f(textureLeft,textureDown); //Lower left
098 GL11.glVertex2f(-width,height);
099
100 GL11.glTexCoord2f(textureRight,textureDown); // Lower right
101 GL11.glVertex2f(width,height);
102
103 }
104 GL11.glEnd();
105 }
106
107 }
|