1
votes

I'm writing a 3D Viewer that displays .obj file and offers some basic gestures (pinning, rotating, zooming) by following 2 Raywenderlich tutorials: http://www.raywenderlich.com/48293/how-to-export-blender-models-to-opengl-es-part-1

http://www.raywenderlich.com/50398/opengl-es-transformations-gestures

I'm able to load and display correctly small .obj files but for big .obj files, the textures become suddenly transparent ! I have tested with the same texture files so I think the image size is not the cause. Please take a look at the below screenshot to have an idea:

Big obj: about 20000 vertices Big obj: about 20000 vertices

Small obj: about 5000 vertices: Small obj: about 5000 vertices

Quite big obj: about 67000 vertices: Quite big obj: about 67000 vertices

A texture bitmap with only 2 colors (blue and yellow) which are used in big and quite big objs A texture bitmap with only 2 colors (blue and yellow) which are used in big objs

The capsule texture (I don't use the 2 colors texture so that we can see clearly there is no transparency in the small obj) The capsule texture

I have tried different textures on different obj and it's always the same problem: the texture starts to be transparent when the obj file is big. I have also tested on different physical Iphone so it's not specific to the simulator. Enable/disable gl_blend doesn't solve the problem neither.

You can find the full code at http://pastecode.org/index.php/view/32247978 Here is the code I use to create the GLKBaseEffect and load texture image:

// Initialize
self.effect = [[GLKBaseEffect alloc] init];

// Texture
NSDictionary* options = @{ GLKTextureLoaderOriginBottomLeft: @YES };
NSError* error;
NSString* path = [[NSBundle mainBundle] pathForResource:@"capsule0.jpg" ofType:nil];

GLKTextureInfo* texture = [GLKTextureLoader textureWithContentsOfFile:path
                                                              options:options
                                                                error:&error];

if(texture == nil)
    NSLog(@"Error loading file: %@", [error localizedDescription]);

self.effect.texture2d0.name = texture.name;
self.effect.texture2d0.enabled = true;
self.effect.texture2d0.envMode = GLKTextureEnvModeReplace;


// Light
self.effect.light0.enabled = GL_TRUE;
self.effect.light0.position = GLKVector4Make(1.0f, 1.0f, 1.0f, 1.0f);
self.effect.lightingType = GLKLightingTypePerVertex;

And this part is for setting up OpenGL in viewDidLoad() after creating the effect:

// OpenGL ES Settings
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
1
Can you post any better images with proper texture to guess it clearly. It is tuff to guess with above textures. Either culling or normals should be the problem. - VivekParamasivam
@GoodnezEverywer: I just uploaded the texture pictures used in the 3 models - Son
Disable culling and verify whether it fixes. If it fixes the issue, then some of the normals in the mesh would have flipped, so you need fix the normal calculation. - VivekParamasivam
Thanks for your help. Finally it is just a Xcode config for GLKView and enabling the depth for OpenGL ... - Son

1 Answers

0
votes

I have finally found the solution:

First, you need to set the depth format to 24 or 16 in the storyboard for the GLKView: enter image description here

Then enable the depth in viewDidLoad() by

    glEnable(GL_DEPTH_TEST);

And finally for each draw call, you need to clear the depth buffer:

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);