Advertisement
pushrbx

Pixel copy Opengl DIB

Apr 19th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. void CopyPBufferToImage(int width, int height)
  2. {
  3.     // Copy the contents of the framebuffer - which in our case is our pixel buffer -
  4.     // to our bitmap image (dummy target) in local system memory. Notice that we also need
  5.     // to invert the pbuffer's pixel data since OpenGL by default orients the
  6.     // bitmap image bottom up. Our Windows DIB wrapper expects images to be
  7.     // top down in orientation.
  8.  
  9.     static BYTE *pixels = new BYTE[width * height * 4];
  10.     memset(pixels, 0, width * height * 4);
  11.  
  12.     glPixelStorei(GL_PACK_ALIGNMENT, 1);
  13.     glReadPixels(0, 0, width, height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
  14.  
  15.     for (int i = 0; i < height; ++i)
  16.     {
  17.         memcpy(&m_img.pPixels[m_img.pitch * i],
  18.             &pixels[((height - 1) - i) * (width * 4)],
  19.             width * 4);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement