Question

I'm using Cheetah3D to export a COLLADA file ( .dae ) and then Erik Buck's COLLADAViewer2 ( https://github.com/erikbuck/COLLADAViewer2/tree/master/COLLADAViewer2 ) program to export a modelplist format as described in his book.

My COLLADA file is a simple Sphere which I am trying to render an earth texture onto.

In the COLLADAViewer program, my exported .dae file looks fine, here's a screenshot:

enter image description here

The portion of my code used to render the texture on the sphere is here:

// Setup texture
CGImageRef imageRef =
[[UIImage imageNamed:@"Earth.jpg"] CGImage];

GLKTextureInfo *textureInfoEarth = [GLKTextureLoader
                               textureWithCGImage:imageRef
                               options:[NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool:YES],
                                        GLKTextureLoaderOriginBottomLeft, nil]
                               error:NULL];

self.baseEffect.texture2d0.name = textureInfoEarth.name;
self.baseEffect.texture2d0.target = textureInfoEarth.target;

// Enable fragment blending with Frame Buffer contents
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Unfortunately, in XCode when I build and run my sphere looks like this on the Simulator:

enter image description here

I'm not sure how to explain the strange pattern on the sphere, it's like the texture is there but being repeated. Can anyone please help me figure this out? Thanks -

I uploaded the xcode project I am experimenting with to Github. It uses alot of the example code from Mr. Buck's OpenGL book.

Here's the link: https://github.com/phishstang65/renderer

Was it helpful?

Solution

This looks to me like the texture coordinates for each triangle in the model are identical.

Looking at your code I think your vertex buffer is in the format of 40 bytes per vertex, each value is a GLFloat of two bytes, 3 for position, 3 for normal, 2 for texture coordinates, and 2 for a second set of texture coordinates.

I ran the app, with a breakpoint after it populates the data in the UtilityMesh object. Looking it a dump of the data in the debugger, there is a definite pattern that repeats every 40 bytes. The first 24 bytes for position and normals vary as expected. The last eight bytes are always 0, which I think correspond to the unused second set of texture coordinates. The problem is that the eight bytes corresponding to the primary texture coordinates cycles through three values.

00000000 00000000 
0000003d 0000803d 
00000000 0000803d

So I think your program is just fine, it's just getting bad data. Check your conversion process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top