<p>I am trying to create a raytracer following peter shirley's in a weekend series. I am getting weird color distortion artifacts when I am running the code on windows. However, the code runs fine when executed on the on my mac. The only difference in code being that I had to replace <code>drand48()</code> with <code>(float)rand() / (RAND_MAX + 1.0)</code> as the former is not supported on windows.</p>

<p>How the image looks on windows 
<a href="https://i.sstatic.net/S0Klb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/S0Klb.png" alt="enter image description here"></a></p>

<p>How it should look
<a href="https://i.sstatic.net/W2SoL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/W2SoL.png" alt="enter image description here"></a></p>

<p>Heres the code I am using to generate the ppm file </p>

<pre><code>void writeToImgae(Vector3f *frameBuffer, RenderOptions *options)
{
    ofstream ofs("finalImage.ppm", ios::out);
    ofs &lt;&lt; "P6\n"
            &lt;&lt; options-&gt;width &lt;&lt; " " &lt;&lt; options-&gt;height &lt;&lt; "\n255\n";
    for (uint32_t i = 0; i &lt; options-&gt;height * options-&gt;width; ++i)
    {
        char r = (char)(255 * clamp(frameBuffer[i].x, 0.0f, 1.0f));
        char g = (char)(255 * clamp(frameBuffer[i].y, 0.0f, 1.0f));
        char b = (char)(255 * clamp(frameBuffer[i].z, 0.0f, 1.0f));
        ofs &lt;&lt; r &lt;&lt; g &lt;&lt; b;
    }
    ofs.close();
    delete[] frameBuffer;
}
</code></pre>

<p>Would really appreciate if someone could help me with this.</p>

CC BY-SA 4.0
2019-09-08T16:52:59.573Z
Try my fork of the code: https://github.com/vchizhov/InOneWeekend-1
If it works it's probably due to the rng, in which case you can use the random() from my fork in rng.hpp. We discussed this in one of the issue, but it still hasn't been implemented.
lightxbulb
CC BY-SA 4.0
2019-09-08T21:57:14.157Z
Also shouldn't you `ofs << r << "\t" << g << "\t" << b << "\n";`?
lightxbulb
<raytracing>
Weird Ray tracing artifacts when Code run on widows
B0rn2C0de
# Weird Ray tracing artifacts when Code run on widows

(Asked by: username_0 on 2019-09-08)

I am trying to create a raytracer following peter shirley's in a weekend series. I am getting weird color distortion artifacts when I am running the code on windows. However, the code runs fine when executed on the on my mac. The only difference in code being that I had to replace `drand48()` with `(float)rand() / (RAND_MAX + 1.0)` as the former is not supported on windows.

How the image looks on windows
[![enter image description here](https://i.sstatic.net/S0Klb.png)](https://i.sstatic.net/S0Klb.png)

How it should look
[![enter image description here](https://i.sstatic.net/W2SoL.png)](https://i.sstatic.net/W2SoL.png)

Heres the code I am using to generate the ppm file

```
void writeToImgae(Vector3f *frameBuffer, RenderOptions *options)
{
    ofstream ofs("finalImage.ppm", ios::out);
    ofs << "P6\n"
            << options->width << " " << options->height << "\n255\n";
    for (uint32_t i = 0; i < options->height * options->width; ++i)
    {
        char r = (char)(255 * clamp(frameBuffer[i].x, 0.0f, 1.0f));
        char g = (char)(255 * clamp(frameBuffer[i].y, 0.0f, 1.0f));
        char b = (char)(255 * clamp(frameBuffer[i].z, 0.0f, 1.0f));
        ofs << r << g << b;
    }
    ofs.close();
    delete[] frameBuffer;
}

```

Would really appreciate if someone could help me with this.

**Tags:** raytracing

> **Comments:**
> **username_1**: Try my fork of the code: https://github.com/vchizhov/InOneWeekend-1 If it works it's probably due to the rng, in which case you can use the random() from my fork in rng.hpp. We discussed this in one of the issue, but it still hasn't been implemented.  
> **username_1**: Also shouldn't you `ofs << r << "\t" << g << "\t" << b << "\n";`?  

---

## 0 answers

