我在SDL库的帮助下创建了我的opengl窗口的屏幕截图,但它全是黑色的,我不明白为什么。如何解决?
代码:
SDL_Surface * image = SDL_CreateRGBSurface(SDL_SWSURFACE, current_w, current_h, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0);
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, current_w, current_h, GL_RGB, GL_UNSIGNED_BYTE, image->pixels);
SDL_SaveBMP(image, "pic.bmp");
SDL_FreeSurface(image);
答案 0 :(得分:2)
我已经看到你已经找到了删除glReadBuffer的调用,而对于垂直翻转,你可以从http://lists.libsdl.org/pipermail/sdl-libsdl.org/2005-January/047965.html获取此函数:
SDL_Surface* flipVert(SDL_Surface* sfc)
{
SDL_Surface* result = SDL_CreateRGBSurface(sfc.flags, sfc.w, sfc.h,
sfc.format.BytesPerPixel * 8, sfc.format.Rmask, sfc.format.Gmask,
sfc.format.Bmask, sfc.format.Amask);
ubyte* pixels = cast(ubyte*) sfc.pixels;
ubyte* rpixels = cast(ubyte*) result.pixels;
uint pitch = sfc.pitch;
uint pxlength = pitch*sfc.h;
assert(result != null);
for(uint line = 0; line < sfc.h; ++line) {
uint pos = line * pitch;
rpixels[pos..pos+pitch] =
pixels[(pxlength-pos)-pitch..pxlength-pos];
}
return result;
}