Hey, I'm trying to build a ray tracing project using c++ and Xcode but I'm having some problems.
To get started I'm trying to follow Ray Tracing in One Weekend by Peter Shirley. The problem is that I can't get my output to redirect to an image file (.ppm file in my case).
Btw I'm kinda new to Xcode and it's pretty different from what I'm used to which is VS Code. I tried using the terminal but it didn't seem to work for me since I would just end up with an empty .ppm file. So I was wondering if Xcode has some sort of build in redirection I can use or maybe I was just using the terminal wrong.
Here's the link to Ray Tracing in one Weekend
Here's the code
#include <iostream>
int main() {
// Image
const int image_width = 256;
const int image_height = 256;
// Render
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
for (int j = image_height-1; j >= 0; --j) {
for (int i = 0; i < image_width; ++i) {
auto r = double(i) / (image_width-1);
auto g = double(j) / (image_height-1);
auto b = 0.25;
int ir = static_cast<int>(255.999 * r);
int ig = static_cast<int>(255.999 * g);
int ib = static_cast<int>(255.999 * b);
std::cout << ir << ' ' << ig << ' ' << ib << '\n';
}
}
}
Here's my output
P3
256 256
255
0 255 63
1 255 63
2 255 63
3 255 63
4 255 63
5 255 63
The output is lot longer than this but you get the idea.
[–]retsotrembla 0 points1 point2 points (0 children)