2 package com.introlab.rtabmap;
4 import java.nio.ByteBuffer;
5 import java.nio.ByteOrder;
6 import java.nio.FloatBuffer;
7 import java.nio.ShortBuffer;
8 import java.util.Iterator;
9 import java.util.Vector;
11 import android.content.Context;
12 import android.graphics.Bitmap;
13 import android.graphics.Canvas;
14 import android.graphics.Color;
15 import android.graphics.Rect;
16 import android.graphics.Typeface;
17 import android.opengl.GLES20;
18 import android.opengl.GLUtils;
19 import android.text.TextPaint;
20 import android.util.Log;
31 "uniform mat4 uMVPMatrix;" +
32 "attribute vec4 vPosition;" +
33 "attribute vec2 a_texCoord;" +
34 "varying vec2 v_texCoord;" +
36 " gl_Position = uMVPMatrix * vPosition;" +
37 " v_texCoord = a_texCoord;" +
40 "precision mediump float;" +
41 "uniform float uColor;" +
42 "varying vec2 v_texCoord;" +
43 "uniform sampler2D s_texture;" +
45 " gl_FragColor = texture2D( s_texture, v_texCoord );" +
46 " gl_FragColor.rgb *= uColor;" +
80 float[] mCharacterWidth;
85 vecs =
new float[3 * 10];
86 uvs =
new float[2 * 10];
108 Canvas canvas =
new Canvas(bitmap);
109 bitmap.eraseColor(0);
112 TextPaint textPaint =
new TextPaint();
114 textPaint.setColor(
Color.WHITE);
115 textPaint.setAntiAlias(
true);
116 textPaint.setTypeface(Typeface.create(
"Arial", Typeface.BOLD));
122 Rect textBounds =
new Rect();
123 textPaint.getTextBounds(String.valueOf(
c), 0, 1, textBounds);
124 if(textBounds.height() + textBounds.bottom >
mTextHeight)
126 mTextHeight = textBounds.height() + textBounds.bottom;
138 Rect textBounds =
new Rect();
139 textPaint.getTextBounds(String.valueOf(
c), 0, 1, textBounds);
141 mCharacterWidth[
i] = textPaint.measureText(String.valueOf(
c));
145 GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,
mTextures[0]);
146 GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
147 GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
148 GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
163 int shader = GLES20.glCreateShader(
type);
166 GLES20.glShaderSource(shader, shaderCode);
167 GLES20.glCompileShader(shader);
183 for(
int i=0;
i<vec.length;
i++)
190 for(
int i=0;
i<uv.length;
i++)
197 for(
int j=0;
j<indi.length;
j++)
216 if(!(
txt.text==
null))
218 charcount +=
txt.text.length();
228 vecs =
new float[charcount * 12];
229 uvs =
new float[charcount * 8];
230 indices =
new short[charcount * 6];
240 for( Iterator< TextObject > it = txtcollection.iterator(); it.hasNext() ; )
245 if(!(
txt.text==
null))
257 GLES20.glDisable(GLES20.GL_DEPTH_TEST);
258 GLES20.glEnable(GLES20.GL_BLEND);
264 ByteBuffer bb = ByteBuffer.allocateDirect(
vecs.length * 4);
265 bb.order(ByteOrder.nativeOrder());
271 ByteBuffer bb2 = ByteBuffer.allocateDirect(
uvs.length * 4);
272 bb2.order(ByteOrder.nativeOrder());
278 ByteBuffer dlb = ByteBuffer.allocateDirect(
indices.length * 2);
279 dlb.order(ByteOrder.nativeOrder());
285 int mPositionHandle = GLES20.glGetAttribLocation(
sp_Text,
"vPosition");
288 GLES20.glEnableVertexAttribArray(mPositionHandle);
291 GLES20.glVertexAttribPointer(mPositionHandle, 3,
292 GLES20.GL_FLOAT,
false,
295 int mTexCoordLoc = GLES20.glGetAttribLocation(
sp_Text,
"a_texCoord" );
298 GLES20.glVertexAttribPointer ( mTexCoordLoc, 2, GLES20.GL_FLOAT,
302 GLES20.glEnableVertexAttribArray ( mPositionHandle );
303 GLES20.glEnableVertexAttribArray ( mTexCoordLoc );
306 int mtrxhandle = GLES20.glGetUniformLocation(
sp_Text,
"uMVPMatrix");
309 GLES20.glUniformMatrix4fv(mtrxhandle, 1,
false,
m, 0);
312 int colorhandle = GLES20.glGetUniformLocation(
sp_Text,
"uColor");
313 GLES20.glUniform1f(colorhandle,
mColor);
315 int mSamplerLoc = GLES20.glGetUniformLocation (
sp_Text,
"s_texture" );
318 GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
320 GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,
mTextures[0]);
322 GLES20.glUniform1i ( mSamplerLoc,
texturenr);
325 GLES20.glDrawElements(GLES20.GL_TRIANGLES,
indices.length, GLES20.GL_UNSIGNED_SHORT,
drawListBuffer);
328 GLES20.glDisableVertexAttribArray(mPositionHandle);
329 GLES20.glDisableVertexAttribArray(mTexCoordLoc);
340 Log.i(
"RTABMapActivity", String.format(
"convertTextToTriangleInfo() set status=%s",
text));
343 for(
int j=0;
j<
text.length();
j++)
351 if(indx<0 || indx>=mCharacterWidth.length) {
359 int row = indx / colCount;
360 int col = indx % colCount;
368 float[] vec =
new float[12];
369 float[] uv =
new float[8];
370 float[] colors =
new float[16];
401 short[] inds = {0, 1, 2, 0, 2, 3};