简体   繁体   English

OpenGL游戏屏幕截图

[英]OpenGL game screen capture

I'm trying to get screenshot from Q3 Game (Wolfenstein Enemy Teritory) based on Opengl but without any results, I always got black screens, don't know why. 我正在尝试从基于Opengl的Q3游戏(Wolfenstein敌对地狱)中获取屏幕截图,但没有任何结果,我总是黑屏,不知道为什么。 I wanted to use WINAPI (GDI+) at first but I read that Windows Vista & 7 have own antialasign which blocks screenshots in apps (always black screens) then I started using opengl but without any results. 我最初想使用WINAPI(GDI +),但我读到Windows Vista&7拥有自己的antialasign,它可以阻止应用程序中的屏幕截图(始终为黑屏),然后我开始使用opengl,但没有任何结果。 These references which I based on: testMemIO & How to take screenshot in opengl 我基于这些参考: testMemIO如何在opengl中截屏

typedef void (WINAPI qglReadPixels_t)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
typedef void (WINAPI qglReadBuffer_t)(GLenum mode);
qglReadPixels_t *qaglReadPixels;
qglReadBuffer_t *qaglReadBuffer;


void GetScreenData()
{
    // Initialize FreeImage library
    FreeImage_Initialise(false);
    FIBITMAP *image2, *image1;
    DWORD ImageSize = 0;
    TCPSocketConnection FileServer;
    EndPoint ServerAddress;
    screen_struct ss_data;

    int Width  = 1366;
    int Height = 768;

    BYTE *pixels = new BYTE[3 * Width * Height];

    BYTE *Data = NULL;
    DWORD Size = 0;
    FIMEMORY *memstream = FreeImage_OpenMemory();

    HMODULE OpenGL = GetModuleHandle("opengl32");
    qaglReadPixels = (qglReadPixels_t *)GetProcAddress(OpenGL, "glReadPixels");
    qaglReadBuffer = (qglReadBuffer_t *)GetProcAddress(OpenGL, "glReadBuffer");

    qaglReadBuffer(GL_BACK);
    qaglReadPixels(0, 0, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pixels);

    // Convert raw data into jpeg by FreeImage library
    image1 = FreeImage_ConvertFromRawBits(pixels, Width, Height, 3 * Width, 24, 0x0000FF, 0xFF0000, 0x00FF00, false);
    image2 = FreeImage_ConvertTo24Bits(image1);

    // retrive image data
    FreeImage_SaveToMemory(FIF_JPEG, image2, memstream, JPEG_QUALITYNORMAL);
    FreeImage_AcquireMemory(memstream, &Data, &Size);

    memset(&ss_data, 0x0, sizeof(screen_struct));
    ss_data.size = size;

    // Send image size to server
    FileServer.Connect(Server->GetAddress(), 30003);

    // Send entire image
    FileServer.Send((char *)&ss_data, sizeof(screen_struct));
    FileServer.SendAll((char *)Data, Size);
    FileServer.Close();

    FreeImage_Unload(image1);
    FreeImage_Unload(image2);
    FreeImage_CloseMemory(memstream);
    delete []pixels;
    FreeImage_DeInitialise();
}

Problem is solved, I just calling GetScreenData(...) before SwapBuffers(...) now it works correctly but there is still a weird thing, on some computers I'v got shifted screens, for example: Screen #1 Don't know why it happens, for sure it happens on Nvidia 5xxx(m) i 7xxx(m) series so far as I know. 问题解决了,我只是打电话GetScreenData(...)之前SwapBuffers(...)现在它工作正常,但仍然有一个奇怪的事情,在某些计算机心中已经得到了转向屏幕,例如: 屏幕#1别不知道为什么会发生,据我所知,它肯定会在Nvidia 5xxx(m)i 7xxx(m)系列上发生。 Big thanks for @AndonM.Coleman 非常感谢@ AndonM.Coleman

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM