Log in or register to post comments

displaying user-input text

September 14, 2011 - 12:53am #1

Hi.
I'm building an AR application based on QCAR sdk, which displays user-input texts such as sentences like "Happy Birthday My Dear Friend" over a certain trackable object. A user runs the application, and inputs his/her message. Then, when the user views a trackable object via app's camera view, the message shows up over the object.

I'm new to mobile AR application and OpenGL stuff.
I'll appreciate any advise or help. Thanks in advance.

Re: displaying user-input text

October 27, 2011 - 3:31am #4

Is there already a solution for this?

Re: displaying user-input text

September 21, 2011 - 3:09am #3

To render the text, I've added the code in "onDrawFrame" method of ImageTargetsRenderer as follows. (the code from the link, http://stackoverflow.com/questions/1339136/draw-text-in-opengl-es-android)

public void onDrawFrame(GL10 gl)
{
if (!mIsActive)
return;

// Call our native function to render content
renderFrame();

// Create an empty, mutable bitmap
Bitmap bitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_4444);
bitmap.eraseColor(Color.TRANSPARENT);
// get a canvas to paint over the bitmap
Canvas canvas = new Canvas(bitmap);

// get a background image from resources
// note the image format must match the bitmap format
Drawable background = context.getResources().getDrawable(R.drawable.background);
background.setBounds(0, 0, 256, 256);
background.draw(canvas); // draw the background to our bitmap

// Draw the text
Paint textPaint = new Paint();
textPaint.setTextSize(32);
textPaint.setFakeBoldText(true);
textPaint.setAntiAlias(true);
textPaint.setARGB(0xff, 0x00, 0x00, 0x00);
// draw the text centered
canvas.drawText("Hello World", 16,112, textPaint);

int[] textures = new int[1];

//Generate one texture pointer...
gl.glDeleteTextures(1,textures, 0);
gl.glGenTextures(1, textures, 0);
//...and bind it to our array
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

//Create Nearest Filtered Texture
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

//Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);

//Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

//Clean up
bitmap.recycle();
}

However, I don't see the text, "Hello World" at all. Any help plz.

Re: displaying user-input text

September 14, 2011 - 9:39pm #2

If you want to render the text in 3D you'll need to use OpenGL. The OpenGL API doesn't include any direct methods for rendering text, however. If you want to render dynamically created text (as opposed to prebaked images) you'll want to find an OpenGL ES compatible text rendering library, or some source code to get you started.

http://stackoverflow.com/questions/1339136/draw-text-in-opengl-es-android

- Kim

Log in or register to post comments