Log in or register to post comments

adding a home screen

February 6, 2012 - 1:41am #19

I'm building an AR app based on QCAR.
I want the app to work as follows.
First, it shows a home screen, which has a couple of menu buttons. One of them is, for example, "Start AR". When users click the button, camera starts and AR contents are displayed.

The sample applications like ImageTargets and VirtualButtons have only one activity, which does initialization stuff and shows a splashscreen image and then GLView.

I'm going to make a home screen as an main activity, and when menu button is pressed, AR related activity (like VirtualButtons) will be started. If so, it seems that delay time to do initialization is long because a lot of texture images are added for my app.

My question is.. Can I do initialization stuff before the home screen is displayed? If so, how?

or any idea to make such an app?

Re: adding a home screen

February 6, 2012 - 7:35pm #18

The problem is that OpenGL resources (e.g. textures, models) are bound to the context that is created and destroyed with the activity. See more here: http://stackoverflow.com/questions/2112768/prevent-onpause-from-trashing-opengl-context

One option might be to create a single-activity application that overlays views for the main menu, etc. rather than using separate activities.

- Kim

Re: adding a home screen

February 7, 2012 - 2:59am #17
ksiva wrote:

The problem is that OpenGL resources (e.g. textures, models) are bound to the context that is created and destroyed with the activity. See more here: http://stackoverflow.com/questions/2112768/prevent-onpause-from-trashing-opengl-context

One option might be to create a single-activity application that overlays views for the main menu, etc. rather than using separate activities.

- Kim

Thanks Kim.

I also thought about the option you mentioned. However, I faced the out-of-memory problem. The home screen activity loads several image resources for GUI. So, it seems that the consumed memory for the resources and texture images go beyond the available limits when I handled this with an activity. It might be due to my poor programming skill. anyway....

So, I'm thinking about an another way. It is to provide camera preview first and some toast message like "preparing AR tracking" before loading textures when I press the "start AR" button in the home screen. I think it doesn't annoy users because preview video is shown.

What do you think about it? Is it possible and a reasonable way?

Re: adding a home screen

February 7, 2012 - 8:52pm #16

It's certainly a reasonable way, but it might prove a bit tricky. The camera background image is rendered each frame by the renderFrame method, on the OpenGL thread. You'll want to create your textures on this thread as well, but you don't want to block the renderFrame call or the camera will stop updating on the screen. So one approach would be to load one texture per call to the renderFrame method until you've loaded them all.

You could try sharing the OpenGL context between multiple threads, I haven't tried this before but I believe it's possible. Then you could load your textures in a separate thread. Do a bit of web research on that one.

- Kim

Re: adding a home screen

February 7, 2012 - 8:55pm #15

As to your out-of-memory issue, make sure you are releasing any bitmaps using Bitmap.recycle(). This is a common mistake with Android GUIs.

- Kim

Re: adding a home screen

February 7, 2012 - 10:53pm #14
ksiva wrote:

It's certainly a reasonable way, but it might prove a bit tricky. The camera background image is rendered each frame by the renderFrame method, on the OpenGL thread. You'll want to create your textures on this thread as well, but you don't want to block the renderFrame call or the camera will stop updating on the screen. So one approach would be to load one texture per call to the renderFrame method until you've loaded them all.

You could try sharing the OpenGL context between multiple threads, I haven't tried this before but I believe it's possible. Then you could load your textures in a separate thread. Do a bit of web research on that one.

- Kim

Thanks. I'll try the approach to load one texture per call to the renderFrame.

Re: adding a home screen

February 7, 2012 - 11:00pm #13
ksiva wrote:

As to your out-of-memory issue, make sure you are releasing any bitmaps using Bitmap.recycle(). This is a common mistake with Android GUIs.

- Kim

Thanks.

I already read the post (probably your post) to recommend releasing bitmaps using bitmap.recycle(). so, I added 'bitmap.recycle();' in the loadTextureFromApk method (just before 'return texture;')

However, I'm not sure it's all enough to prevent the out-of-memory problem because the error occurs from time to time while I test the app.

could you give me any other advice?

Re: adding a home screen

February 8, 2012 - 4:54pm #12

Unfortunately I don't have any other tips, other than to release resources when you hide the menu.

I suggest trying to profile the memory usage of your app. You can get some data from the DDMS perspective in Eclipse. I'm sure there are other tools to help as well, do a general web search.

- Kim

Re: adding a home screen

February 28, 2012 - 5:02am #11
ksiva wrote:

It's certainly a reasonable way, but it might prove a bit tricky. The camera background image is rendered each frame by the renderFrame method, on the OpenGL thread. You'll want to create your textures on this thread as well, but you don't want to block the renderFrame call or the camera will stop updating on the screen. So one approach would be to load one texture per call to the renderFrame method until you've loaded them all.

You could try sharing the OpenGL context between multiple threads, I haven't tried this before but I believe it's possible. Then you could load your textures in a separate thread. Do a bit of web research on that one.

- Kim

Hi Kim.

Following your comment, I've changed the code to load one texture per call to the renderFrame method. This works well with my test device, HTC nexus one.

Now I'm testing my app with other test devices. Unfortunately, I've found strange cases with some devices with 720x1280 px, Samsung Galaxy S2 HD LTE and LG Optimus 4G LTE.

After I start the AR activity from the home screen activity, the camera background image is rendered while textures are loading as expected. However, after loading textures is completed, the camera background image isn't rendered anymore, the screen becomes black, only AR objects are rendered.

Do you have any idea to resolve this problem?

Re: adding a home screen

February 28, 2012 - 6:49pm #10

Hmm, that's strange, are there any errors in the log?

You may want to try using only power-of-two sized textures, if you aren't already.

It's strange that the camera image only stops rendering once you've loaded all the textures. Is that the point at which you start rendering with those textures? Are you changing the texture stage (glActiveTexture)?

Try isolating the point at which you lose the video background. Check if you lose the background if you turn off all rendering and only load the textures.

- Kim

Re: adding a home screen

February 28, 2012 - 7:44pm #9

There are no errors. Texture rendering is fine.
I didn't make any change to the rendering part of codes, which work well with Nexus One.

Also, there isn't such a problem with other test devices, for example, Samsung Galaxy S, Galaxy S2 LTE (480x800 px), Motorola RAZR XT910S (540x960 px), Pantech Vega LTE (800x1280 px).

Is there possibility of screen resolution to cause such a problem? Two devices are 720x1280 px.

I'll try to find potential bugs anyway.

Re: adding a home screen

February 28, 2012 - 10:30pm #8

It doesn't seem that the screen resolution is related to the problem.

I just found another case with Pantech Vega Racer (IM-A760S) (480x800 px).
It also shows black background and only AR objects are rendered.

Re: adding a home screen

February 29, 2012 - 2:00pm #7

If you send your project to

I could take a look. Use a file sharing service, you can use this one if you don't have access to another: http://me2u.qualcomm.com

As a thought, what happens if you just load a few textures using this approach, do you also lose the camera? Maybe you're maxing out the texture memory... Also, don't load any textures bigger than 1024x1024.

- Kim

Re: adding a home screen

March 8, 2012 - 1:07am #6

Hi Kim.

I found the cause of the problem. It is due to the opengl function, glBlendFunc().

My app renders 2-D AR objects with texture images that have transparent part. So I use that function. I'm a novice at opengl programming. so I applied parameters for the function after googling some related web pages.

My previous code was as follows.

// Render video background:
QCAR::State state = QCAR::Renderer::getInstance().begin();
QCAR::Renderer::getInstance().drawVideoBackground();

// to enable transparent area
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);

// texture rendering codes follow....

I changed two parameters for the glBlendFunc like followings.
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

then I don't see the problem. I still don't understand why some devices have problems while others don't.

Is that a correct way to render texture images with some transparent part?

Since I just tested a couple of devices, I have to do more tests with other devices.

Re: adding a home screen

March 8, 2012 - 10:57pm #5

I think it depends on how the alpha value is represented, and whether it is pre-multiplied or not... I would do a bit more research on that one.

- Kim

Re: adding a home screen

March 9, 2012 - 1:08am #4

I have tested with a range of devices including ones that previously had the problem and others that didn't have the problem. With glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA), video background was rendered well with AR objects.

But I found some strange cases. A couple of particular AR objects got black once in a while. When I restarted, they were rendered well.
Although I don't understand why and when such a condition occurs, I'm trying to resolve it.

Re: adding a home screen

March 13, 2012 - 9:13pm #3

Hi, Kim

I have another issue related to the opengl blending function, glBlendFunc().
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) seems not be a perfect solution.

I have translucent 2d image texture (texture.png). The translucent part of the image is rendered with white color (demo.png), while it is fine with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).

Could you give me any advice for this issue?

Re: adding a home screen

March 14, 2012 - 8:07pm #2

Unfortunately I don't have too much experience with different blending modes. I've almost always used glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). Perhaps you should figure out why your other images weren't working with that setting?

- Kim

Re: adding a home screen

March 15, 2012 - 12:57am #1

Thanks Kim.

I think that glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) is the right choice if there is no issue of black video background in some devices. Hmm.. I'm not quite sure how I can resolve this issue.

Log in or register to post comments