Hi everybody!
Here's what I'd like to do: Using the Dominoes sample I want to place the green glow texture -that is normally used for marking the starting Domino- in the center of the trackable the moment the trackable is recognized. And increase the diameter of the green texture.
Easy, right? Not if you're new to OpenGL like I am.
I looked at the OpenGL code of the ImageTargets app and the Dominoes app as well and experimented a bit. As a result I managed to place a tiny cube with the non-transparent green glow texture as its six sides in the center of the trackable.
That's almost what I wanted: I don't want a cube, I want a big but flat, slightly transparent texture where the tiny cube is now.
It would be great if someone could give me a hint how to do that. Beneath is my patchwork code that draws the unloved cube. The code is placed in the Java_com_qualcomm_QCARSamples_Dominoes_DominoesRenderer_renderFrame(JNIEnv* env , jobject obj) method in Dominoes.cpp.
// Constants: const Texture* const greenGlowTexture = textures[1]; static const float kObjectScale = 3.f; QCAR::Matrix44F transform = SampleMath::Matrix44FIdentity(); float* transformPtr = &transform.data[0]; SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]); SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,&modelViewMatrix.data[0]); SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &cubeVertices[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &cubeNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &cubeTexCoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glUseProgram(shaderProgramID); glBindTexture(GL_TEXTURE_2D, greenGlowTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjection.data[0] ); glDrawElements(GL_TRIANGLES, NUM_CUBE_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &cubeIndices[0]); SampleUtils::checkGlError("Dominoes renderFrame");
You're never rendering any geometry with the green glow texture. In the Dominoes sample we render a flattened cube, you could also just render a plane object (sample code at http://ar.qualcomm.at/node/2000357). You'll need another call to glDrawElements or glDrawArrays after setting up the geometry using glVertexAttribPointer.
- Kim