Advertisement
agul

20141222 :: GrayScale (OpenGL)

Dec 22nd, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. void grayScale() {
  2.     if (fst) {
  3.         fst = false;
  4.         glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
  5.         uint count = Width * Height;
  6.         for (uint i = 0; i < count; ++i) {
  7.             double luminance = 0.3 * pixelData[i * 4] + 0.59 * pixelData[i * 4 + 1] + 0.11 * pixelData[i * 4 + 2];
  8.             pixelData[i] = static_cast<uchar>(luminance);
  9.         }
  10.     }
  11.     glDrawPixels(Width, Height, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixelData);
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement