Any help would be appreciated
The image i'm using for the glyphs is a 16x16 grid of all ascii characters so the ascii code is used to index the texture map.

Using java Syntax Highlighting
- public class TextRenderer
- {
- private GL10 gl;
- private int[] tex;
- private float width;
- private float height;
- private FloatBuffer vertexBuffer;
- private FloatBuffer texBuffer;
- private ByteBuffer indexBuffer;
- public TextRenderer(GL10 _gl, Context ctx)
- {
- float[] texcoords;
- float quad[] =
- {
- 0.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- 1.0f, 0.0f, 0.0f,
- 1.0f, 1.0f, 0.0f
- };
- byte indices[] =
- {
- 0, 1, 2, 3
- };
- gl = _gl;
- tex = new int[1];
- gl.glGenTextures(1, tex, 0);
- Bitmap bmp = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.berlin);
- gl.glBindTexture(GL10.GL_TEXTURE_2D, tex[0]);
- GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
- bmp.recycle();
- texcoords = new float[16*16*4*2];//16 by 16 tiles by 4 vertices per quad by 2 coords per vertex
- for(int y = 0; y < 16; y++)
- {
- for(int x = 0; x < 16; x++)
- {
- texcoords[(x*8)+(y*16*8)] = (float)x / 16.0f;
- texcoords[(x*8)+(y*16*8)+1] = (float)y / 16.0f;
- texcoords[(x*8)+(y*16*8)+2] = (float)x / 16.0f;
- texcoords[(x*8)+(y*16*8)+3] = ((float)y + 1.0f) / 16.0f;
- texcoords[(x*8)+(y*16*8)+4] = ((float)x + 1.0f) / 16.0f;
- texcoords[(x*8)+(y*16*8)+5] = (float)y / 16.0f;
- texcoords[(x*8)+(y*16*8)+6] = ((float)x + 1.0f) / 16.0f;
- texcoords[(x*8)+(y*16*8)+7] = ((float)y + 1.0f) / 16.0f;
- }
- }
- ByteBuffer vbb = ByteBuffer.allocateDirect(quad.length*4);
- vbb.order(ByteOrder.nativeOrder());
- vertexBuffer = vbb.asFloatBuffer();
- vertexBuffer.put(quad);
- vertexBuffer.position(0);
- vbb = ByteBuffer.allocateDirect(texcoords.length * 4);
- vbb.order(ByteOrder.nativeOrder());
- texBuffer = vbb.asFloatBuffer();
- texBuffer.put(texcoords);
- texBuffer.position(0);
- indexBuffer = ByteBuffer.allocateDirect(indices.length);
- indexBuffer.put(indices);
- indexBuffer.position(0);
- }
- public void drawText(float x, float y, String text)
- {
- gl.glEnable(gl.GL_TEXTURE_2D);
- gl.glMatrixMode(gl.GL_PROJECTION);
- gl.glPushMatrix();
- gl.glLoadIdentity();
- gl.glOrthof(0.0f, 1.0f, 0.0f, 1.0f, 0.1f, 10.0f);
- gl.glMatrixMode(gl.GL_MODELVIEW);
- gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
- gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
- gl.glVertexPointer(4, gl.GL_FLOAT, 0, vertexBuffer);
- gl.glBindTexture(GL10.GL_TEXTURE_2D, tex[0]);
- gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- float drawx = x;
- float drawy = y;
- for(int i = 0; i < text.length(); i++)
- {
- int ascii = text.codePointAt(i);
- texBuffer.position(ascii*2*4);
- gl.glTexCoordPointer(2, gl.GL_FLOAT, 0, texBuffer);
- gl.glTranslatef(drawx, drawy, 1.0f);
- gl.glDrawElements(gl.GL_TRIANGLE_STRIP, 4, gl.GL_UNSIGNED_BYTE, indexBuffer);
- drawx++;
- }
- gl.glDisable(gl.GL_TEXTURE_2D);
- gl.glMatrixMode(gl.GL_PROJECTION);
- gl.glPopMatrix();
- gl.glMatrixMode(gl.GL_MODELVIEW);
- }
- public void resize(float w, float h)
- {
- width = w;
- height = h;
- }
- }
Parsed in 0.044 seconds, using GeSHi 1.0.8.4


