Log in or register to post comments

Teapot image into our own image

March 15, 2013 - 2:27am #1

How to change the teapot image into our userdefine  image in image target sample apple,

Display a 2d object with an image.

September 23, 2013 - 4:56am #6

Display a 2d object with an image.

const char* textureFilenames[] = {

        "yourImage1.png", // width and hight must be a power of 2 (..., 256, 512, 1024, 2048, .....), ex: 1024x512

        "yourImage2.png"

    };

 

In Teapot.h

Replace the constants with:

static const float teapotVertices[] =

{

    -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 teapotTexCoords[] =

{

    0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0

};

 

static const float teapotNormals[] =

{

    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 teapotIndices[] =

{

    0, 1, 2, 0, 2, 3

};

 

In EAGLView.mm    -(void)renderFrameQCAR    copy paste this code after

#ifndef USE_OPENGL1

else {

            // OpenGL 2

            const QCAR::Trackable* trackable = state.getTrackable(i);

            QCAR::Vec2F targetSize = ((QCAR::ImageTarget *) trackable)->getSize();

            QCAR::Matrix44F modelViewProjection;

            

            //------Distance between device and printed marker--------

            QCAR::Vec3F position(modelViewMatrix.data[12], modelViewMatrix.data[13], modelViewMatrix.data[14]);

            float distance = sqrt(position.data[0] * position.data[0] +

                                  position.data[1] * position.data[1] +

                                  position.data[2] * position.data[2]);

            NSLog(@"-----------Distance: %f", distance);

            //---------------------------------------

            

            ShaderUtils::translatePoseMatrix(0.0f0.0fkObjectScale,

                                             &modelViewMatrix.data[0]);

            ShaderUtils::scalePoseMatrix(targetSize.data[0], targetSize.data[1], 1.0f,

                                         &modelViewMatrix.data[0]);

            ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0],

                                        &modelViewMatrix.data[0] ,

                                        &modelViewProjection.data[0]);

            glUseProgram(shaderProgramID);

            glVertexAttribPointer(vertexHandle3GL_FLOATGL_FALSE0,

                                  (const GLvoid*) &teapotVertices[0]);

            glVertexAttribPointer(normalHandle3GL_FLOATGL_FALSE0,

                                  (const GLvoid*) &teapotNormals[0]);

            glVertexAttribPointer(textureCoordHandle2GL_FLOATGL_FALSE0,

                                  (const GLvoid*) &teapotTexCoords[0]);

            glEnableVertexAttribArray(vertexHandle);

            glEnableVertexAttribArray(normalHandle);

            glEnableVertexAttribArray(textureCoordHandle);

            glActiveTexture(GL_TEXTURE0);

            //----- Transparent background-------

            glEnable(GL_BLEND);

            glBlendFunc(GL_SRC_ALPHAGL_ONE_MINUS_SRC_ALPHA);

            //-------------------------------------------

            glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);

            glUniformMatrix4fv(mvpMatrixHandle1GL_FALSE,

                               (GLfloat*)&modelViewProjection.data[0] );

            glDrawElements(GL_TRIANGLES6GL_UNSIGNED_SHORT,

                           (const GLvoid*) &teapotIndices[0]);

        }

#endif

   }

    glDisable(GL_BLEND); //-------- for transparent background---------

Teapot image into our own image

May 16, 2013 - 2:40am #5

Please avoid double posting.

See my answer to your related question elsewhere.

N

Teapot image into our own image

May 16, 2013 - 1:33am #4

no replies with any positive answer i also want to solve this problem

Teapot image into our own image

March 15, 2013 - 5:56am #3

sorry i don't know well English any have thank you for your help.

Teapot image into our own image

March 15, 2013 - 3:37am #2

Could you please be clearer with your question?

N

Log in or register to post comments