Log in or register to post comments

Trying to render 2 models on 1 image target

June 20, 2012 - 4:38am #1

I'm trying to render two chess pieces using as base source code, the one from the ImageTragets sample. I've managed to render a single piece but when I try to render the second one, it doesn't show.

I don't use a fresh modelViewMatrix with the second piece, cause I never overwrite the contents of the original.

As you can see, for the transformations, I begin with and identityMatrix to which I apply rotations, translations... etc then I multiply the transformation matrix and the modelViewMatrix and store the results in another matrix called objectMatrix and continue from there to obtain a modelViewProjectionMatrix which I send to the shader. This process is repeted for the second piece but with different translation with no results.

what am I missing?
Thanks in advance

I think the piece of code that's important is this:

        static const float kObjectScale = 30.f;

        // set shader
        glUseProgram(shaderProgramID);

        // enable attributes
        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);

        // set texture
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);

// PAWN 1

        // specify piece data
        unsigned int chosenPiece = PAWN;
        unsigned int firstVertex = vertex_offset_table[chosenPiece];
        unsigned int firstIndex = indices_offset_table[chosenPiece];

        // set attributes
        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, sizeof(vertex_struct), (const GLfloat*) &vertices[firstVertex].x);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, sizeof(vertex_struct), (const GLfloat*) &vertices[firstVertex].nx);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_struct), (const GLfloat*) &vertices[firstVertex].u);

        // transformations
        QCAR::Matrix44F transformMatrix = SampleMath::Matrix44FIdentity();
        SampleUtils::rotatePoseMatrix(90.0f, 1.0f, 0.0f, 0.0f, &transformMatrix.data[0]); // rotation
        SampleUtils::translatePoseMatrix(0.0f, 0.0f, 0.0f, &transformMatrix.data[0]); // translation
        SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &transformMatrix.data[0]); // scale

        // apply transformations to object
        QCAR::Matrix44F modelViewProjection, objectMatrix;
        SampleUtils::multiplyMatrix(&modelViewMatrix.data[0], &transformMatrix.data[0], &objectMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &objectMatrix.data[0], &modelViewProjection.data[0]);


        // draw piece
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjection.data[0] );
        glDrawElements(GL_TRIANGLES, (faces_count [chosenPiece] * 3), GL_UNSIGNED_SHORT,(const GLvoid*) &indexes[firstIndex]);

// PAWN 2

        // transformations
        transformMatrix = SampleMath::Matrix44FIdentity();
        SampleUtils::rotatePoseMatrix(90.0f, 1.0f, 0.0f, 0.0f, &transformMatrix.data[0]); // rotation
        SampleUtils::translatePoseMatrix(100.0f, 0.0f, 0.0f, &transformMatrix.data[0]); // translation
        SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &transformMatrix.data[0]); // scale


        // apply transformations to object
        // QCAR::Matrix44F modelViewProjection, objectMatrix;
        SampleUtils::multiplyMatrix(&modelViewMatrix.data[0], &transformMatrix.data[0], &objectMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &objectMatrix.data[0], &modelViewProjection.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0] , &modelViewProjection.data[0]);

        // draw piece
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjection.data[0] );
        glDrawElements(GL_TRIANGLES, (faces_count [chosenPiece] * 3), GL_UNSIGNED_SHORT,(const GLvoid*) &indexes[firstIndex]);

Trying to render 2 models on 1 image target

October 5, 2013 - 10:37pm #8

I fix the problem with a little patient, just the matter of OpenGL problem..
and 1 more help needed, on this link : https://developer.vuforia.com/forum/android/video-and-3d-model
Please

thanks

 

regards

Trying to render 2 models on 1 image target

October 5, 2013 - 7:33am #7

Hi all, i made 2 object showed in camera with this methode :

1. Draw object in _ImageTargetRenderer_RenderFrame

//draw 1st object
         glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
         glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &buku6TexCoords[0]);
         glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &buku6Verts[0]);
         glDrawArrays(GL_TRIANGLES, 0, buku6NumVerts);

//draw 2nd object
         glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
         glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &BookTexCoords[0]);
         glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &BookVerts[0]);
         glDrawArrays(GL_TRIANGLES, 0, BookNumVerts);

2. initiated object

// 1st object

QCAR::Matrix44F modelViewProjection;
        SampleUtils::translatePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                                         &modelViewMatrix.data[0]);
        glScalef(kObjectScale, kObjectScale, kObjectScale);
        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*) &buku6Verts[0]);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                     (const GLvoid*) &buku6Normals[0]);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                      (const GLvoid*) &buku6TexCoords[0]);
        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
		glDrawArrays(GL_TRIANGLES, 0, buku6NumVerts);
        SampleUtils::checkGlError("ImageTargets renderFrame");

//2nd object

QCAR::Matrix44F modelViewProjection1;
        		SampleUtils::translatePoseMatrix(10f*kObjectScale, 0.4f*kObjectScale, 0.0f*kObjectScale, &modelViewMatrix1.data[0]);
        		SampleUtils::scalePoseMatrix(0.5f*kObjectScale, 0.1f, 0.1f*kObjectScale, &modelViewMatrix1.data[0]);
                SampleUtils::multiplyMatrix(&projectionMatrix1.data[0],
                                            &modelViewMatrix1.data[0] ,
                                            &modelViewProjection1.data[0]);

                glUseProgram(shaderProgramID);
                glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                              (const GLvoid*) &BookVerts[0]);
                glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                             (const GLvoid*) &BookNormals[0]);
                glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                                              (const GLvoid*) &BookTexCoords[0]);
                glEnableVertexAttribArray(vertexHandle);
                glEnableVertexAttribArray(normalHandle);
                glEnableVertexAttribArray(textureCoordHandle);
                glActiveTexture(GL_TEXTURE0);
                glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
                glUniform1i(texSampler2DHandle, 0 GL_TEXTURE0);
                glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                                   (GLfloat*)&modelViewProjection1.data[0] );
        		glDrawArrays(GL_TRIANGLES, 0, BookNumVerts);
                SampleUtils::checkGlError("ImageTargets renderFrame");

 

but the result do not satisfied me, see attachment.

where they use the same texture, 1st object use the correct texture and the 2nd object show the texture in reverse

please lead me to the correct code,

thanks

AttachmentSize
Image icon SC20131005-204027.png213.25 KB

Trying to render 2 models on 1 image target

September 29, 2013 - 12:16pm #6

finally i can show two object on 1 marker, but another issue is , the object is use the  same texture and right on top of the first object,

could you help me on this ?? I need to show different object with different texture and show 2d object.

 

thanks,

regard

Trying to render 2 models on 1 image target

September 28, 2013 - 9:48pm #5

dear admin and all member..

i'm still trying to show SIMULTANEOUS objek on 1 target image, could you please explain me more which part of code should i replace or modify ?

i need to show 1 3d object and 3 2d object

thanks..

Re: Trying to render 2 models on 1 image target

June 20, 2012 - 8:17am #4

Ok I got it. So many consective commeting-in commenting-out, I left uncommented a line that shouldn't be visible.

The second pawn should read (there was an extra line in the apply transformation block)

// PAWN 2

        // transformations
        transformMatrix = SampleMath::Matrix44FIdentity();
        SampleUtils::rotatePoseMatrix(90.0f, 1.0f, 0.0f, 0.0f, &transformMatrix.data[0]); // rotation
        SampleUtils::translatePoseMatrix(100.0f, 0.0f, 0.0f, &transformMatrix.data[0]); // translation
        SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &transformMatrix.data[0]); // scalate


        // apply transformations to object
        SampleUtils::multiplyMatrix(&modelViewMatrix.data[0], &transformMatrix.data[0], &objectMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &objectMatrix.data[0], &modelViewProjection.data[0]);

        // draw piece
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjection.data[0] );
        glDrawElements(GL_TRIANGLES, (faces_count [chosenPiece] * 3), GL_UNSIGNED_SHORT,(const GLvoid*) &indexes[firstIndex]);


Re: Trying to render 2 models on 1 image target

June 20, 2012 - 7:35am #3

Yes, that was my first thought but when I render the first pawn using that value, It shows somewhere near the border, Keep in mind that I have to scale by 30 the models in order to see them with a decent size.

I'll double check though. Thanks!

Re: Trying to render 2 models on 1 image target

June 20, 2012 - 7:19am #2

Hi juanmb

I just tried this on the ImageTargets sample and was able to get two teapots overlapping.

Your code looks a little different, but after looking through one suggestion I might have is this line:

SampleUtils::translatePoseMatrix(100.0f, 0.0f, 0.0f, &transformMatrix.data[0]); // translation

The second pawn might have been translated out of view. In my sample I just moved it by 0.5.

HTH

N

Log in or register to post comments