Log in or register to post comments

2 different Image Targets and 2 Objects

May 24, 2013 - 5:53am #18

Hi, I tried to make multi image targets. For example: image target  "stones" can show oject "A" and image target "chips" can show object "B".
I did it. but then I realize there is something happened, which is the second object is looks like a strange shape . . .

here is the screen shoot image targets "chips":
http://foxcun.com/img/obj1.png

the second object "stones" screen shoot:
http://foxcun.com/img/obj2.png

then i try to make it simultaneously:

http://foxcun.com/img/obj3.png

it still the same, the second object in "stones" looks wired ...
When I use single object , the shape looks normaly, but when I used 2 different object, the second object will looks wired. 

here is my code:



// Did we find any trackables this frame?
    for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
    {
        // Get the trackable:
        const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);
        const QCAR::Trackable& trackable = result->getTrackable();
        QCAR::Matrix44F modelViewMatrix =
            QCAR::Tool::convertPose2GLMatrix(result->getPose());        

        // Choose the texture based on the target name:
        int textureIndex;
        if (strcmp(trackable.getName(), "chips") == 0)
        {
                 //first object
        	 textureIndex = 0;
        	 glVertexAttribPointer(vertexHandle,3, GL_FLOAT, GL_FALSE, 0, foxboxOBJVerts);
        	 glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, foxboxOBJTexCoords);
        }
        else if (strcmp(trackable.getName(), "stones") == 0)
        {
                 //second object
                 textureIndex = 1;
                 glVertexAttribPointer(vertexHandle,3, GL_FLOAT, GL_FALSE, 0, foxtriVerts);
                 glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, foxtriTexCoords);
        }
        else
        {
            textureIndex = 2;
        }

        const Texture* const thisTexture = textures[textureIndex];

..........................
..........................

 

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

 

        glDrawArrays(GL_TRIANGLES, 0, foxtriNumVerts);

 

        glDrawArrays(GL_TRIANGLES, 0, foxboxOBJNumVerts);
 
        SampleUtils::checkGlError("ImageTargets renderFrame");

here is the full code:
http://foxcun.com/zipfile/ImageTargets.zip
Hoping anyone could help  .. 
 

2 different Image Targets and 2 Objects

May 24, 2013 - 10:04am #17

Hi, 

your OpenGL code is incorrect;

the main problem is this:

 

 glDrawArrays(GL_TRIANGLES, 0, foxtriNumVerts);

        glDrawArrays(GL_TRIANGLES, 0, foxboxOBJNumVerts);

 
This is not the right way of using glDrawArrays (using it twice consecutivley)
what you need to do is to do something like:
 
if (textureIndex == 0)
 glDrawArrays(GL_TRIANGLES, 0, foxboxOBJNumVerts);
 
else if (textureIndex == 1)
 glDrawArrays(GL_TRIANGLES, 0, foxtriNumVerts);
 
 

2 different Image Targets and 2 Objects

May 24, 2013 - 6:32pm #16

Awesome . . . . 
Thank You AlessandroB
 

2 different Image Targets and 2 Objects

June 3, 2013 - 12:38am #15

its SDK 2.0??
hei how to add different object in different image target....could you explain step by step??

thx 

2 different Image Targets and 2 Objects

June 3, 2013 - 1:25am #14

keju_coklat_susu wrote:

its SDK 2.0??
hei how to add different object in different image target....could you explain step by step??

thx 

Gan . . just use my code below n paste to image target sample n dont forget to remove all the glNormal in your object . . .
tell me if there is anythng that goes wrong ...
 

2 different Image Targets and 2 Objects

June 3, 2013 - 9:14am #13

foxcun wrote:

keju_coklat_susu wrote:

its SDK 2.0??
hei how to add different object in different image target....could you explain step by step??

thx 

Gan . . just use my code below n paste to image target sample n dont forget to remove all the glNormal in your object . . .
tell me if there is anythng that goes wrong ...
 

 

Yeah thx gan..solved :D

2 different Image Targets and 2 Objects

June 3, 2013 - 9:37am #12

When using my own data set...my model look collision
Image:attach file

AttachmentSize
Image icon Screenshot_2013-06-03-23-31-41.png639.39 KB

2 different Image Targets and 2 Objects

June 3, 2013 - 10:05am #11

The models should appearjust on top of the targets... maybe you are rendering two different models for the same target;

my suggestion is to double-check your OpenGL code in the renderFrame() method of your CPP code, there is probably something wrong there..

 

2 different Image Targets and 2 Objects

June 5, 2013 - 9:01am #10

-----EDIT-----
Ah...its all about marker

2 different Image Targets and 2 Objects

February 2, 2014 - 11:31pm #9

Hi,

I've following all the code

But i still got this :

Any one help me pls.
Thank you

2 different Image Targets and 2 Objects

February 3, 2014 - 1:11am #8

Hi Perucha,

it looks like there is so;ething wrong in your OpenGL code that causes that crash;

for example, you might have some issues with the size of your vertex arrays, or any other data/rendering mismatch;

but you really need to debug / check your code, we cannot help with OpenGL custom rendering issues

 

2 different Image Targets and 2 Objects

February 5, 2014 - 3:14am #7

Hi,

Here is my problem, .java code :

    /** We want to load specific textures from the APK, which we will later
    use for rendering. */
    private void loadTextures()
    {
        mTextures.add(Texture.loadTextureFromApk("TextureBajuPertama.png",
                getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureBajuBlue.png",
                getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureBajuBrass.png",
                getAssets()));
        mTextures.add(Texture.loadTextureFromApk("TextureBajuRed.png",
                getAssets()));
        //mTextures.add(Texture.loadTextureFromApk("TextureBajuKedua.png",
                //getAssets()));
    }

When i use that code, i can running my project, but the second object showed without texture

So i Uncomment the TextureBajuKedua, but it becomes an error, "fatal error"

Here code in .cpp :

// Did we find any trackables this frame?
    for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
    {
        // Get the trackable:
        const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);
        const QCAR::Trackable& trackable = result->getTrackable();
        QCAR::Matrix44F modelViewMatrix =
            QCAR::Tool::convertPose2GLMatrix(result->getPose());        

        // Choose the texture based on the target name:
        int textureIndex;
        if (strcmp(trackable.getName(), "chips") == 0)
        {
            textureIndex = 0;
            glVertexAttribPointer(vertexHandle,3, GL_FLOAT, GL_FALSE, 0, bajuPertamaVerts);
            glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, bajuPertamaTexCoords);
        }
        else if (strcmp(trackable.getName(), "stones") == 0)
        {
            textureIndex = 1;
            glVertexAttribPointer(vertexHandle,3, GL_FLOAT, GL_FALSE, 0, bajuKeduaVerts);
            glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, bajuKeduaTexCoords);
        }
        else
        {
            textureIndex =2;
        }

Thanks  you

2 different Image Targets and 2 Objects

February 5, 2014 - 3:38am #6

In your code you seem to miss this line:

 glDrawArrays(GL_TRIANGLES, 0, Your_Mesh_NumVerts);

Also, note that the 'Your_Mesh_NumVerts" will have to be adjusted based on which specific mesh (banana or others) you are using (i.e. based on the texture index, in pratice).
 
For instance, you should have some code like:
 
if (textureIndex == 0)
 glDrawArrays(GL_TRIANGLES, 0, bajuPertamaJNumVerts);
 
else if (textureIndex == 1)
 glDrawArrays(GL_TRIANGLES, 0, bajuKeduaNumVerts);
 
 

2 different Image Targets and 2 Objects

February 5, 2014 - 7:00am #5

Hi,

I do, here :

But still error

Thank you

2 different Image Targets and 2 Objects

February 5, 2014 - 7:37am #4

OK. So, from the code below, everything seems to be correct on the OpenGL level, or at least I cannot see anyting obviously wrong.

So, my guess is that there could be something wrong with the definitions of those vertex arrays (check their header files .h), or perhaps the arrays are toolarge (for instance, if the number of vertices exceeds 64K you might have problems on some devices).

Have you tried the same code using a different set of meshes ?

 

2 different Image Targets and 2 Objects

February 5, 2014 - 10:51am #3

Hi,

Each object only have around 10k number of vertices

Which makes me confuse is why when i replace the texture, its becames erros

I've following all the code below

Please take a look from my full code, i think i missing something that i can't find it

Thank you very much

AttachmentSize
Plain text icon code_in_cpp.txt25.45 KB
Plain text icon code_in_java.txt34.49 KB

2 different Image Targets and 2 Objects

February 6, 2014 - 5:12am #2

Sorry, but I cannot debug your entire application code for you; at a first glance the code looks correct, but given that, as you said, the probem arises when you change the textures to use your own images, you may want to check the following things:

- check the value of textureCount, and ensure that it is actually 3 or more (as you load many textures in the Java code); this is important because otherwise the textureIndex in your C++ code might exceed the texturecount

- check that all textures in C++ are created sccessfully, without any error logged by the application

- check the size of your textures; it could be that the code is correct, but the images are too large, thus causing the crash

- check that the textures dimensions are power-of-two (e.g. 256 x 256 or 256 x 128, or 512 x 256, etc...), as your device OpenGL driver might not like non-power-of-two textures

 

2 different Image Targets and 2 Objects

February 12, 2014 - 1:26am #1

Hi,

I've found the error, thank you so much AlessandroB

It's about the dimensions of my texture ..

But i've question, i've try to resize my object like this : (left scale 100.0f and right scale 200.0f)