質問

私はOpenGL/Glkitを初めて使用し、深度テストに問題があります。下の写真は、5つのビームが交差する投稿を示しています。それらはすべて(投稿の内側)に会いますが、あなたが見ることができるように、不明瞭になるように意図されたビームの部分はまだ見えます。彼らはクレイジーのようにちらつき、ビューを変更して画面上でオーバーラップするようにビューを変更すると同じことが起こります。 Glenable(gl_cull_face)がglenableしない場合、各形状内で発生します。つまり、リアポリゴンのバックフェイスが描画され、フロントポリゴンの前面に干渉します。

enter image description here

ここに私が関連していると思うコードスニペットは、Vertexesとviewing Angleをセットアップすることについて除外しました。うまくいけば、誰かが問題を認識し、そこに銀の弾丸があります。

私のビューコントローラーで

- (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];

}

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);

}

私はこれに非常に新しくて経験の浅いことを完全に認めているので、アプリをうまく構成していれば、建設的な批判を非常にオープンにしています。

乾杯、クレイグ

役に立ちましたか?

解決

解決策は、hannessak(http://www.iphonedevsdk.com/forum/iphone-sdk-development/5239-opengl-es-problem-depthbuffer-culling.html)から来ました。 1.0Fに変更し、画像が正しくレンダリングされました。

self.effect.transform.projectionMatrix = GLKMatrix4MakePerspective(0.125*RADIANS, 2.0/3.0, 1.0f, 50.0f);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top