私は、OpenGLES 2.0について学ぶために簡単なiOSアプリケーションを開発しています。このプロジェクトでは、ピラミッドの頂点の高さを調整するためのスライダーとy軸の周りのmodalViewMatrixを回転させるために、4つの三角形をピラミッドの形でレンダリングしています。このオブジェクトを反時計回りに三角形が他の三角形の前に現れる点まで回転させた後、私は三角形の近くを見ることができる理由を見つけようとしています。しかし、時計回りに同じ点に回転すると、近くの三角形は不透明で最も遠い三角形を塞いでしまいます。GLKitで三角形を見る
私は理由が深さレンダリングバッファが不足していると仮定しましたが、プロパティーを設定した後には、view.drawableDepthFormat = GLKViewDrawableDepthFormat16;
の動作は持続します。
参考のために、これは私のdrawRect関数で描画が行われます。他のコードはviewDidLoadとxcodeプロジェクトのグローバルスコープでのみ実行されます。
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
[self.baseEffect prepareToDraw];
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindBuffer(GL_ARRAY_BUFFER,pos);
glEnableVertexAttribArray(GLKVertexAttribPosition);
const GLvoid * off1 = NULL + offsetof(SceneVertex, position) ;
glVertexAttribPointer(GLKVertexAttribPosition, // Identifies the attribute to use
3, // number of coordinates for attribute
GL_FLOAT, // data is floating point
GL_FALSE, // no fixed point scaling
sizeof(SceneVertex), // total num bytes stored per vertex
off1);
glEnableVertexAttribArray(GLKVertexAttribNormal);
const GLvoid * off2 = NULL + offsetof(SceneVertex, normal) ;
glVertexAttribPointer(GLKVertexAttribNormal, // Identifies the attribute to use
3, // number of coordinates for attribute
GL_FLOAT, // data is floating point
GL_FALSE, // no fixed point scaling
sizeof(SceneVertex), // total num bytes stored per vertex
off2);
GLenum error = glGetError();
if(GL_NO_ERROR != error)
{
NSLog(@"GL Error: 0x%x", error);
}
int sizeOfTries = sizeof(triangles);
int sizeOfSceneVertex = sizeof(SceneVertex);
int numArraysToDraw = sizeOfTries/sizeOfSceneVertex;
glDrawArrays(GL_TRIANGLES, 0, numArraysToDraw);
}
深度テストと深度書き込みを有効にして、深度テストをどこに設定していますか?また、裏面のカリングを無効にして、それが違いを生むかどうかを確認することもできます(glDisable(GL_CULL_FACE)) – Columbo
奥行きバッファに関する唯一の行はdrawableDepthFormatプロパティの設定です。 GLKViewにも設定できるブール値はどこですか? –