Log in or register to post comments

Projecting an Android view onto a target

May 16, 2013 - 11:43am #1

I am trying to create an AR experience where the user can dynamically create a target (like in UserDefinedTargets). I then want to replace the teapot model with a regular two dimensional Android View (animated). I found a thread saying that the CloudRecognition app projects a bitmap (guessing the book info) that's drawn into by a canvas onto the target. This is what I would like to do, but I don't need cloud capability and I would like to integrate the user-defined-target capability with projecting a bitmap that can be updated to simulate animation. 

Can someone guide me into which parts of the code I need to look at, and/or other threads to look at? Thanks!

Projecting an Android view onto a target

May 25, 2013 - 10:08am #7

After fiddling around, I got exactly what I wanted using the tips you have provided. Thanks!

Projecting an Android view onto a target

May 21, 2013 - 1:21am #6

Hi, the right place where you can call glTexSubImage2D() is in the renderFrame() function; the reason is that there you will be sure to execute OpenGL code in the OpenGL rendering thread.

Normally you should:

- first bind the texture you want to update (see glBindTexture() function, as shown for instance in ImageTargets.cpp)

- then you call glTexSubImage2D() right after the glBindTexture() function call.

If you search the internet you can find plenty of tutorials and examples about how to use glTexSubImage2D (it's a very commonly used function).

For how to pass the bitmap from Java to C++, you can define a native method in Java, which takes three parameters as input (int width, int height, and byte[] pixels);

then you can implement it in native code (C++), similarly to any other native functions (our examples show many of these functions);




Projecting an Android view onto a target

May 20, 2013 - 3:26pm #5

I have successfully replaced the teapot in the UsereDefinedTargets with a 2d texture where I pass in a bitmap, but I am very new to OpenGl. Is there an example I can look at that impements glTexSubImage2D? Where and how would I pass in the updated bitmap data from java to cpp? And where should I call glTexSubImage2D?

Projecting an Android view onto a target

May 17, 2013 - 12:08am #4

Hi, there is no funtion in the SDK to manipulate the textures; the code in the sample just relies on plain OpenGL;

typically, if you want to dynamically update the content of a texture (e.g. at every rendering frame), you can use an OpenGL function called:


So, basically the idea is to pass your updated pixel buffer (byte array) from Java to C++ and call glTexSubImage2D to update the content of the texture in the graphics memory;

the use of glTexSubImage2D avoids that you need to re-create an OpenGL texture each time (so the texture is always the same, but the content is updated), and that's the only way of updating efficiently a texture in OpenGL.

Note: performance-wise this function is the fastest possible approach, however it can still be expensive if the size if the texture is very large, but this will vary from device to device. 

I hope this helps.

Projecting an Android view onto a target

May 16, 2013 - 1:35pm #3

What is the best way to make a 2d image non-static (ie. bitmap is being changed from a view class)? Would I just reload the texture or is there a function that tells the sdk to update it automatically? 

Projecting an Android view onto a target

May 16, 2013 - 1:10pm #2

Hi, you can check the CloudReco sample, in particular look at the mBookDataTexture variable (and all its occurrences) in CloudReco.java;

in particular, check the code in the GetBookDataTask class (see doInBackground() method, where the product texture is built, based on the book data view);

then, in C++, look at the CloudReco.cpp, in particular:


I cannot drive you through all the code, but if you start from the elements above, you can find the relationship between the various code blocks and variables.

I hope this helps.


Log in or register to post comments