我OpenGL
用来模拟物体。并且stbi_write_png
用来保存图片,但是图片大小只有200K多,放大后不是很清晰。所以想知道C++代码中还有没有其他保存高清图片的方法。我的代码如下所示:
int SaveScreenshot(const char *filename)
{
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
int x = viewport[0];
int y = viewport[1];
int width = viewport[2];
int height = viewport[3];
char *data = (char*)malloc((size_t)(width * height * 4)); // 3 components (R, G, B)
if (!data)
return 0;
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
stbi_flip_vertically_on_write(1);
int saved = stbi_write_png(filename, width, height, 4, data, 0);
free(data);
return saved;
}