Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opengl Fbo纹理将翻转/旋转_Opengl_Fbo - Fatal编程技术网

Opengl Fbo纹理将翻转/旋转

Opengl Fbo纹理将翻转/旋转,opengl,fbo,Opengl,Fbo,我通过fbo拍了几张照片。然后,我重用这些图像,向它们添加一些内容(使用fbo和着色器)。现在,由于某种原因,图像被旋转了,我不知道它发生在哪里 下面是一些可能与bug有关的代码。我可以根据要求提供更多的代码 我这样保存图像: glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); int bpp = 4; // Assuming a 32-bit display with a byte each for red, green, blue, and

我通过fbo拍了几张照片。然后,我重用这些图像,向它们添加一些内容(使用fbo和着色器)。现在,由于某种原因,图像被旋转了,我不知道它发生在哪里

下面是一些可能与bug有关的代码。我可以根据要求提供更多的代码

我这样保存图像:

glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
            int bpp = 4; // Assuming a 32-bit display with a byte each for red, green, blue, and alpha.
            ByteBuffer buffer = BufferUtils.createByteBuffer(SAVE_WIDTH * SAVE_HEIGHT * bpp);
            glReadPixels(0, 0, SAVE_WIDTH, SAVE_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, buffer );

            File file = new File("picture" + k + ".png"); // The file to save to.
            String format = "png"; // Example: "PNG" or "JPG"
            BufferedImage image = new BufferedImage(SAVE_WIDTH, SAVE_HEIGHT, BufferedImage.TYPE_INT_ARGB);

            for(int x = 0; x < SAVE_WIDTH; x++)
                for(int y = 0; y < SAVE_HEIGHT; y++)
                {
                        int i = (x + (SAVE_WIDTH * y)) * bpp;
                        int r = buffer.get(i) & 0xFF;
                        int g = buffer.get(i + 1) & 0xFF;
                        int b = buffer.get(i + 2) & 0xFF;
                        int a = buffer.get(i + 3) & 0xFF;
                        image.setRGB(x, SAVE_HEIGHT - (y + 1), (a << 24) | (r << 16) | (g << 8) | b);
                }


            try {
                ImageIO.write(image, format, file);
            } catch (IOException e) { 
                e.printStackTrace(); 
            }
  ByteBuffer buf = null;
        File file = new File(filename);

        if (file.exists()) {

            try {
                BufferedImage image = ImageIO.read(file);

                buf = Util.getImageDataFromImage(image);
            } catch (IOException ex) {
                Logger.getLogger(SkyBox.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            int length = SAVE_WIDTH * SAVE_HEIGHT * 4;
            buf = ByteBuffer.allocateDirect(length);
            for (int i = 0; i < length; i++)
                buf.put((byte)0xFF);
            buf.rewind();
        }

        // Create a new texture object in memory and bind it
        glBindTexture(GL_TEXTURE_2D, pictureTextureId);

        // All RGB bytes are aligned to each other and each component is 1 byte
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

        // Upload the texture data and generate mip maps (for scaling)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SAVE_WIDTH, SAVE_HEIGHT, 0, 
                        GL_RGBA, GL_UNSIGNED_BYTE, buf);    

        // Setup what to do when the texture has to be scaled
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 
                        GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
                        GL_NEAREST);
glReadBuffer(GL\u COLOR\u ATTACHMENT0\u EXT);
int bpp=4;//假设32位显示,红色、绿色、蓝色和alpha各有一个字节。
ByteBuffer buffer=BufferUtils.createByteBuffer(保存宽度*保存高度*bpp);
glReadPixels(0,0,保存宽度,保存高度,GL\u RGBA,GL\u无符号字节,缓冲区);
File File=新文件(“图片”+k+“.png”);//要保存到的文件。
字符串格式=“png”;//示例:“PNG”或“JPG”
BuffereImage=新的BuffereImage(保存宽度、保存高度、BuffereImage.TYPE\u INT\u ARGB);
对于(int x=0;ximage.setRGB(x,保存高度-(y+1),(a旋转,或垂直翻转?如果它们被翻转,那是因为OpenGL和图像文件格式不一定在坐标系的原点上一致。对于OpenGL和通常的投影设置,原点在左下角。大多数图像文件格式和IO库假定原点在左上角

    WritableRaster wr = bufferedImage.getRaster();
    DataBuffer db = wr.getDataBuffer();
    DataBufferByte dbb = (DataBufferByte) db;
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(dbb.getData().length);

    byte[] bytes = dbb.getData();

    for(int i=0; i<bytes.length; i+=4) {
        byteBuffer.put(bytes[i+3]);
        byteBuffer.put(bytes[i+2]);
        byteBuffer.put(bytes[i+1]);
        byteBuffer.put(bytes[i]);
    }

    byteBuffer.flip();
    return byteBuffer;