/* * mandelbrot.c * * Mandelbrot set viewer */ #include #include #include #include #include #include #include #include #include /* Global variables: view of the set */ GLint windW, windH; /* size of the window on the screen */ /* Texture values */ #ifdef GL_VERSION_1_1 static GLuint texName; #endif #define TEXTURE_WIDTH 64 #define TEXTURE_HEIGHT 64 GLubyte Picture[TEXTURE_WIDTH][TEXTURE_HEIGHT][4]; /* Array of texels */ /* Objects to draw on */ GLUquadricObj *sphere; double point[][3] = {{-1.0, -1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0}, {-1.0, -1.0, -1.0}, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0}}; double normal[][3] = {{0.0, 0.0, 1.0}, {-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, -1.0}}; int polygon[][4] = {{0, 1, 2, 3}, /* front faces */ {0, 3, 7, 4}, {0, 4, 5, 1}, /* back faces */ {1, 5, 6, 2}, {2, 6, 7, 3}, /* side faces */ {7, 6, 5, 4}}; /* Menu options */ enum { CHOOSE_BOX, CHOOSE_SPHERE, CHOOSE_DECAL, CHOOSE_REPLACE, CHOOSE_MODULATE, CHOOSE_BLEND, CHOOSE_FLAT, CHOOSE_SMOOTH }; int shape = CHOOSE_BOX; int mapping = GL_DECAL; // int shading = GL_FLAT; double yaw = 0; double pitch = 0; double dist = -5.0; /* Initialization */ void Init(void) { /* Set background color */ glClearColor(0.2, 0.8, 1.0, 0.0); /* blue sky */ /* Generate a window */ windW = 300; windH = 300; glutInitWindowPosition(0, 0); glutInitWindowSize(windW, windH); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); if (glutCreateWindow("Mandelbrot Texture") == GL_FALSE) { exit(1); } /* Create sphere for drawing on */ if ((sphere = gluNewQuadric()) == NULL) exit(1); gluQuadricDrawStyle (sphere, GLU_FILL); gluQuadricNormals (sphere, GLU_FLAT); gluQuadricTexture (sphere, GL_TRUE); /* Enable shading and backface culling */ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glShadeModel(GL_FLAT); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); /* Enable texture mapping */ glEnable(GL_TEXTURE_2D); } /* Generate a texture */ void GenerateTexture(void) { /* Generate the texture map */ int i, j; GLubyte r, g; for (j=0, r=255; j