好的伙计们,所以我正在使用OpenGL for Iphone绘制图表。一切都很好,直到我使用Texture2D类绘制X轴标签和Y轴标签。绘图标签的功能正在每帧执行,我认为这是耗时的。为了解决动画减速问题,我有2个想法,但我仍然无法找到如何实现它们: 1.绘制标签1次,但下次只重用它们,重复使用矩阵或纹理,如果有可能(对不起我是新手,我可能会写一些不够的东西); 2.清洁缓冲区时(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT))只清除屏幕的一部分,而不是整个渲染场景,我也很高兴知道是否有可能清除整个屏幕而不是绘制对象(例如在柱形图中,仅清除列,而不是背景而不是标签或lengend)。 我非常感谢你的帮助。
答案 0 :(得分:2)
glLoadIdentity(); // Added line
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
NumberFormatter *lFormater = [[NumberFormatter alloc] init];
int i = 0;
for (NSNumber *lNumber in mColXLabelCoord) {
NSNumber *lUnformated = [NSNumber numberWithInteger:[[NSString stringWithString:[mColYLabelsArray objectAtIndex:i]] integerValue]];
NSString *lFormated = [NSString stringWithString:[lFormater stringFromNumber:lUnformated withMask:[[mGraphArray objectAtIndex:0] mGraphMask]]];
Texture2D* lWord= [[Texture2D alloc] initWithString:lFormated dimensions:CGSizeMake(40, 15) alignment:UITextAlignmentLeft fontName:@"Helvetica" fontSize:13];
glColor4f(RedFromRGB(0xFFFFFF), GreenFromRGB(0xFFFFFF), BlueFromRGB(0xFFFFFF), 1.0);
[lWord drawInRect:CGRectMake([lNumber floatValue]+2, 470,40,15) rotation:-90];
[lWord release];
i++;
}
[lFormater release];
i = [mColYCoord count]-1;
for (NSNumber *lNumber in mColYCoord) {
Texture2D* lWord= [[Texture2D alloc] initWithString:[NSString stringWithFormat:((GraphValue*)[mGraphValuesArray objectAtIndex:i]).mGraphValueXLabel,[lNumber floatValue]]
dimensions:CGSizeMake(40, 15)
alignment:UITextAlignmentCenter
fontName:@"Helvetica" fontSize:12];
if ([mColYCoord count] < kOptimalLabelNumber) {
glColor4f(RedFromRGB(0xFFFFFF), GreenFromRGB(0xFFFFFF), BlueFromRGB(0xFFFFFF), 1.0);
[lWord drawInRect:CGRectMake(10, [lNumber floatValue]+15, 40, 15) rotation:-90];
}else {
glColor4f(RedFromRGB(0xFFFFFF), GreenFromRGB(0xFFFFFF), BlueFromRGB(0xFFFFFF), 1.0);
[lWord drawInRect:CGRectMake(2, [lNumber floatValue]+5, 40, 15) rotation:-30];
}
[lWord release];
i--;
}
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
答案 1 :(得分:0)
如果每次都清除完整的渲染缓冲区,事情会变得更简单并且更加顺利。只需将轴预渲染为单个纹理,然后在每次传递时渲染纹理。