I am just starting to work with OpenGL ES and need some help. I am trying to load a .obj model into my game and have problems with how the the model renders. I narrowed it down to the depth buffer probelm
The mesh I am trying to render has some surfaces within the object. Like in this example.
The problem is that the faces within the object don’t get filtered by the depth buffer test, instead they are rendered as normal front faces.
0.) Is such mash considered as invalid?
1.) How come that blender seams to have no problems with this issue?
2.) Any suggestions on how to fix this? There were some indications about the problem with depth precision.
ok : the code you showed looks correct.
But you have to show more code : the part that creates the GL window or image or surface or whatever it is called in GL ES.
/* Init the SDL library, this provides graphics, audio, keyboard etc */
result = SDL_Init(SDL_INIT_EVERYTHING);
assert(result == 0);
/* Create a screen 'image' and make it full screen */
screen = SDL_SetVideoMode(IMAGE_WIDTH * 2, IMAGE_HEIGHT * 2, 0, SDL_HWSURFACE | SDL_FULLSCREEN);
assert(screen);
/* Give it an appropriate title and icon when it gets minimised*/
SDL_WM_SetCaption("OpenGL Grid", "OpenGL Grid");
SDL_ShowCursor(SDL_DISABLE);
/* Init the SDL Gles library */
result = SDL_GLES_Init(SDL_GLES_VERSION_2_0);
assert(result == 0);
/* Create the render context */
context = SDL_GLES_CreateContext();
assert(context);
/* Makes the rendering context we just created current */
result = SDL_GLES_MakeCurrent(context);
assert(result == 0);
/* Prepare the shader were going to use, and init the opneGL */
Init();
Try setting SDL_GLES_Attr with SDL_GLES_DEPTH_SIZE to 24 (for 24 bits of depth precision) or 16 if your platform can not handle more precision.
/** Sets a specific context attribute (before calling SDL_CreateContext()).
@param attr attribute to set
@param value new value
@return 0 if the attribute exists, -1 otherwise.
*/
extern DECLSPEC int SDLCALL SDL_GLES_SetAttribute(SDL_GLES_Attr attr, int value);
It was exactly this. I only needed to set the Depth Buffer to the context.
...
/*Set Depth Buffer to your context*/
SDL_GLES_SetAttribute(SDL_GLES_DEPTH_SIZE, 24);
...
I also edited my OpenGL configuration, but am not suer if it affects anything. I will post it in case someone will want to compare with what they have.
/* Configure the Open GL renderer */
/*Enable back face culling*/
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
/* Depth buffer setup */
glClearDepthf( 1.0f );
/* Enables Depth Testing */
glEnable( GL_DEPTH_TEST );
/* The Type Of Depth Test To Do */
glDepthFunc( GL_LEQUAL );
/* Set the background color*/
glClearColor(0.3, 0.5, 0.5, 0.1);
/*Set viewport*/
glViewport(0, 0, screen->w, screen->h);
Now the models are rendering as they should. Thank you very much for your help. Here is the result.
Does the forum have any rating system, where I could rate your help.