1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| GLuint CaptureScreen(int width, int height, std::function<void()> foo) { foo(); unsigned char * screenPixel = new unsigned char[width*height*3]; glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, screenPixel); GLuint texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, screenPixel); glBindTexture(GL_TEXTURE_2D, 0); delete screenPixel; return texture; }
|