- Sort Posts
- 17 replies
- Last post
Re: Create/Replace Object
Re: Create/Replace Object
Hi,
I have the exact same problem..
I can not export an image(texture) that can be applied correctly to my model.. I assume that my mistake is that I do not create the texture appropriately..
My models already have a texture. I work in 3ds Max. I select Render to Texture and export the texture.
I convert my .3ds object with obj2opengl script. The object is rendered correctly but the texture not.
The question here is that is there a way or a procedure that we should follow to export the texture with any tool along with the obj in order to render correctly in the sdk?
It is a similar problem with the post above..
Thanks in advance,
Andreas
Re: Create/Replace Object
hei, kim i have another problem. i make a soccer ball in "3dmax", and export it into .obj with "blender"..then i try to "bake" this .obj into .png..but when i start imagetargets, my object have a wrong texture..
this is my texture.png:
this is the result when i start ImageTargets with my object an texture:
can you tell me what tools you use to get texture.png for "Teapot" object to get "TextureTeapotBlue.png" or "TextureTeapotBrass.png"??maybe i can use tools that you use to get the correct texture..
or maybe if you use "blender" too, would you like to tell me the correct way to "bake" my object..
Re: Create/Replace Object
Re: Create/Replace Object
Finally my object and teapot object can be shown with different target in one application after i change the renderframe method :
int textureIndex = (!strcmp(trackable->getName(), "stones")) ? 0 : 1; //const Texture* const thisTexture = textures[textureIndex]; if (strcmp(trackable->getName(), "stones") == 0) { // render your model const Texture* const thisTexture = textures[textureIndex]; QCAR::Matrix44F modelViewProjection; SampleUtils::translatePoseMatrix(0.0f, 0.0f, 100.f, &modelViewMatrix.data[0]); SampleUtils::scalePoseMatrix(100.f, 100.f, 100.f, &modelViewMatrix.data[0]); SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0] , &modelViewProjection.data[0]); glUseProgram(shaderProgramID); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaVerts[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaTexCoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjection.data[0] ); glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts); SampleUtils::checkGlError("ImageTargets renderFrame"); } else if (strcmp(trackable->getName(), "chips") == 0) { // render the teapot const Texture* const thisTexture = textures[textureIndex]; QCAR::Matrix44F modelViewProjection; 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]); 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); glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjection.data[0] ); glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0]); SampleUtils::checkGlError("ImageTargets renderFrame"); } }
i change opengl_es_1_1 value to false, because my application wont display the teapot with opengl1_1.
can you tell me why??
Re: Create/Replace Object
You still need to pick a texture to bind. Add this line back in for both cases, replacing textureIndex with a valid texture id (0 or 1 for the original sample).
const Texture* const thisTexture = textures[textureIndex];
The textureIndex is defined by the order you add the textures in your Java code, see the loadTextures() method in ImageTargets.java.
- Kim
Re: Create/Replace Object
Ok, i set OPENGL_ES_1_1 to true. then i change the code in image targets :
int textureIndex = (!strcmp(trackable->getName(), "stones")) ? 0 : 1; const Texture* const thisTexture = textures[textureIndex];
to
if (strcmp(trackable->getName(), "stones") == 0) { // render your model 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->mTextureID); glVertexPointer(3, GL_FLOAT, 0, bananaVerts); glNormalPointer(GL_FLOAT, 0, bananaNormals); glTexCoordPointer(2, GL_FLOAT, 0, bananaTexCoords); glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts); } else if (strcmp(trackable->getName(), "chips") == 0) { // render the teapot // 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->mTextureID); glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*) &teapotTexCoords[0]); glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*) &teapotVertices[0]); glNormalPointer(GL_FLOAT, 0, (const GLvoid*) &teapotNormals[0]); glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0]); }
but i get the following error
E:/development/android/qcar-sdk-1-0-0/samples/imagetargets/jni/ImageTargets.cpp: In function 'void Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRender er_renderFrame(JNIEnv*, _jobject*)': E:/development/android/qcar-sdk-1-0-0/samples/imagetargets/jni/ImageTargets.cpp: 153: error: 'thisTexture' was not declared in this scope E:/development/android/qcar-sdk-1-0-0/samples/imagetargets/jni/ImageTargets.cpp: 172: error: 'thisTexture' was not declared in this scope make: *** [/cygdrive/e/development/android/qcar-sdk-1-0-0/samples/imagetargets/o bj/local/armeabi/objs-debug/ImageTargets/ImageTargets.o] Error 1
Did i make mistake??
Re: Create/Replace Object
You're going to need a basic understanding of OpenGL and the rendering code in the renderFrame method. If you are looking at ImageTargets.cpp, here are the variables that need to change for your model:
textureIndex
teapotVertices
teapotNormals
teapotTexCoords
teapotIndices
NUM_TEAPOT_OBJECT_INDEX
Note that you will not have the last two if you are using glDrawArrays instead of glDrawElements.
You can swap the data out according to the target that is visible, or simply copy the rendering code and make the few changes required:
if (strcmp(trackable->getName(), "stones") == 0) { // render your model } else if (strcmp(trackable->getName(), "chips") == 0) { // render the teapot }
I might suggest picking OpenGL ES 1.1 or 2.0 and removing the extra code to make it easier to work with. OpenGL ES 2.0 is the default, but this can be changed by opening the Android.mk file and changing the USE_OPENGL_ES_1_1 flag to true.
- Kim
Re: Create/Replace Object
oke i found this code :
int textureIndex = (!strcmp(trackable->getName(), "stones")) ? 0 : 1;
i dont know what i must do with this code to make ImageTargets can detect different target with different object to render, for example : if my camera detect "chips" image, "teapot" will be shown. but if "stones" is detect, my object is shown..
Re: Create/Replace Object
You can switch your content based on the target name in the cpp code. Take a look at ImageTargets.cpp. The renderFrame method is called each frame, and that code loops through all visible trackables for the frame. You can check the target name with trackable->getName() and render the appropriate content using its modelview matrix. The sample currently switches the texture based on the target name (using the same teapot model) but you can adapt it to switch the vertex/normal/texcoord/index arrays as well to draw a different model.
- Kim
Re: Create/Replace Object
50 is a rough limit right now. You might be able to go a little higher than that, but you will eventually reach a ceiling past which extra targets cannot be tracked. The cap will be expanded in a later release.
You can however track as many frame markers as there are available (512).
- Kim
thanks robertross. it must flip vertically. my texture had wrap my object perfectly..thank you very much..
Regards,
Gyan