0
OpenGLESを使用してiOSにバナナを表示しようとしています。私はすべてが正しく設定されていることを確信していますが、アプリが起動するとバナナが正しく描画されていません。OpenGLES 3三角形で表示され、塗りつぶされていないiOSオブジェクト
私が表示しようとしているバナナオブジェクトは、obj2openglで提供されているサンプルbanana.hからです。ここで
App running on iPhone 5 simulator
セットアップです:
- (void)setupGL {
[EAGLContext setCurrentContext:self.context];
[self loadShaders];
glEnable(GL_BLEND);
self.effect = [[GLKBaseEffect alloc] init];
self.effect.light0.enabled = GL_TRUE;
self.effect.light0.diffuseColor = GLKVector4Make(1.0f, 0.4f, 0.4f, 1.0f);
glGenVertexArrays(1, &_vertexArray);
glBindVertexArray(_vertexArray);
glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(bananaVerts), bananaVerts, GL_STATIC_DRAW);
glGenBuffers(1, &_textureCoords);
glBindBuffer(GL_ARRAY_BUFFER, _textureCoords);
glBufferData(GL_ARRAY_BUFFER, sizeof(bananaTexCoords), bananaTexCoords, GL_STATIC_DRAW);
//Vertex attribute
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 0,0);
glEnableVertexAttribArray(GLKVertexAttribPosition);
// Normal attribute
/*glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 0,0);
glEnableVertexAttribArray(GLKVertexAttribNormal);*/
// TexCoord attribute
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
[self loadTexture];
glBindVertexArray(0);
}
そして、これは、描画方法である:
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self calculateMatrices];
glUseProgram(_program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _texture.name);
glUniform1i(glGetUniformLocation(_program, "texture1"), 0);
glUniformMatrix4fv(glGetUniformLocation(_program, "viewMatrix"), 1, GL_FALSE, _modelViewMatrix.m);
glUniformMatrix4fv(glGetUniformLocation(_program, "projectionMatrix"), 1, GL_FALSE, _projectionMatrix.m);
glBindVertexArray(_vertexArray);
glDrawArrays(GL_TRIANGLE_STRIP, 0, bananaNumVerts);
}
バーテックスシェーダ:
attribute vec3 position;
attribute vec2 texCoord;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
varying vec2 TexCoord;
varying vec3 vNormal;
void main()
{
gl_Position = viewMatrix * projectionMatrix * vec4(position, 1.0);
TexCoord = vec2(texCoord.x, 1.0 - texCoord.y);
}
フラグメントS hader:
precision mediump float;
varying vec2 TexCoord;
uniform sampler2D texture1;
void main()
{
gl_FragColor = texture2D(texture1, TexCoord);
}
EDIT:
私はglVertexAttribPointer
のご使用は間違っ見え
GL_LINES
代わりの
GL_TRIANGLES.
これを指摘してくれてありがとう。私はそれを修正したが、問題はまだ残っている。 – ModGod