Log in or register to post comments

Is it possible to load textures from local image files?

December 23, 2010 - 5:37pm #1

Is it possible to load textures from images in the phone? Texture class only provide loadTextureFromApk() method to load texture .

Re: Is it possible to load textures from local image files?

December 24, 2010 - 6:39pm #8

This code is not in onCreate method. I call onDestroy aim to stop running tasks and release original texture. I loaded two textures. I only switch TextureTeapotBlue and TextureTeapotBrass for a test.

I just want to know how to update opengl texture after reloading texture image. I've tried in many ways , such as calling initApplicationNative method and initRendering method , but not success. Running task not stop or get crashes always happen.

Re: Is it possible to load textures from local image files?

December 24, 2010 - 6:06am #7

Is this code in the ImageTargets.java onCreate method? Why are you calling onDestroy here? That could certainly be causing problems.

Also, the ImageTargets sample is expecting two textures, so if you are only loading one you will get a crash when one of the two targets comes into view. You can change this line in ImageTargets.cpp to fix this issue:

int textureIndex = (!strcmp(trackable->getName(), "stones")) ? 0 : 1;

- Kim

Re: Is it possible to load textures from local image files?

December 24, 2010 - 5:38am #6

after reloading texture to mTextures defined in Imagetargets ,I call updateApplicationStatus(APPSTATUS_INIT_APP) to create opengl textures.Then,the App exit if it detect any trackable.
here's my code:
onDestroy();
mTextures.clear();
loadTextures();
mQCARFlags = getInitializationFlags();
updateApplicationStatus(APPSTATUS_INIT_APP);

Why?

Re: Is it possible to load textures from local image files?

December 23, 2010 - 7:25pm #5

thanks for the quick reply ^_^

Re: Is it possible to load textures from local image files?

December 23, 2010 - 6:33pm #4

You use the JNI (Java Native Interface). See the initApplicationNative method for an example. The method is defined in ImageTargets.cpp (in SDK beta 2) and called in ImageTargets.java.

To pass a pixel array, you can use a jbyteArray, jshortArray, or jintArray, depending on the data type. Use the GetByteArrayElements method to get a native pointer to the data. See the Texture.cpp create method for an example.

- Kim

Re: Is it possible to load textures from local image files?

December 23, 2010 - 6:13pm #3

how to pass the pixel array and size from Java to native?

Re: Is it possible to load textures from local image files?

December 23, 2010 - 5:49pm #2

This isn't built into the SDK, loadTextureFromApk is just a convenience method used in the samples. What is the source of the image you want to use as a texture? If you can get a bitmap for the image, it should be pretty easy to create your own OpenGL texture by passing the pixel array and size from Java to native. See the Texture.cpp class and the initRendering method in ImageTargets.cpp for some sample code.

- Kim

Log in or register to post comments