Phongo Clap RT  1.0
Simple Raytracing Renderer
Film.cpp
Go to the documentation of this file.
1 
4 #include "Film.h"
5 #include <ngl/Colour.h>
6 
8 
10 
11 void Film::setDimensions(int _w, int _h)
12 {
13  m_width = _w;
14  m_height = _h;
15 }
16 
17 void Film::writePixel(ngl::Colour _colour)
18 {
19  Pixel curr;
20  curr.r = _colour.m_r;
21  curr.g = _colour.m_g;
22  curr.b = _colour.m_b;
23  m_pixels.push_back(curr);
24 }
25 
26 void Film::writeFile(const char* _image_name)
27 {
28  m_file.open(_image_name, std::ios::out | std::ios::binary);
29  m_file << "P6\n" << m_width << " " << m_height << "\n255\n";
30 
31  for(unsigned int i = 0; i < m_pixels.size(); ++i)
32  {
33  m_file << (unsigned char) (m_pixels.at(i).r * 255) <<
34  (unsigned char) (m_pixels.at(i).g * 255) <<
35  (unsigned char) (m_pixels.at(i).b * 255);
36  }
37 
38  m_file.close();
39 }
void writeFile(const char *_image_name)
Iterates over the pixel vector and writes into a file using basic output stream methods.
Definition: Film.cpp:26
float b
Definition: Film.h:21
float g
Definition: Film.h:20
std::ofstream m_file
File output stream, in charge of writing the pixels into a file.
Definition: Film.h:76
All the operations regarding to file output and file input belong to this class. It abstracts the ide...
Film()
Film constructor.
Definition: Film.cpp:7
~Film()
Destructor for the Film.
Definition: Film.cpp:9
void setDimensions(int _w, int _h)
Sets the dimensions of the Film.
Definition: Film.cpp:11
std::vector< Pixel > m_pixels
Vector of pixels. The index of the pixel corresponds to this equation: i = height * y + x...
Definition: Film.h:72
float r
Definition: Film.h:19
int m_width
Width of the Film's image.
Definition: Film.h:64
void writePixel(ngl::Colour _colour)
Will create a pixel and push it to the pixel vector.
Definition: Film.cpp:17
int m_height
Height of the Film's image.
Definition: Film.h:68
Pixel data structure that will be used to hold the image units.
Definition: Film.h:17