Log in or register to post comments

Create/Replace Object

May 4, 2011 - 8:43am #1

I'm very new with AR and QCAR..i want displaying my own object instead of teapot..can you tell me how to do that??

i have created "tower" with autocad and 3ds..but i dont know how to import my object to replace "teapot" in Image Targets..

Re: Create/Replace Object

May 11, 2011 - 7:10am #18

thanks robertross. it must flip vertically. my texture had wrap my object perfectly..thank you very much..

Regards,

Gyan

Re: Create/Replace Object

May 11, 2011 - 3:12am #17

The texture may need to be flipped vertically or horizontally (i forget which way).

I just opened the image file in an image editor and flipped it and then used that.

or go here http://ar.qualcomm.at/node/2000458

Re: Create/Replace Object

May 11, 2011 - 12:17am #16

Hi,

I have the exact same problem..

I can not export an image(texture) that can be applied correctly to my model.. I assume that my mistake is that I do not create the texture appropriately..

My models already have a texture. I work in 3ds Max. I select Render to Texture and export the texture.

I convert my .3ds object with obj2opengl script. The object is rendered correctly but the texture not.

The question here is that is there a way or a procedure that we should follow to export the texture with any tool along with the obj in order to render correctly in the sdk?

It is a similar problem with the post above..

Thanks in advance,

Andreas

Re: Create/Replace Object

May 10, 2011 - 11:00pm #15

hei, kim i have another problem. i make a soccer ball in "3dmax", and export it into .obj with "blender"..then i try to "bake" this .obj into .png..but when i start imagetargets, my object have a wrong texture..

this is my texture.png:

this is the result when i start ImageTargets with my object an texture:

can you tell me what tools you use to get texture.png for "Teapot" object to get "TextureTeapotBlue.png" or "TextureTeapotBrass.png"??maybe i can use tools that you use to get the correct texture..

or maybe if you use "blender" too, would you like to tell me the correct way to "bake" my object..

Re: Create/Replace Object

May 9, 2011 - 6:56am #14

Take a look at the original sample code. There were blocks for rendering using OpenGL ES 1.1, and blocks for rendering with 2.0. The code is different in several key ways, for instance glUseProgram() is only available with OpenGL ES 2.0.

- Kim

Re: Create/Replace Object

May 8, 2011 - 9:56am #13

Finally my object and teapot object can be shown with different target in one application after i change the renderframe method :

int textureIndex = (!strcmp(trackable->getName(), "stones")) ? 0 : 1;
        //const Texture* const thisTexture = textures[textureIndex];
        if (strcmp(trackable->getName(), "stones") == 0)
        {
            // render your model
        	const Texture* const thisTexture = textures[textureIndex];
        QCAR::Matrix44F modelViewProjection;

        SampleUtils::translatePoseMatrix(0.0f, 0.0f, 100.f,
                                         &modelViewMatrix.data[0]);
        SampleUtils::scalePoseMatrix(100.f, 100.f, 100.f,
                                     &modelViewMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0] ,
                                    &modelViewProjection.data[0]);

        glUseProgram(shaderProgramID);

        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &bananaVerts[0]);
                glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &bananaNormals[0]);
                glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &bananaTexCoords[0]);

                glEnableVertexAttribArray(vertexHandle);
                glEnableVertexAttribArray(normalHandle);
                glEnableVertexAttribArray(textureCoordHandle);

                glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
                glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                                   (GLfloat*)&modelViewProjection.data[0] );
                glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);

        SampleUtils::checkGlError("ImageTargets renderFrame");


        }
        else if (strcmp(trackable->getName(), "chips") == 0)
        {
            // render the teapot
        	const Texture* const thisTexture = textures[textureIndex];

        QCAR::Matrix44F modelViewProjection;

        SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale,
                                         &modelViewMatrix.data[0]);
        SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                     &modelViewMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0] ,
                                    &modelViewProjection.data[0]);

        glUseProgram(shaderProgramID);

        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &teapotVertices[0]);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &teapotNormals[0]);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &teapotTexCoords[0]);

        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);

        SampleUtils::checkGlError("ImageTargets renderFrame");

        }

    }

i change opengl_es_1_1 value to false, because my application wont display the teapot with opengl1_1.

can you tell me why??

Re: Create/Replace Object

May 8, 2011 - 5:15am #12

You still need to pick a texture to bind. Add this line back in for both cases, replacing textureIndex with a valid texture id (0 or 1 for the original sample).

const Texture* const thisTexture = textures[textureIndex];

The textureIndex is defined by the order you add the textures in your Java code, see the loadTextures() method in ImageTargets.java.

- Kim

Re: Create/Replace Object

May 6, 2011 - 8:42pm #11

Ok, i set OPENGL_ES_1_1 to true. then i change the code in image targets :

int textureIndex = (!strcmp(trackable->getName(), "stones")) ? 0 : 1;
        const Texture* const thisTexture = textures[textureIndex];

to

if (strcmp(trackable->getName(), "stones") == 0)
{
    // render your model
glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(projectionMatrix.data);

        // Load model view matrix:
        glMatrixMode(GL_MODELVIEW);
        glLoadMatrixf(modelViewMatrix.data);
        glTranslatef(0.f, 0.f, kObjectScale);
        glScalef(kObjectScale, kObjectScale, kObjectScale);

        // Draw object:
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glVertexPointer(3, GL_FLOAT, 0, bananaVerts);
        glNormalPointer(GL_FLOAT, 0, bananaNormals);
        glTexCoordPointer(2, GL_FLOAT, 0, bananaTexCoords);
        glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);
}
else if (strcmp(trackable->getName(), "chips") == 0)
{
    // render the teapot
// Load projection matrix:
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(projectionMatrix.data);

        // Load model view matrix:
        glMatrixMode(GL_MODELVIEW);
        glLoadMatrixf(modelViewMatrix.data);
        glTranslatef(0.f, 0.f, kObjectScale);
        glScalef(kObjectScale, kObjectScale, kObjectScale);

        // Draw object:
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &teapotTexCoords[0]);
        glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &teapotVertices[0]);
        glNormalPointer(GL_FLOAT, 0,  (const GLvoid*) &teapotNormals[0]);
        glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                       (const GLvoid*) &teapotIndices[0]);

}

but i get the following error

E:/development/android/qcar-sdk-1-0-0/samples/imagetargets/jni/ImageTargets.cpp:
 In function 'void Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRender
er_renderFrame(JNIEnv*, _jobject*)':
E:/development/android/qcar-sdk-1-0-0/samples/imagetargets/jni/ImageTargets.cpp:
153: error: 'thisTexture' was not declared in this scope
E:/development/android/qcar-sdk-1-0-0/samples/imagetargets/jni/ImageTargets.cpp:
172: error: 'thisTexture' was not declared in this scope
make: *** [/cygdrive/e/development/android/qcar-sdk-1-0-0/samples/imagetargets/o
bj/local/armeabi/objs-debug/ImageTargets/ImageTargets.o] Error 1

Did i make mistake??

Re: Create/Replace Object

May 6, 2011 - 11:01am #10

You're going to need a basic understanding of OpenGL and the rendering code in the renderFrame method. If you are looking at ImageTargets.cpp, here are the variables that need to change for your model:

textureIndex
teapotVertices
teapotNormals
teapotTexCoords
teapotIndices
NUM_TEAPOT_OBJECT_INDEX

Note that you will not have the last two if you are using glDrawArrays instead of glDrawElements.

You can swap the data out according to the target that is visible, or simply copy the rendering code and make the few changes required:

if (strcmp(trackable->getName(), "stones") == 0)
{
    // render your model
}
else if (strcmp(trackable->getName(), "chips") == 0)
{
    // render the teapot
}

I might suggest picking OpenGL ES 1.1 or 2.0 and removing the extra code to make it easier to work with. OpenGL ES 2.0 is the default, but this can be changed by opening the Android.mk file and changing the USE_OPENGL_ES_1_1 flag to true.

- Kim

Re: Create/Replace Object

May 6, 2011 - 9:14am #9

oke i found this code :

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

i dont know what i must do with this code to make ImageTargets can detect different target with different object to render, for example : if my camera detect "chips" image, "teapot" will be shown. but if "stones" is detect, my object is shown..

Re: Create/Replace Object

May 6, 2011 - 5:33am #8

You can switch your content based on the target name in the cpp code. Take a look at ImageTargets.cpp. The renderFrame method is called each frame, and that code loops through all visible trackables for the frame. You can check the target name with trackable->getName() and render the appropriate content using its modelview matrix. The sample currently switches the texture based on the target name (using the same teapot model) but you can adapt it to switch the vertex/normal/texcoord/index arrays as well to draw a different model.

- Kim

Re: Create/Replace Object

May 5, 2011 - 8:50pm #7

i want to detect more than 2 target. and each target have their own object, how to do that??

Re: Create/Replace Object

May 5, 2011 - 4:48am #6

50 is a rough limit right now. You might be able to go a little higher than that, but you will eventually reach a ceiling past which extra targets cannot be tracked. The cap will be expanded in a later release.

You can however track as many frame markers as there are available (512).

- Kim

Re: Create/Replace Object

May 5, 2011 - 3:23am #5

i want to make Augmented Reality mobile application in android which can detect more than 50 marker/target, and i want using QCAR-SDK..are QCAR capable to do that??

Re: Create/Replace Object

May 5, 2011 - 1:41am #4

I'd suggest using a 3D Suite called Blender.
Look for tutorials on something called "baking" to get your texture png.

Re: Create/Replace Object

May 4, 2011 - 8:10pm #3

oh ok, so i can use "obj2opengl.pl"to create the .h file..next, how to render my object into .png ( ex : texture.png ), what modelling tools i must use??

Re: Create/Replace Object

May 4, 2011 - 6:20pm #2

Please see this thread for some ideas: http://ar.qualcomm.at/node/2000231

- Kim

Log in or register to post comments