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.0f, 0.0f, kObjectScale,
&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(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);
//----- Transparent background-------
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//-------------------------------------------
glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
(const GLvoid*) &teapotIndices[0]);
}
#endif
}
glDisable(GL_BLEND); //-------- for transparent background---------
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.0f, 0.0f, kObjectScale,
&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(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);
//----- Transparent background-------
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//-------------------------------------------
glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
(const GLvoid*) &teapotIndices[0]);
}
#endif
}
glDisable(GL_BLEND); //-------- for transparent background---------