如何截取opengl中的截图 [英] How to take screenshot in opengl

查看:754
本文介绍了如何截取opengl中的截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c ++中截取opengl窗口并将其保存到文件中。

How to take screenshot of opengl window in c++ and save it to file.

我找到一个glReadPixels(),但不知道该怎么做。我可以设置文件的路径,例如?

I find a glReadPixels() but dont know what to do next. Where i can set path to a file, for example?

如果不困难,请写代码。

If not difficult, write code, please.

推荐答案

这段代码捕获了openGL窗口并导出到BMP文件。您必须有FreeImage库才能运行它。

This piece of code captures the openGL window and export to an BMP file. You must have FreeImage library to run it.

// Make the BYTE array, factor of 3 because it's RBG.
BYTE* pixels = new BYTE[ 3 * width * height];

glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);

// Convert to FreeImage format & save to file
FIBITMAP* image = FreeImage_ConvertFromRawBits(pixels, width, height, 3 * width, 24, 0x0000FF, 0xFF0000, 0x00FF00, false);
FreeImage_Save(FIF_BMP, image, "C:/test.bmp", 0);

// Free resources
FreeImage_Unload(image);
delete [] pixels;

这篇关于如何截取opengl中的截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆