title: Loading another 3D model on touch in qualcomm sdk for android
body: <p>I am using qualcomm sdk and using the ImageTargets sample application to develop an augmented reality application. Application runs fine but i want to load another 3D model when the user touches the screen i.e. when camera view starts and comes to marker then the teapot 3D model loads and then user touches the screen a new model should load. The following are the steps i am doing :-</p>
  
  <ol>
  <li><p>I have got the new 3D model and got its .h file . I have included it in assets folder 
  and also included it in ImageTargets.cpp file i.e. #include "./banana.h"</p></li>
  <li><p>Then i have added ontouchEvent in ImageTargets.java file which calls another function in
  ImageTargets.cpp which updates the modelID variable. </p></li>
  <li><p>Following is the editted code of the ImageTargets.cpp in renderFrame function</p>
  
  <pre><code> #ifdef USE_OPENGL_ES_1_1
  // Load projection matrix:
  
  glMatrixMode(GL_PROJECTION);
  glLoadMatrixf(projectionMatrix.data);
  
  // Load model view matrix:
  glMatrixMode(GL_MODELVIEW);
  glLoadMatrixf(modelViewMatrix.data);
  glTranslatef(0.f, 0.f, kObjectScale);
  glScalef(kObjectScale, kObjectScale, kObjectScale);
  
  // Draw object:
  glBindTexture(GL_TEXTURE_2D, thisTexture-&gt;mTextureID);
  
  if (modeId == 0){
      glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &amp;teapotTexCoords[0]);
      glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &amp;teapotVertices[0]);
      glNormalPointer(GL_FLOAT, 0,  (const GLvoid*) &amp;teapotNormals[0]);
      glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                 (const GLvoid*) &amp;teapotIndices[0]);
  }
  else{
      glVertexPointer(3, GL_FLOAT, 0, bananaVerts);
      glNormalPointer(GL_FLOAT, 0, bananaNormals);
      //glTexCoordPointer(2, GL_FLOAT, 0, bananaTexCoords);
      glDrawArrays(GL_TRIANGLES, 0 , bananaNumVerts);
  }
    #else
  LOG("When tracker found 4");
  QCAR::Matrix44F modelViewProjection;
  
  SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale,
                                   &amp;modelViewMatrix.data[0]);
  SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
                               &amp;modelViewMatrix.data[0]);
  SampleUtils::multiplyMatrix(&amp;projectionMatrix.data[0],
                              &amp;modelViewMatrix.data[0] ,
                              &amp;modelViewProjection.data[0]);
  
  glUseProgram(shaderProgramID);
  
  if (modelId == 0)
  {
      LOG("ModelID is 0");
      glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                        (const GLvoid*) &amp;teapotVertices[0]);
      glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                        (const GLvoid*) &amp;teapotNormals[0]);
      glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                        (const GLvoid*) &amp;teapotTexCoords[0]);
  }
  else
  {
      LOG("ModelID is 1");
      glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                (const GLvoid*) &amp;bananaVerts[0]);
      glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                                (const GLvoid*) &amp;bananaNormals[0]);
      glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                               (const GLvoid*) &amp;bananaTexCoords[0]);
  }
  
  glEnableVertexAttribArray(vertexHandle);
  glEnableVertexAttribArray(normalHandle);
  glEnableVertexAttribArray(textureCoordHandle);
  
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, thisTexture-&gt;mTextureID);
  glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                     (GLfloat*)&amp;modelViewProjection.data[0] );
  
  if (modelId == 0)
  {
      LOG("ModelID is 0");
      glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
                 (const GLvoid*) &amp;teapotIndices[0]);
  }
  else{
      LOG("ModelID is 1");
      glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);
  }
  
  
  SampleUtils::checkGlError("ImageTargets renderFrame");
  
   #endif
  </code></pre></li>
  </ol>
  
  <p><strong>Edit</strong></p>
  
  <p>I solved the problem though if using glDrawElements then you should not use glDrawArrays. So i created another .h file from some 3d .obj file and it started working.   </p>