title: Mandelbrot Set in a fragment shader version 330
body: <p>I am trying to to make a Mandelbrot set on the fragment shader. I initially build a rectangle, and use the gl_FragCoords to calculate the algorithm. Here is the code:</p>
  
  <pre><code>#version 330 core
  
  uniform float MaxIterations;
  
  out vec4 pixelColor;
  
  void main()
  {
      float   real  = gl_FragCoord.x;
      float   imag  = gl_FragCoord.y;
      float   Creal = real;  
      float   Cimag = imag;  
  
      float r2 = 0.0;
  
      for (float iter = 0.0; iter &lt; MaxIterations &amp;&amp; r2 &lt; 4.0; ++iter)
      {
          float tempreal = real;
  
          real = (tempreal * tempreal) - (imag * imag) + Creal;
          imag = 2.0 * tempreal * imag + Cimag;
          r2   = (real * real) + (imag * imag);
      }
  
      vec3 color;
  
      if (r2 &lt; 4.0)
          color = vec3(0.0f, 0.0f, 0.0f);
      else
          color = vec3(1.0f, 1.0f, 1.0f);
  
      pixelColor = vec4(color, 1.0);
  }
  </code></pre>
  
  <p>This code is actually kind of simplified and adapted version of what I found on the internet. I just assume the y axis as the imaginary and the x axis as the real part. Then I calculate the iterations until a max value passed by an uniform. It should show a black and white rectangle (white outside of the set, and black inside), but I just get a white rectangle. Does anybody knows what is wrong?</p>
  
  <p>EDIT: to add a little bit more detail.
  Here is the vertices I used for the rectangle</p>
  
  <pre><code>GLfloat vertices[] = {
          0.9f, 0.9f,     
          0.9f, -0.9f,    
          -0.9f, -0.9f, 
          -0.9f, 0.9f 
      };
  </code></pre>
  
  <p>and here is the vertex shader:</p>
  
  <pre><code>#version 330 core
  
  layout (location = 0) in vec2 position;
  
  void main() {
      gl_Position = vec4(position, 0.0f, 1.0f);
  }
  </code></pre>