V-ARTContributions
pnmexporter.cpp
Go to the documentation of this file.
1 
6 #include <sstream>
7 #include <cassert>
8 #include <iostream>
9 #include <fstream>
10 #include <iomanip>
11 
12 using namespace std;
13 
15  dataPtr(NULL)
16 {
17 }
18 
20 {
21  if (dataPtr)
22  delete[] dataPtr;
23 }
24 
25 void VART::PNMExporter::SetBufferSize(int columns, int lines)
26 {
27  if (dataPtr)
28  delete[] dataPtr;
29  dataPtr = new unsigned int[columns*lines];
30  numColumns = columns;
31  numLines = lines;
32 }
33 
35 // virtual
36 {
37  assert(dataPtr && "No memory allocated for PNMExporter!");
38  static int counter = 0;
39  static ostringstream oss;
40  oss.str("frame");
41  oss.fill('0');
42  oss << "frame" << setw(5) << counter << ".pnm";
43  ++counter;
44  ofstream outFile(oss.str().c_str());
45  outFile << "P6\n#Creator: V-ART framework PNMExporter class\n"
46  << numColumns << " " << numLines << "\n255\n";
47  glReadPixels(0,0,numColumns,numLines,GL_RGBA,GL_UNSIGNED_BYTE,dataPtr);
48  char* pixelPtr;
49  for (int lin = numLines; lin > 0; --lin)
50  {
51  pixelPtr = reinterpret_cast<char*>(dataPtr + ((lin-1)*numColumns));
52  for (int col = 0; col < numColumns; ++col)
53  {
54  outFile.write(pixelPtr,3);
55  pixelPtr += 4;
56  }
57  }
58 }
virtual void OnDraw()
Reads frame buffer and writes to file.
Definition: pnmexporter.cpp:34
void SetBufferSize(int columns, int lines)
Changes the buffer size.
Definition: pnmexporter.cpp:25
virtual ~PNMExporter()
Definition: pnmexporter.cpp:19