相关疑难解决方法(0)

翻转OpenGL纹理

当我正常加载图像中的纹理时,由于OpenGL的坐标系统,它们是颠倒的.翻转它们的最佳方法是什么?

  • glScalef(1.0f,-1.0f,1.0f);
  • 反向映射纹理的y坐标
  • 手动垂直翻转图像文件(在Photoshop中)
  • 加载后以编程方式翻转它们(我不知道怎么做)

这是我在Utilities.m文件(Objective-C)中用来加载png纹理的方法:

+ (TextureImageRef)loadPngTexture:(NSString *)name {
    CFURLRef textureURL = CFBundleCopyResourceURL(
                                                  CFBundleGetMainBundle(),
                                                  (CFStringRef)name,
                                                  CFSTR("png"),
                                                  CFSTR("Textures"));
    NSAssert(textureURL, @"Texture name invalid");

    CGImageSourceRef imageSource = CGImageSourceCreateWithURL(textureURL, NULL);
    NSAssert(imageSource, @"Invalid Image Path.");
    NSAssert((CGImageSourceGetCount(imageSource) > 0), @"No Image in Image Source.");
    CFRelease(textureURL);

    CGImageRef image = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
    NSAssert(image, @"Image not created.");
    CFRelease(imageSource);

    GLuint width = CGImageGetWidth(image);
    GLuint height = CGImageGetHeight(image);

    void *data = malloc(width * height * 4);

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    NSAssert(colorSpace, @"Colorspace not created.");

    CGContextRef context = CGBitmapContextCreate(
                                                 data, …
Run Code Online (Sandbox Code Playgroud)

opengl macos textures image objective-c

7
推荐指数
1
解决办法
5076
查看次数

标签 统计

image ×1

macos ×1

objective-c ×1

opengl ×1

textures ×1