I'm following TinyRayTracer and can't properly output to ppm file. I am on windows.
#include <limits>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm> //<-- max/min
#include "geometry.h"
void render() {
const int width = 1024;
const int height = 768;
std::vector<Vec3f> framebuffer(width*height);
for (size_t j = 0; j < height; j++) {
for (size_t i = 0; i < width; i++) {
framebuffer[i + j * width] = Vec3f(j / float(height), i / float(width), 0);
}
}
std::ofstream ofs; // save the framebuffer to file
ofs.open("./out.ppm", std::ofstream::out | std::ofstream::binary);
ofs << "P6\n" << width << " " << height << "\n255\n";
for (size_t i = 0; i < height*width; ++i) {
for (size_t j = 0; j < 3; j++) {
ofs << (char)(255 * std::max(0.f, std::min(1.f, framebuffer[i][j])));
}
}
ofs.close();
}
int main() {
render();
return 0;
}
The line giving me issues is ofs.open("./out.ppm", std::ofstream::out | std::ofstream::binary);
I've also tried writing ofs.open("./out.ppm",std::ios::binary); and ofs.open("./out.ppm"); to no avail. Some help would be appreciated. I am on windows, using powershell to compile and run. compiling by using g++ .\main.cpp -o raytracer and running .\raytracer.exe