将图像从c+加载到OpenGL ES中+;iPhone中的代码

将图像从c+加载到OpenGL ES中+;iPhone中的代码,iphone,uiimage,core-graphics,Iphone,Uiimage,Core Graphics,我正在创建一个iPhone游戏,需要将PNG文件中的图像加载到OpenGL(并将其绑定为纹理)。我使用函数glTexImage2D来实现这个目标 我知道如何使用UIImage将图像加载到OpenGL中(通过将其转换为CGImage,然后将其绘制到上下文中) 如何从C++代码中调用我的ObjuleC代码(我在.MM文件中编码)?< /P> 下面是我正在使用的代码,它将在Objective-C中工作: NSString *path = [[NSBundle mainBundle] pathForRe

我正在创建一个iPhone游戏,需要将PNG文件中的图像加载到OpenGL(并将其绑定为纹理)。我使用函数glTexImage2D来实现这个目标

我知道如何使用UIImage将图像加载到OpenGL中(通过将其转换为CGImage,然后将其绘制到上下文中)

如何从C++代码中调用我的ObjuleC代码(我在.MM文件中编码)?< /P> 下面是我正在使用的代码,它将在Objective-C中工作:

NSString *path = [[NSBundle mainBundle] pathForResource:@"texture" 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 );
    CGColorSpaceRelease( colorSpace );
    CGContextClearRect( context, CGRectMake( 0, 0, width, height ) );
    CGContextTranslateCTM( context, 0, 0 );
    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);
    [image release];
    [texData release];
<>有没有办法从C++代码中调用UI和核心图形函数?我必须包括哪些文件


提前谢谢。

解决了问题。必须手动查找并添加核心图形框架。

或者,右键单击框架组并选择“添加现有框架”,然后从列表中选择核心图形。