How to take screenshot in OpenGL

前端 未结 7 703
终归单人心
终归单人心 2020-12-01 04:59

How to take a screenshot of an OpenGL window in C++ and save it to file.

I found the glReadPixels() function, but I don\'t know what to do next. Where I can set path

7条回答
  •  有刺的猬
    2020-12-01 05:19

    Saving that data to a file is something you'll either have to do yourself or use a third-party library for - OpenGL has no such feature.

    Windows .bmp is probably the easiest if you're looking to do it yourself - Wikipedia has a pretty good explanation of the file format. Otherwise you can use image saving/loading libraries: libpng, libjpeg, etc. for low-level control, or devIL (there are others, but this is my favorite, and it's an extremely versatile library that goes well with GL) for high-level "just do it" image i/o.

提交回复
热议问题