views:

22

answers:

2

Ok guys, so I am drawing charts in OpenGL for Iphone. And everything is ok, until I use that Texture2D class to draw X axis labels and Y axis labels. The function of drawing labels is executing at each frame which I think is time consuming. In order to solve animation slowing, I have 2 ideas, but I still can't find how could I implement them: 1. Draw the Labels 1 time, but next time just reuse them, reuse the matrix or the textures, if there is any possibility (sorry I am a newbie, I may write some not adequate stuff); 2. When cleaning the buffer (glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) clean just a part of the screen, not the whole Rendering scene, I would also be very happy to know if there is any possibility to clear not the whole screen but the drawn objects (for example in the Column chart, to clear just the columns, not the background and not the Labels, or lengend). I would appreciate very much your help.

A: 

Things will be much simpler and go far more smoothly if you clear the full render buffer every time. Just pre-render the axes into a single texture and render the texture on each pass.

Marcelo Cantos
By clearing render buffer did you mean clearing frame and depth buffer (glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)). If so than I do clear them on every frame. How do I pre-render the axes into a single texture. Sorry, could you please provide more details, with some code example? I will mention you that I am using Texture2D class to draw Labels. Here is how I do it:
Oleg Danu
+1  A: 
    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);
Oleg Danu