Cocoa Design Patterns
Learning OpenGL ES for iOS
Presentations
Buy at Amazon Now
  • Cocoa Design Patterns
    Cocoa Design Patterns
    by Erik M. Buck, Donald A. Yacktman
  • Learning OpenGL ES for iOS: A Hands-on Guide to Modern 3D Graphics Programming
    Learning OpenGL ES for iOS: A Hands-on Guide to Modern 3D Graphics Programming
    by Erik M. Buck

Errata > Chapter 5 loading from .obj file

Hi, I'm making amzing headway through this great book and am trying to load a different .obj file following along with the sphere example in chapter 5.

I have tried both ways to create the .h file using the examples provided and although I can load and see the model it look as though I may be viewing it from behind and so I see all the triangles and a slight bit of colour showing through from what I guess is the front?

I have the .h file and the .png texture file if someone would like to see it. I cannot see where I am going wrong and have tried many things from using flipped z to no flipped z to use gl_blend, depth test etc...

Help any one...sorry did not know where else to post this?
August 31, 2013 | Unregistered CommenterPaul
The usual causes for what you are seeing are lack of a depth buffer, not turning on depth testing, or culling the "wrong" faces. The order of the vertices in a triangle determines which face is front and which is back. If all of your triangles are back facing and back face culling is turned on, you won't see the outside of a polygon: you'll see the inside.

I don't actually recommend using the .obj to .h technique for importing models even though Apple likes it. Keep reading. Alternative and more flexible ways for loading models are introduced in subsequent chapters.
September 2, 2013 | Registered CommenterErik Buck
Hi Eric, thanks for reply. Yes I have seen that a few chapters away is a way to import models but at this point I was experimenting to see if I could replicate your example but with a different model.

I do have the depth buffer enabled and have tried all variations such as:

glEnable(GL_DEPTH_TEST);

or

glDisable(GL_CULL_FACE);

or

glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);
glCullFace(GL_BACK);

or

glEnable(GL_CULL_FACE);
glFrontFace(GL_CW);
glCullFace(GL_BACK);

all produce the weird result.

but if as you say you suggest the other method I'll have to wait, just want to encourage myself by importing a different model whilst in chapter 5 ;-)
September 2, 2013 | Unregistered CommenterPaul
If you like, email the .obj model to me (erik.buck@sbcglobal.net) and I'll give it a try.
September 2, 2013 | Registered CommenterErik Buck
Thanks Erik I have emailed the details to you, but just to acknowledge on this thread I have read further into the book (well skipped ahead) and read the part where you say .obj can lose important information so it might well be the case that this is the cause of the problem....although you may find otherwise lol

Thanks

Paul
September 3, 2013 | Unregistered CommenterPaul