Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6926399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:54:49+00:00 2026-05-27T10:54:49+00:00

I’m new to OpenGL/GLKit and having trouble with depth testing. The picture below shows

  • 0

I’m new to OpenGL/GLKit and having trouble with depth testing. The picture below shows a post with five beams intersecting it. They all meet in the middle (inside the post) but as you can see the parts of the beams that are meant to be obscured are still visible. They flicker like crazy and the same thing happens when I change the view so that the beams overlap on screen. If I don’t glEnable(GL_CULL_FACE) then it happens within each shape i.e. the backface of the rear polygons gets drawn and interferes with the front face of the front polygon.

enter image description here

Here are the code snippets that I think are relevant, I’ve left out the stuff about setting up the vertexes and the viewing angle. Hopefully someone will recognise the problem and there’s a silver bullet out there.

In my view controller

- (void)viewDidLoad
{
    [super viewDidLoad];    
    self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];    
    GLKView *view = (GLKView *)self.view;
    view.context = self.context;
    view.drawableDepthFormat = GLKViewDrawableDepthFormat24;

    [self setupGL];
}


- (void)setupGL
{

    [EAGLContext setCurrentContext:self.context];
    self.effect = [[GLKBaseEffect alloc] init];

    self.effect.lightModelAmbientColor = GLKVector4Make(0.5, 0.5, 0.5, 1);
    self.effect.colorMaterialEnabled = GL_TRUE;
    self.effect.light0.enabled = GL_TRUE;    
    self.effect.light0.position = GLKVector4Make(2, 4, -5, 1);    
    self.effect.material.shininess = 10.0;    
    self.effect.material.specularColor = GLKVector4Make(0.5, 0.5, 1, 1);    
    self.effect.lightingType = GLKLightingTypePerPixel;

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glDepthFunc(GL_LEQUAL);
}


- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{    
    glClearColor(0.2, 0.2, 0.2, 0.5);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    [self.effect prepareToDraw];
    [beams makeObjectsPerformSelector:@selector(draw)];    
    [post draw];

}

In Beam.m

-(void) draw
{
    self.effect.material.shininess = 15.0;    

    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 0, triangleVertices);

    glEnableVertexAttribArray(GLKVertexAttribColor);
    glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, 0, triangleColours);

    glEnableVertexAttribArray(GLKVertexAttribNormal);
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 0, triangleNormals);


    glDrawArrays(GL_TRIANGLES, 0, 48);

    glDisableVertexAttribArray(GLKVertexAttribPosition);
    glDisableVertexAttribArray(GLKVertexAttribColor);
    glDisableVertexAttribArray(GLKVertexAttribNormal);

}

I fully admit to being very new and inexperienced at this, so I’m quite open to constructive criticism if I’ve structured the app poorly.

Cheers,
Craig

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:54:49+00:00Added an answer on May 27, 2026 at 10:54 am

    The solution came from HannesSAK (http://www.iphonedevsdk.com/forum/iphone-sdk-development/5239-opengl-es-problem-depthbuffer-culling.html) it seems that setting zNear as 0.0f was my problem. I changed it to 1.0f and the image rendered correctly.

    self.effect.transform.projectionMatrix = GLKMatrix4MakePerspective(0.125*RADIANS, 2.0/3.0, 1.0f, 50.0f);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I used javascript for loading a picture on my website depending on which small
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.