How would I make a Mandelbulb (C++ / SDL)

I've created a Mandelbrot in C++ / SDL.

And was wondering how I'd make it 3d to created a Mandelbulb.

Heres my current code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <SDL2/SDL.h>
#include <iostream>
#include <complex>

#undef main

#define WINDOW_WIDTH 500
#define WINDOW_HEIGHT 500

#define MATH_PI 3.1415

int main(int argc, char* argv[])
{
    SDL_Window* window;
    SDL_Renderer* renderer;

    SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL, &window, &renderer);
    SDL_SetWindowPosition(window, 16, 16);

    for (int x = 0; x < WINDOW_WIDTH; x++)
    {
        for (int y = 0; y < WINDOW_HEIGHT; y++)
        {
            std::complex<double> cIterator(0.5 * x / WINDOW_WIDTH, 0.5 * y / WINDOW_HEIGHT);
            std::complex<double> z(0.0, 0.0);

            float count = 0;

            while (count < 255.0)
            {
                z = z * z + cIterator;  

                if (abs(z) > 2.0)
                {
                    break;
                }

                count++;
            }

            SDL_SetRenderDrawColor(renderer, count, count, 255, 255);

            SDL_RenderDrawPoint(renderer, x, y);
        }
    }

    SDL_RenderPresent(renderer);

    printf("Finished!\n");

    std::cin.get();

    SDL_Quit();
}


I'm trying to convert it to a 3D Mandelbulb but have no idea how I'd do this, let alone the formula to do it. After googling for a few hours, I've seem to come to a conclusion multiple formulas can be used to generate one? It seems to be that way. Based on wikipedia, and some fractals I've found. But I guess it makes sense when you put it into retrospective.

Thanks! All helps appreciated!

I don't know about the fractal bit, but I would consider rendering backwards from screen-space -- i.e., by ray tracing -- until you compute a (sufficiently near) intersection with one of the points (or is the mandelbulb a field?) that make up your fractal. You'd get good detail that way.

That saves you from having to model the whole fractal in 3D, which you could do by picking enough vertices from the "surface", reconstructing a mesh from it, and giving the result to OpenGL, which I think would be very difficult; maybe
http://pointclouds.org/
would offer help.

If you do that, however, you can get the graphics pipeline to do the shading work directly for you.
Last edited on
Topic archived. No new replies allowed.