summaryrefslogtreecommitdiff
path: root/src/OffscreenContext.h
blob: 34948983d50f67a042eabad3088fe648284ca2cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef OFFSCREENCONTEXT_H_
#define OFFSCREENCONTEXT_H_

#include <iostream>
#include <fstream>
#include <string>

struct OffscreenContext *create_offscreen_context(int w, int h);
bool teardown_offscreen_context(OffscreenContext *ctx);
bool save_framebuffer(OffscreenContext *ctx, std::ostream &output);
std::string offscreen_context_getinfo(OffscreenContext *ctx);

void bind_offscreen_context(OffscreenContext *ctx)
{
	if (ctx) fbo_bind(ctx->fbo);
}

/*
  Capture framebuffer from OpenGL and write it to the given filename as PNG.
*/
inline bool save_framebuffer(OffscreenContext *ctx, const char *filename)
{
  std::ofstream fstream(filename);
  if (!fstream.is_open()) {
    std::cerr << "Can't open file " << filename << " for writing";
    return false;
  } else {
    save_framebuffer(ctx, fstream);
    fstream.close();
  }
  return true;
}

#endif
contact: Jan Huwald // Impressum