我有一些基本代码来绘制各种多边形(在本例中为三角形):
#import "Triangle.h"
@interface Triangle() {
GLKBaseEffect * effect;
NSMutableData *vertexData;
int numVertices;
}
@property (nonatomic, strong) GLKBaseEffect * effect;
@property (nonatomic, assign) int numVertices;
@property (nonatomic, assign) GLKVector2 *vertices;
@end
@implementation Triangle
@synthesize effect;
@synthesize numVertices;
@synthesize vertices;
- (id)initWithEffect : (GLKBaseEffect *)effectPassed {
self.effect = effectPassed;
self.numVertices = 3;
self.vertices[0] = GLKVector2Make(0,0);
self.vertices[1] = GLKVector2Make(500, 0);
self.vertices[2] = GLKVector2Make(500, 500);
return self;
}
- (GLKVector2 *)vertices {
if (vertexData == nil)
vertexData = [NSMutableData dataWithLength:sizeof(GLKVector2)*self.numVertices];
return [vertexData mutableBytes];
}
-(void)render {
effect.useConstantColor = YES;
effect.constantColor = GLKVector4Make(1.0, 0.0, 0.1, 1.0);
[self.effect prepareToDraw];
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, self.vertices);
glDrawArrays(GL_TRIANGLE_FAN, 0, self.numVertices);
glDisableVertexAttribArray(GLKVertexAttribPosition);
}
@end
我想要做的是以某种方式在形状内放置一些文本。我正在考虑创建相同形状的纹理(也许使用 Quartz ?),然后在形状上使用此纹理。
任何人都可以建议这是否是实现这一目标的好方法,或任何其他建议?是否可以使用 Quartz 2D 创建屏幕外形状然后保存为 UIImage ?