【发布时间】:2014-05-21 21:22:58
【问题描述】:
我正在使用 GLKit 创建一个视图以在 iOS 中试验 opengl。视图有如下加载方式:
- (void)viewDidLoad
{
[super viewDidLoad];
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!self.context) {
NSLog(@"Failed to create ES context");
}
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[EAGLContext setCurrentContext:self.context];
self.effect = [[GLKBaseEffect alloc] init];
}
在一个形状的绘制方法中,我有以下代码:
float vertices[] = {
-1, -1,
1, -1,
0, 1};
glEnableVertexAttribArray(GLKVertexAttribPosition);
glColor4f(0.0, 1.0, 0.0, 1.0);
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glDrawArrays(GL_TRIANGLES, 0, sizeof(vertices));
glDisableVertexAttribArray(GLKVertexAttribPosition);
此代码将在屏幕中心绘制一个三角形,但该三角形是白色的。我用glColor4f(0.0, 1.0, 0.0, 1.0) 将当前颜色设置为绿色,但这不会改变当前的绘图颜色。如何更改三角形的颜色?
【问题讨论】: