pixelStorei(gl.UNPACK_FLIP_Y_WEBGL,true);

sam*_*b90 3 javascript xcode objective-c webgl ios

如果使用OpenGL ES,我一直试图找出相应的行,UNPACK_FLIP_Y_WEBGL.我一直无法找到解决方案.

有人可以帮我找一个等价的吗?

问候

gma*_*man 9

它在ES 2.0中不存在.

解决方案从最好到最差

  1. 在编译时翻转图像.

    这是专业人士所做的.为什么浪费内存和代码以及为什么让用户等待翻转图像,如果你不需要?

  2. 将图像上下颠倒,(libpng有该选项)

  3. 装载后翻转.

    假设每个通道图像有一个RGBA 8比特,那么要翻转的代码是类似的

     void flipInPlace(unsigned char* data, int width, int height) {
       size_t line_size = width * 4;
       unsigned char* line_buffer = new unsigned char[line_size];
       int half_height = height / 2
       for (int y = 0; y < halfHeight) {
         void* top_line = data + y * line_size;
         void* bottom_line = data + (height - y - 1) * line_size;
         memcpy(line_buffer, top_line, line_size);
         memcpy(top_line, bottom_line, line_size);
         memcpy(bottom_line, line_buffer, line_size);
       }
       delete [] line_buffer;
     }
    
    Run Code Online (Sandbox Code Playgroud)