Log in or register to post comments

Using 2d Images

July 18, 2012 - 7:45am #1


How can i import images in 2d, images like png o jpeg, i'm working on Image Target Sample and i would like to change de 3d image to 2d images but i didn't know how.

(Sorry for my english)

Thanks for your help.

Using 2d Images

October 25, 2012 - 3:08am #14

Please can you post up the XCode log to provide more information.



Using 2d Images

October 23, 2012 - 11:59pm #13

i use this code..but error in line 404 amp is not declare and error expected ; before ) refers to &projectionmatrix.data

Using 2d Images

October 12, 2012 - 3:34am #12

Please see my answer to your question in the iOS forums.

Please try to avoid double-posting - we will get to your questions as quickly as possible.


Using 2d Images

October 12, 2012 - 1:48am #11


i work image target sample. how can i change teapot to 2d image(any image). i develop for ios. thank you

Using 2d Images

July 26, 2012 - 2:35am #10


the ImageTargets app, on its own, out of the box, shows a teapot when the device is pointed at the chips or stones images

Using 2d Images

July 25, 2012 - 10:44pm #9

so this is only to show plane?not a teapot?

Using 2d Images

July 25, 2012 - 2:55am #8

This code is to replace the teapot with the plane - not to show both.

I posted up similar code here on iOS and the devs there were able to display a plane, which is what they wanted.



Using 2d Images

July 24, 2012 - 11:07pm #7

yes to show 2d plane image.i try to follow david instruction..but the tepot in plane not show

Using 2d Images

July 24, 2012 - 3:50am #6

try what?

teapot ? or plan 2D image?

If you are trying to show a 2D image check the dimensions of the texture, they need to be a power of two.

Non power of two textures OGL ES


Using 2d Images

July 23, 2012 - 10:38pm #5

i try it but the teapot not show

Using 2d Images

July 18, 2012 - 6:18pm #4

Yes but the picture will need to be rendered onto a plane that's defined in 3D space. You can use the instructions I'd posted to define the plane and render the texture to it.

Using 2d Images

July 18, 2012 - 1:56pm #3

Hi, thanks for your reply, i'm using the Android SDK i made de change on loadTextures() method and ImageTargets.cpp, im working on ImageTarget sample, what im trying to do is to display just a normal picture, without drawing any object, is this possible? can i show only a picture?



Using 2d Images

July 18, 2012 - 11:05am #2

Which SDK are you using?

The following instructions are for OpenGL 2 and Android, but can easily be adapted for iOS..

  1. Start with the ImageTargets sample project. Open ImageTargets.cpp, located in the jni folder.
  2. Add the following just after the includes at the top:

#include <QCAR/ImageTarget.h>

static const float planeVertices[] =
    -0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.5, 0.5, 0.0, -0.5, 0.5, 0.0,

static const float planeTexcoords[] =
    0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0

static const float planeNormals[] =
    0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0

static const unsigned short planeIndices[] =
    0, 1, 2, 0, 2, 3

Now replace the OpenGL ES 2.0 rendering code in the renderFrame method with the following:


// assuming this is an image target
QCAR::Vec2F targetSize = ((QCAR::ImageTarget *) trackable)->getSize();

QCAR::Matrix44F modelViewProjection;

SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale,
SampleUtils::scalePoseMatrix(targetSize.data[0], targetSize.data[1], 1.0f,
                            &modelViewMatrix.data[0] ,

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                      (const GLvoid*) &planeVertices[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                      (const GLvoid*) &planeNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                      (const GLvoid*) &planeTexcoords[0]);


glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                   (GLfloat*)&modelViewProjection.data[0] );
               (const GLvoid*) &planeIndices[0]);


Build the native code using ndk-build, then refresh the Eclipse project and run the app. You should see the teapot texture stretched over the image target.

You can swap the texture by adding your image to the project's assets folder (png or jpg format). Then open ImageTargets.java and look for the loadTextures() method. Replace the teapot texture filenames with your own. Note that the order the textures are added set the order they are stored in the native textures array (the first texture is at position 0).

Log in or register to post comments