gpt4 book ai didi

c++ - OpenGL 游戏截屏

转载 作者:太空宇宙 更新时间:2023-11-04 13:49:48 25 4
gpt4 key购买 nike

我正在尝试从基于 Opengl 的 Q3 游戏(Wolfenstein Enemy Teritory)中获取屏幕截图,但没有任何结果,我总是黑屏,不知道为什么。一开始我想使用 WINAPI (GDI+),但我读到 Windows Vista 和 7 有自己的 antialasign,它会阻止应用程序中的屏幕截图(总是黑屏),然后我开始使用 opengl,但没有任何结果。我基于的这些引用资料: testMemIO & How to take screenshot in 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();
}

最佳答案

问题解决了,我只是在 SwapBuffers(...) 之前调用了 GetScreenData(...) 现在它可以正常工作了,但是仍然有一个奇怪的事情,在一些电脑我有移动屏幕,例如:Screen #1不知道为什么会发生,据我所知,肯定会发生在 Nvidia 5xxx(m) i 7xxx(m) 系列上。非常感谢@AndonM.Coleman

关于c++ - OpenGL 游戏截屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23898877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com