Log in or register to post comments

Texture problem with ImageTargets when changing the model

March 10, 2011 - 2:23am #1

Hello,

I am experiencing troubles when I try to change your 3D models by mine.
This is the way, I am doing it:
1) I create models or import models with 3DS Max then after modifying them and texturing them, I export them to .obj and generate a texture file.

2)If necessary, I reduce the number of polygons to be able to work in real time.

3) I use the famous obj2opengl.pl script to generate a .h file to embed it in the example. (I have several arrays: vertex, faces, normals and textures coordinates)

      

        	glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        	glVertexPointer(3, GL_FLOAT, 0, myTeapotVerts);
        	glNormalPointer(GL_FLOAT, 0, myTeapotNormals);
        	glTexCoordPointer(2, GL_FLOAT, 0, myTeapotTexCoords);
        	// draw data
        	glDrawArrays(GL_TRIANGLES, 0, myTeapotNumVerts);

until then it's working fine the problem is the texture aren't mapped as they should.

I don't understand where the problem is coming from.
I don't know if it's from the code, from 3DS Max(texture coordinates) or...

I have attached some files so you can see what's happening

It would be a great help if someone could give me a hint
I already thank you for the information you might provide me

Allan

Texture problem with ImageTargets when changing the model

October 1, 2013 - 12:45am #26

Hi, AlessandroB

Thanks for help..

But still not able to render texture properly.. :(

I have banana.h and banana.jpg texture. I have test my application using these files. It render correctly.

I have notice that banana.jpg file doesn't contain in transperant background. But in my texture TextureTeapot3.png (Flip vertically) 512x512 size contain lots of blank spaces. So how to overcome this problem..

I know this is related with image tool. Give me some links if have have related to it. Because I stuck here more than 12 days.

 

 

 

AttachmentSize
Image icon banana.jpg238.08 KB
Image icon TeapotTexture3.png142.2 KB

Texture problem with ImageTargets when changing the model

September 27, 2013 - 12:40am #25

The texture should be Ok for Vuforia, if it is the same texture which is used by the 3D modeling tool (except for the vertical flipping), and if the model is exported to OBJ with the right texture coordinates. 

 

Texture problem with ImageTargets when changing the model

September 26, 2013 - 4:52am #24

Hi, Thankx for help AlessandroB.

I am using Image Texture :https://developer.vuforia.com/sites/default/files/TextureTeapot1.png name TextureTeapot1.png

Now this texture image of size 512x512. Now As per this image there is too much blank space surrond it. (background is transperent)

Thats why the render texture display like : https://developer.vuforia.com/sites/default/files/IMG_0086.PNG

So This image texture is correct. for vuforia?? I fliiped it vertically.

 

 

 

AttachmentSize
Image icon TextureTeapot1.png87.18 KB
Image icon IMG_0086.PNG612.3 KB

Texture problem with ImageTargets when changing the model

September 25, 2013 - 6:49am #23

You can try either exporting to OBJ from 3DS Max, or from Blender, both possibilities are viable, but how to use those modeling tools is beyond the scope of this Forum.

 

Texture problem with ImageTargets when changing the model

September 25, 2013 - 4:33am #22

Yes.

Tell me if I use 3d max and export model to blender to get .obj file to further conversion. Is that fine process. Bcoz I am not much knowledge of blender in compare to 3d max.

Texture problem with ImageTargets when changing the model

September 25, 2013 - 4:24am #21

The code:

glDisable ( GL_CULL_FACE );
glDrawArrays(GL_TRIANGLES, 0, obj3D.numVertices);
glEnable ( GL_CULL_FACE );

looks fine.

If you still see the issue (and you ave flipped the image vertically), then something is probably wrong with the model export;

usually, a recommended approach is to load the model in Blender, export it as OBJ, then convert the OBJ to a header file, as explained in this article:

https://developer.vuforia.com/forum/faq/android-how-do-i-replace-teapot

Texture problem with ImageTargets when changing the model

September 25, 2013 - 3:55am #20

Hi,

AlessandroB

The model look correctly textured in Blender / autocad.

Actually I am ios developer. Not much knowledge about 3d modeling software. 

I am using blender and autocad 3d max. While developing the model in 3d max it looks correct but when I click on render, It shows the light effects on model.( Too mich brightness).

Here I am in confusion where wrong going on... In my code OR in development in 3d max.

My code is:

 glUseProgram(shaderProgramID);
            
            glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices);
            glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.normals);
            glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.texCoords);

            
            glEnableVertexAttribArray(vertexHandle);
            glEnableVertexAttribArray(normalHandle);
            glEnableVertexAttribArray(textureCoordHandle);
            
            glActiveTexture(GL_TEXTURE0);
          
            glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);
           // NSLog(@"texture ID : %d",[obj3D.texture textureID]);
            
            glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
            glUniform1i(texSampler2DHandle, 0/*GL_TEXTURE0*/);//0
           // glDrawElements(GL_TRIANGLES, obj3D.numIndices, GL_UNSIGNED_SHORT, (const GLvoid*)obj3D.indices);
            
            glDisable ( GL_CULL_FACE );
            
             glDrawArrays(GL_TRIANGLES, 0, obj3D.numVertices);
            glEnable ( GL_CULL_FACE );

 

Texture problem with ImageTargets when changing the model

September 24, 2013 - 7:05am #19

Does your model look correctly textured in Blender ?

if yes, then you might have exported the OBJ model incorrectly; 

Also, your rendered 3D model seems to have some "holes" (missing polygons); this could be related to back-face culling;

in your rendering code, you can add:

glDisable ( GL_CULL_FACE );

just before calling glDrawElements() (or glDrawArrays() )

and then re-enable it right after:

glEnable ( GL_CULL_FACE );

 

 

Texture problem with ImageTargets when changing the model

September 24, 2013 - 6:57am #18

Hi,

AlessandroB

 

Thankx for reply.

I have observed one thing if I used 256X256 , 512X512 texture images. Then its work.. But still the texture doesn't feet properly.

The texture shoul display like : https://developer.vuforia.com/sites/default/files/TextureTeapotGray.png

But it is display on marker like : https://developer.vuforia.com/sites/default/files/IMG_0086.PNG

I have set kObject: 100.0

and Size of texture 256X256.

 

Please help me regarding this

AttachmentSize
Image icon IMG_0086.PNG612.3 KB
Image icon TextureTeapotGray.png77.32 KB

Texture problem with ImageTargets when changing the model

September 23, 2013 - 8:33am #17

Hi, 

what you simply need to do is to open the images with an Image editor of your choice, and flip them vertically (i.e. top-down).

This should fix the problem.

 

Texture problem with ImageTargets when changing the model

September 23, 2013 - 7:41am #16

Hi Allan,

 

Same Problem  found  while rendering texture to 3d model. Even I have use .mtl converter to .h file. But its not so helpfull.

As you mentioned:

1. OpenGL ES use an mirror image of the one blender use. --  In this how to generate mirror image OR shall we write code in OPENGL ES to create an mirror image? OR If blender can generate such mirror image what will be the procedure for that.

2.applying a horizontal mirror transformation. --- where and how to apply such transformation?

Please help me regarding this I am stuck here from several days. If anyone have correct ans please give me step by step way.

Re: Texture problem with ImageTargets when changing the model

June 19, 2011 - 8:33pm #15

Double check your texture coordinates, make sure you are exporting them when you export your model. Check to see that you've cleanly unwrapped your model, one texture coordinate per vertex. It's simplest to use a single texture per model.

- Kim

Re: Texture problem with ImageTargets when changing the model

June 19, 2011 - 12:21am #14

Hi, andreasv.
Have you solved your problem yet? It seems that I meet the same problem.
Can somebody help me? Thanks!

Re: Texture problem with ImageTargets when changing the model

May 11, 2011 - 3:18am #13

Dear robertross,

What exactly do you mean?

The code is the following:


       glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &ringVerts[0]);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &ringNormals[0]);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &ringTexCoords[0]);
							  

        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);
		
		
	glBindTexture(GL_TEXTURE_2D, textures[0]->mTextureID);
		
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0] );
						   
        glDrawArrays(GL_TRIANGLES, 0, ringNumVerts);

Re: Texture problem with ImageTargets when changing the model

May 11, 2011 - 3:09am #12

I've seen this happen if you don't bind the texture properly in native.

Make sure your calling glbind before calling teximage2d.

Re: Texture problem with ImageTargets when changing the model

May 11, 2011 - 2:00am #11

as a follow to my previous post i can show you this screenshot of the rendering with the sdk which I can say that
I can see the whole texture displayed on the diamond..probably displaying the texture on each polygon..

please have a look:

Thanks in advance..

Andreas

Re: Texture problem with ImageTargets when changing the model

May 11, 2011 - 1:27am #10

First of all, thank you for your quick reply.

I would like to be more specific and hopefully get some help..

I have this 3d model in 3ds:

http://www.turbosquid.com/3d-models/diamond-ring-max-free/597885

and I import it in 3ds max. Then I choose [B" />Render to Texture[/B" /> from the menu:

[IMG" />http://i56.tinypic.com/15h0ria.png[/IMG" />

I choose[B" /> All Prepared[/B" /> in the dialog and render and get the following texture image:

[IMG" />http://i53.tinypic.com/2zgz29i.png[/IMG" />

I then export my model to obj format:

[IMG" />http://i53.tinypic.com/j8k1p0.png[/IMG" />

and convert it with the obj2opengl script:

http://heikobehrens.net/2009/08/27/obj2opengl/

Finally I get the header file ring.h

which I include in the ImageTargets.cpp:

[CODE" />

#include "ring.h"

QCAR::Matrix44F modelViewProjection;

SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale,
&modelViewMatrix.data[0" />);
SampleUtils::scalePoseMatrix(100.0f, 100.0f, 100.0f,
&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*) &ringVerts[0" />);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &ringNormals[0" />);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &ringTexCoords[0" />);

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

glBindTexture(GL_TEXTURE_2D, textures[0" />->mTextureID);

glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0" /> );

glDrawArrays(GL_TRIANGLES, 0, ringNumVerts);

[/CODE" />

In the Java side I add:

[CODE" />
mTextures.add(Texture.loadTextureFromApk("texture.png", getAssets()));[/CODE" />

The results are not as expected for the texture...

[IMG" />http://i53.tinypic.com/2ztkm5h.jpg[/IMG" />

Can anyone understand what is going wrong?

Any suggestion is welcome...

Re: Texture problem with ImageTargets when changing the model

May 10, 2011 - 7:12am #9

This is where texture coordinates come in. You use a process called UV unwrapping to map each vertex of your 3D model to 2D texture space. Most 3D modeling programs will have tools to help you UV unwrap your model. Be sure to export the UV coordinates when you export your model. Then make sure you've enabled and set the texture coordinate array in your OpenGL code, our samples should give you a good starting point.

- Kim

Re: Texture problem with ImageTargets when changing the model

May 10, 2011 - 6:48am #8

Hi everyone i had a similar problem..first it was the problem that the obj file was not saved in triangles and then I did not see any texture on my object just a mirror of the background applied as a texture on the object.. I managed to apply the texture but the problem is that is the texture is applied to each polygon, for example on each side of a cube instead of applying the texture on the cube as a whole.. How can I apply a texture to an object as a whole and not on each polygon??

Thanks in advance,

Andreas

Re: Texture problem with ImageTargets when changing the model

March 17, 2011 - 2:21am #7

Hi Allan, for me also the similar problem, i am using 3ds max to create 3d models . I used different colors to create my 3d model, but when i am seeing in the mobile only one single color is appearing can u help me out i have been searching for 1 month [i had mtl file with me, wat is the use of it]. it was very urgent to me plz i stucked in the middle

Re: Texture problem with ImageTargets when changing the model

March 16, 2011 - 11:39am #6

OK, I found the problem,it was so tricky...
In fact, softwares like blender, 3DSMax, do NOT use the same coordinate system (U,V for the texture mapping) as OpenGL ES does...
OpenGL ES use an mirror image of the one blender use. So I have to transform the texture by applying a horizontal mirror transformation.

I hope it may help some of you

Allan

Re: Texture problem with ImageTargets when changing the model

March 14, 2011 - 5:07am #5

Thank you for your replies,
I am still blocked but I am nearly sure the problem comes from the way I generate the obj file with 3DS Max.

In fact, when I export the file to .obj there is only a MTL file for the texture but there is no bitmap.
To generate the bitmap that will contains my texture I use the "render to texture" mode.

Can someone give me some tips, or explain me the way to do that with Blender? I am ready to start learning Blender if I have to.

Have a nice day

Allan

Re: Texture problem with ImageTargets when changing the model

March 10, 2011 - 9:20am #4

On second look that may not be your problem...

Re: Texture problem with ImageTargets when changing the model

March 10, 2011 - 9:18am #3

I had the same problem.
What I did was triangulated the model and it worked fine.

(I was using Blender and there is an option to do so when exporting the object to obj)

Re: Texture problem with ImageTargets when changing the model

March 10, 2011 - 5:49am #2

Interesting!

There's definitely something wrong with the texture coordinates, the entire image is being mapped to each object (repeated) instead of each object grabbing a small portion from the texture space... What happens when you reimport the .obj file into 3DS Max, do the textures look correct at that point? It's possible that "the script" isn't handling something correctly. What happens when you export just one of the three objects?

I would take another look at the texture coordinates in 3DS Max, I don't have much experience with that particular program but you should be able to select a group of faces and see what section of the texture is mapping to it.

- Kim

Log in or register to post comments