Log in or register to post comments

3d model not loading

February 21, 2012 - 5:00am #1

I am new to Augmented reality and I am having real fun developing in this technology.
I have altered ImageTargets sample project to show teapot over my own markers and I was successfull doing that. Now I tried to change 3d model to show my own 3d model over the marker but model is not displaying. Please find attachment for 3d model's .obj file. Also How do I create texture for my 3d model?

Ayaz Alavi

Re: 3d model not loading

February 28, 2012 - 10:17pm #19

Thank you very much for your help.

Re: 3d model not loading

February 27, 2012 - 5:24am #18

Well you're in luck, Ayaz, we released QCAR iOS SDK 1.5.8 last week. :-)

Please download the latest version to update your project.

Re: 3d model not loading

February 27, 2012 - 3:11am #17

One more thing
When 1.5 will be out of beta because i need to release app using this version.

Re: 3d model not loading

February 27, 2012 - 2:19am #16

Hi Ayaz,

I'm pelased we've got your model and texture working. What you do to improve that is now between yourself and your 3D modeller.

If you want to learn more about OpenGL and textures there are plenty of specific on-line resources and Phil Rideout's excellent "iPhone 3D Programming"

Re: 3d model not loading

February 26, 2012 - 11:15pm #15

Textures applied successfully by

glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);


Now one more problem :confused::confused:. Textures is just blue because I have placed blue texture file there. Now I need to apply some cool texture file that involves multiple colors and 3d style. How to do that?

Re: 3d model not loading

February 24, 2012 - 9:04am #14
ayazalavi wrote:

I used orange color texture file but model is still looks steel gray.

Well that's not quite true - take a close look at the letters and you'll see that the second letter 'u' has the W and star from your background image in it.

This means that the texture being used is the luminence from the background image. This would happen if you've not loaded or bound your own texture correctly.

Make sure you've got something like this in your gode before the glDrawArrays:

glBindTexture(GL_TEXTURE_2D, textureID);

Test that your texture has loaded okay by following the code in Texture.mm through.

Re: 3d model not loading

February 24, 2012 - 6:53am #13

Designer provided completely triangulated 3d model and it worked. Now model is showing but texture is still not getting applied over it. I used orange color texture file but model is still looks steel gray. Look at attached output shown on iphone. Why it is like that?

Re: 3d model not loading

February 23, 2012 - 4:12am #12

Hi Ayaz,

So it depends on whether you're A) using OpenGL ES 1.1 with inbuilt shaders, or B) OpenGL ES 2.0 with loadable shaders.

And if B) then it'll depend on whether you're using simple pre-baked textures or setting up live lighting and reflections.

If you don't know, or want to keep it simple, then all you need to do is resize the given texture image in Preview to be something like 512x512 or 1024x512 etc and use it in place of the teapot image.

Use of specular and diffuse lighting, normals and reflections maps in OpenGL is an advanced use.

As a test try using your texture with the teapot model.

Re: 3d model not loading

February 23, 2012 - 3:56am #11

I have posted back to the designer about GL_QUADS issue in ios and he will definatly be able to provide us 3d model completely triangulated. Now about texture he replied following:


Regarding the colouring with PNG texture – I’m a little lost on exactly how you envision going about this? 3D shaders are used which either have the diffuse colour or texture nodes are added to the shader if a specific coloured texture is required.

What should I ask from him to apply correct textures to my 3d model?

Re: 3d model not loading

February 22, 2012 - 5:55am #10

Firstly, yes, you need an object reduced to triangles - GL_QUADS is not supported on iOS. Some of your faces are triangles, but most are quads. I assume the convertor you are using doesn't resolve this.

Secondly, for iOS your image my need to be sized to powers of two (eg. 1024x512) depending on which versions of iOS you are supporting - it's easier (and maybe faster) to keep to that constraint.

Re: 3d model not loading

February 21, 2012 - 11:35pm #9

I have placed attached texture file and change code to following

const char* textureFilenames[] = {

but model looks still same as I attached image in my previous post. I dont know why. Is this because I am using GL_Triangles in the code and model is not triangulated? Anyone can shed light on this issue?


glDrawArrays(GL_TRIANGLES, 0, obj3D.numVertices);

Also find attachment for 3d model I m trying to use.

Re: 3d model not loading

February 21, 2012 - 7:01am #8

Well that's progress, Ayaz!

Now try replacing the texture with a solid-coloured image file (make sure it's 256x256 or 512x512 etc).

Re: 3d model not loading

February 21, 2012 - 6:10am #7

Please see attachment for the screenshot of how model is getting rendered now (I set scale to 150.0f so it starts showing it).
Why this model is not getting rendered properly? Also is this requirement that 3d model must be triangulated for showing it on iphone? Why do we triangulate 3d model? I think this might be issue in my 3d model.

Re: 3d model not loading

February 21, 2012 - 6:00am #6

You'll need to manipulate the poseMatrix to move the object. See the method renderFrameQCAR in EAGLView for the ImageTargets sample app - look for the glTranslatef and glScalef calls. Translating the object will change it's position.

Re: 3d model not loading

February 21, 2012 - 5:50am #5

How to set positioning of 3d model? I have set scaling to 15.0f.

Re: 3d model not loading

February 21, 2012 - 5:46am #4

Hi Ayaz,

Ah, I see that you've already used a convertor then.

Even with the wrong texture (ie the teapot) the model should show something here if your code is correct - and it looks okay at first glance.

1) Check the scaling and positioning of the object (maybe its so small you can't see it or so big that you are inside it!)
2) Make sure the texture is loaded

To make a texture for your object, you'll need to load it into a 3D modelling tool and generate a UV map by unwrapping the object's skin into 2D - you can then usually create an image which gives you guidelines to paint the skin in PhotoShop.

Re: 3d model not loading

February 21, 2012 - 5:27am #3

i used obj2opengl tool to convert my obj file into .h file and included it at the top of EAGLView.mm. I also changed to following code for generating 3dobject.

Object3D *obj3D = [[Object3D alloc] init];

        obj3D.numVertices = putitout_text1NumVerts;
        obj3D.vertices = putitout_text1Verts;
        obj3D.normals = putitout_text1Normals;
        obj3D.texCoords = putitout_text1TexCoords;
        obj3D.numIndices = NUM_TEAPOT_OBJECT_INDEX;
        obj3D.indices = teapotIndices;
        obj3D.texture = [textures objectAtIndex:i];

        [objects3D addObject:obj3D];
        [obj3D release];

Also in - (void)renderFrameQCAR I changed code to following

glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*)obj3D.texCoords);
            glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*)obj3D.vertices);
            glNormalPointer(GL_FLOAT, 0, (const GLvoid*)obj3D.normals);
            glDrawArrays(GL_TRIANGLES, 0, obj3D.numVertices);

Still 3d model is not getting loaded. I saw texture file of teapot and it looks strange and it doesnt look teapot at all. How to generate such texture file for my 3d model via blender or photoshop?

Also Number of vertices in .h file at the top are 15789.
unsigned int putitout_text1NumVerts = 15789;

Re: 3d model not loading

February 21, 2012 - 5:19am #2

Hi Ayaz,

Well this is where the real fun starts. :-)

You'll need to get up to speed with how to add textures to your model in the 3D development tool you are using. I'm afraid this we can't help you with.

If you haven't got a 3D development tool and want to texture your object, then Blender is a good open source choice.

You'll need to use an exporter or a conversion tool to get your model from your 3D modeling tool into a .h form for compiling into the app (take a look at teapot.h) or write a loader for your app that reads a standard format like .obj.

Take a look at iOS and OpenGL forums as these issues are not unique to QCAR. And take a look at Jeff Lamarche's excellent log on exporting header files for Objective-C from Blender.

Sorry that there's no quick remedy, unless other developers out there have something they can share. There's always Unity of course. :-)

Log in or register to post comments