2012-01-14 19 views
1

実行時にプログラムで作成したイメージをテクスチャとして使用する必要がありますが、あるポイントから別のポイントへ移動する方法がわかりません。作られた画像)(UIGraphicsBeginImageContextwithOptionsであり、そして以下の私のプロジェクトの画像からテクスチャをロードするための私の現在のコードです:OpenGLでUIGraphicsBeginImageContextWithOptions()で作成したイメージを使用する方法

-(void)loadTextures:(NSString*) filename textureIdentifier:(int) textureNumber { 

    //enable textures. 
    glEnable(GL_TEXTURE_2D); 
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_FASTEST); 
    glEnable(GL_BLEND); 
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 

    // Bind the number of textures we need. 
    glGenTextures(1, &texture[textureNumber]); 
    glBindTexture(GL_TEXTURE_2D, texture[textureNumber]); 
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); 
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); 
    glTexParameterf(GL_TEXTURE_2D,GL_GENERATE_MIPMAP,GL_TRUE);  
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); 
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); 


    NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"png"]; 
    NSData *texData = [[NSData alloc] initWithContentsOfFile:path]; 
    UIImage *image = [[UIImage alloc] initWithData:texData]; 

    if (image == nil) 
     NSLog(@"Do real error checking here"); 

    GLuint width = CGImageGetWidth(image.CGImage); 
    GLuint height = CGImageGetHeight(image.CGImage); 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    void *imageData = malloc(height * width * 4); 
    CGContextRef context = CGBitmapContextCreate(imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); 

    // Flip the Y-axis 
    CGContextTranslateCTM (context, 0, height); 
    CGContextScaleCTM (context, 1.0, -1.0); 

    CGColorSpaceRelease(colorSpace); 
    CGContextClearRect(context, CGRectMake(0, 0, width, height)); 
    CGContextDrawImage(context, CGRectMake(0, 0, width, height), image.CGImage); 

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); 

    CGContextRelease(context); 

    free(imageData); 
} 

答えて

1

簡単。テクスチャローダコードからこれらの行を削除し、あなたのコアグラフィックス描画コードに置き換える:

UIImage *image = [[UIImage alloc] initWithData:texData]; 

と::

UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 

NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"png"]; 
NSData *texData = [[NSData alloc] initWithContentsOfFile:path]; 

は今、この行を置き換えます

関連する問題