Log in or register to post comments

Replaceing the Teapot in sample imagetarget

January 31, 2011 - 8:39am #1

Hi everyone.

So I am trying to replace the teapot with a flat image and I am having problems. I assumed (maybe incorrectly) that I needed to create a plane in a 3d model and attach my image as a texture to get the effect I am looking for.

I created the .obj file and then used the perl script that I found referenced on this board to create the .h file. However when I look at the teapot.h file and the plane.h file I created, I am seeing a number of differences in variable definitions that I don't know how to reconcile. Every attempt I have made just throws errors and I am at a total loss.

Any help would be appreciated!

Thanks.

Re: Replaceing the Teapot in sample imagetarget

June 17, 2011 - 9:28am #13

ACT I try to make banana like You but I have some problems:
1.

ACT wrote:

----> bananaTextCoords by teapotTextCoords

Here is a mistake Tex not Text but thats no problem.

When I ndk-build I get an error:

Marcin@Marcin-PC /cygdrive/c/Development/Android/qcar-sdk-1-0-0/samples/ImageTargets
$ ndk-build -B
Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi-v7a/gdbserver
Gdbsetup       : libs/armeabi-v7a/gdb.setup
Compile++ arm    : ImageTargets <= ImageTargets.cpp
C:/Development/Android/qcar-sdk-1-0-0/samples/ImageTargets/jni/ImageTargets.cpp: In function 'void Java_com_qualcomm_QCARSamp
les_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv*, _jobject*)':
C:/Development/Android/qcar-sdk-1-0-0/samples/ImageTargets/jni/ImageTargets.cpp:185: error: expected ')' before ';' token
C:/Development/Android/qcar-sdk-1-0-0/samples/ImageTargets/jni/ImageTargets.cpp:185: error: expected primary-expression befor
e ')' token
C:/Development/Android/qcar-sdk-1-0-0/samples/ImageTargets/jni/ImageTargets.cpp:185: error: expected ';' before ')' token
make: *** [/cygdrive/c/Development/Android/qcar-sdk-1-0-0/samples/ImageTargets/obj/local/armeabi/objs-debug/ImageTargets/Imag
eTargets.o] Error 1

here is my 182-187 lines:

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,(GLfloat*)&modelViewProjection.data[0] );
        glDrawArrays(GL_TRIANGLES, 0, NUM_TEAPOT_OBJECT_VERTEX);

        SampleUtils::checkGlError("ImageTargets renderFrame");

any idea what I do wrong ?

Thanks for any help

--- problem solved

I placed ; after #define NUM_TEAPOT_OBJECT_VERTEX 24168

Sorry

Re: Replaceing the Teapot in sample imagetarget

May 31, 2011 - 2:57pm #12

solved. problem was in assigning to a wrong matrix

Re: Replaceing the Teapot in sample imagetarget

May 31, 2011 - 2:26pm #11

Hi all!
I'm trying to replace teapot in the virtual buttons sample.
everything is ok except of size. but resizing in SampleUtils::scalePoseMatrix is not working. Does anyone know what could be the problem? Thanks in advance!

Re: Replaceing the Teapot in sample imagetarget

May 17, 2011 - 3:01am #10

Hi,
I would like to replace a 3D object instead of the teapot (and it does not work). I read all the topics here, and this his what I did :

-In Eclipse, I imported the ImageTargets project.
-I chose to replace the teapot by the banana (found on the link provided on the forum https://github.com/HBehrens/obj2opengl)
-so I copy and paste the banana.h in the Teapot.h file in Eclipse.
-In my new Teapot.h file, I replaced :
----> unsigned int bananaNumVerts = 24168; by #define NUM_TEAPOT_OBJECT_VERTEX 24168
---->[B" /> bananaVerts[/B" /> by [B" />teapotVertices[/B" />
----> [B" />bananaNormals[/B" /> by [B" />teapotNormals[/B" />
----> [B" />bananaTextCoords[/B" /> by [B" />teapotTextCoords[/B" />
-Then in ImageTargets.cpp, I replaced twice [B" />glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,(const GLvoid*) &teapotIndices[0" />);[/B" /> by [B" />glDrawArrays(GL_TRIANGLES, 0, NUM_TEAPOT_OBJECT_VERTEX);[/B" />
-I went to Cygwin, wrote the directory of ./Development/Android/qcar-sdk-1-0-0/samples/ImageTargets, then ndk-build.
-I cleaned the project on Eclipse. The libs folder is created.

At the moment, I don't care about the texture, I just would like to see the banana with the teapot texture. I exported the application, and nothing appears when I put my phone in front of the stones or chips targets!

The fact that I don't see the teapots anymore is a good point, but I would like to see this banana :rolleyes:

Could you tell me what I did wrong?

PS : I also tried ndk-build -B

-------------------------------------
I found my problem!

It was not really a problem... the banana was here, but it had a very little size, so I did not paid attention to it... :p

I just needed to increase the size in ImageTargets.cpp
[B" />static const float kObjectScale = 100.f;[/B" />

Re: Replaceing the Teapot in sample imagetarget

May 5, 2011 - 12:12pm #9
ksiva wrote:

Finally, it looks like you may have some triangles winding in the wrong direction, which would create holes in parts of your model. If that's the case, try disabling culling with glDisable(GL_CULL_FACE);

Thank you very much, glDisable(GL_CULL_FACE) did the trick. And thank you for the hint with the texture size. I will try it :)

Re: Replaceing the Teapot in sample imagetarget

May 5, 2011 - 11:40am #8

So it looks like the model is being rendered with the camera image as a texture instead of your texture image. First off, try resizing your texture to 1024x1024, 2000 is probably too large, and power-of-two textures are sure to work on all devices. Then make sure you've placed the texture in the assets folder, and added the filename to the loadTextures java method (e.g. in ImageTargets.java).

Finally, it looks like you may have some triangles winding in the wrong direction, which would create holes in parts of your model. If that's the case, try disabling culling with glDisable(GL_CULL_FACE);

- Kim

Re: Replaceing the Teapot in sample imagetarget

May 5, 2011 - 11:24am #7

http://stackoverflow.com/questions/5897042/how-to-load-maya-models-exported-to-wavefront-obj-with-android-gl)

but now it's triangulated (done with maya) and it's still broken.

I added a file to my post which contains the header, the model and screenshots. Hope you can help us.

http://dl.dropbox.com/u/3985208/model_and_header.zip

PS: Also the app crashes when I want to use my own texture.

Re: Replaceing the Teapot in sample imagetarget

February 1, 2011 - 10:11am #6

Are you rebuilding the shared library using ndk-build after changing the Teapot header? You might try running "ndk-build -B" to force a rebuild as well. Then you have to refresh the project in Eclipse to pick up the changes, or simply clean the Eclipse project.

Note that ImageTargets.cpp has two separate rendering pathways, one using OpenGL ES 1.1 and one using OpenGL ES 2.0. You can switch between the two using the USE_OPENGL_ES_1_1 flag in the Android.mk file (located in the jni folder). Make sure that you are changing the correct rendering code in ImageTargets.cpp.

Finally, I might suggest pasting those arrays directly into the ImageTargets.cpp file and not including Teapot.h at all. It's not necessary for your geometry to be in a separate file, and this way we can be sure the code is using your updated arrays.

- Kim

Re: Replaceing the Teapot in sample imagetarget

February 1, 2011 - 9:59am #5

First thank you for all the help.

Now I have replaced the vertices info in Teapot.h with the plane that you did by hand. I then built the project with ndk-build and refreshed my eclipse project. Everything goes great but when I use the app the teapot still shows up. I have triple checked the Teapot.h file to make sure it contains your plane but the teapot still shows up and I have no idea why.

I am using blender to answer your earlier question.

Thanks.

Re: Replaceing the Teapot in sample imagetarget

January 31, 2011 - 11:45am #4

Hmm, I'm not exactly sure about the error, but it's probably not a good thing that your model doesn't contain normals or texcoords. At the very least you'll need to comment out the normal/texcoord OpenGL code in that case.

Also, your model only has one face, but you'll need two faces (triangles) to make a plane with OpenGL ES. Quads are not supported. Triangulate your model before exporting. By the way, what tool are you using for modeling?

You may find it easier to just create a plane by hand. Here's some sample code:

float planeVertices[] =
{
    -0.5, -0.5, 0.0, 0.5, -0.5, 0.0, 0.5, 0.5, 0.0, -0.5, 0.5, 0.0,
};

float planeTexcoords[] =
{
    0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0
};

float planeNormals[] =
{
    0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0
};

unsigned short planeIndices[] =
{
    0, 1, 2, 0, 2, 3
};

glUseProgram(shaderProgramID);

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                      (const GLvoid*) &planeVertices[0]);

glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                      (const GLvoid*) &planeNormals[0]);

glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                      (const GLvoid*) &planeTexcoords[0]);

glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);

glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                   (GLfloat*) &modelViewProjection.data[0]);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
               (const GLvoid*) &planeIndices[0]);

Note that this is a unit plane, so you'll want to scale it up quite a bit to render it on the sample image targets. Try setting kObjectScale to something like 100.

- Kim

Re: Replaceing the Teapot in sample imagetarget

January 31, 2011 - 11:27am #3

Thanks for the quick response.

So here is what is happening... I replace the Teapot.h file with my new teapot.h file which contains one plane.

/*
created with obj2opengl.pl

source file : .\teapot.obj
vertices : 4
faces : 1
normals : 0
texture coords : 0

// include generated arrays
#import ".\teapot.h"

// set input data to arrays
glVertexPointer(3, GL_FLOAT, 0, teapotVerts);

// draw data
glDrawArrays(GL_TRIANGLES, 0, teapotNumVerts);
*/

unsigned int teapotNumVerts = 3;

float teapotVerts [] = {
// f 1 4 3 2
0.499999945797954, 0, -0.499999837393862,
-0.499999837393862, 0, -0.500000054202046,
-0.500000054202046, 0, 0.499999945797954,
};

Then I update the ImageTargets.cpp with the line of code you provided and when I use cygwin to build it I get the following error:

cygdrive/c/development/android/qcar-sdk-0-10-0/samples/ImageTargets/obj/local/armeabu/objs-debug/ImageTargets//ImageTargets.o.d: *** target pattern contains no '%' Stop.

Not sure what I a doing wrong.

Thanks.

Re: Replaceing the Teapot in sample imagetarget

January 31, 2011 - 10:09am #2

If you want the plane to exist in 3D then yes, you need to use a 3D model.

The main difference when using that perl script is that it does not create indexed arrays. You won't have an indices array, but that's okay. Simply use glDrawArrays rather than glDrawElements in your rendering method.

glDrawArrays(GL_TRIANGLES, 0, planeNumVerts);

instead of

glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0]);

Let me know if you are still having trouble.

- Kim

Log in or register to post comments