Log in or register to post comments

How to define the scale of 2D image to display.

February 14, 2013 - 11:09pm #1

I would like to display the 2D image when FrameMarker is detected. My problem is the scale of 2d image isn't like the original file. And I would like to know is it possible to use 2D image file that the size isn't like 256x256 ,256x512.  My code is

 

static const float planeVertices[] =

 

{

    -0.5, -0.50.00.5, -0.50.00.50.50.0, -0.50.50.0,

};

 

static const float planeTexcoords[] =

{

    0.00.01.00.01.01.00.01.0

};

 

static const float planeNormals[] =

{

    0.00.01.00.00.01.00.00.01.00.00.01.0

};

 

static const unsigned short planeIndices[] =

{

    012023

};

 

 

--------------

 

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

            

            QCAR::Matrix44F modelViewProjection;

            

            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*) &planeVertices[0]);

            glVertexAttribPointer(normalHandle3GL_FLOATGL_FALSE0,

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

            glVertexAttribPointer(textureCoordHandle2GL_FLOATGL_FALSE0,

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

            

            glEnableVertexAttribArray(vertexHandle);

            glEnableVertexAttribArray(normalHandle);

            glEnableVertexAttribArray(textureCoordHandle);

            

            glActiveTexture(GL_TEXTURE0);

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

            glUniformMatrix4fv(mvpMatrixHandle1GL_FALSE,

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

            glDrawElements(GL_TRIANGLES6GL_UNSIGNED_SHORT,

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

How to define the scale of 2D image to display.

February 18, 2013 - 12:46am #2

Hi, concerning the non-power-of-two texture size (i.e. not using 256x256, etc...), these should be supported on iPhone and iPad if you use OpenGL ES 2.0 (which is the default in our samples), provided that you use linear filtering and clamp-to-edge, i.e., your texture creation code should include these lines of code (after the glGenTexture(...) and glBindTexture(...) lines):

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

 

Concerning your first question, can you be more specific on how you want to render your 2D image ? (e.g. do you want to render it as "screen-aligned" while moving with the target in 3D space, like a billboard, or aligned with the 3D surface of your target ? or fullscreen ?)

Log in or register to post comments