Well i’ve got this simple Mandelbrot set and i wonder how does one zoom into the object and pan the view?
Mandelbrot.h
void Mandelbrot(int maxiter){
double left=-2.0;
double right=1.0;
double top=1.125;
double bottom=-1.125;
const int width = glutGet( GLUT_WINDOW_WIDTH );
const int height = glutGet( GLUT_WINDOW_HEIGHT );
glBegin( GL_POINTS );
for(int y=0; y<height; ++y)
{
for(int x=0; x<width; ++x)
{
complex<double> c( left + ( x * ( right - left ) / width ),
top + ( y * ( bottom - top ) / height ) );
complex<double> z ( 0.0,0.0 );
int iteration = 0;
while( abs( z ) < 2.0 && maxiter > iteration){
z = ( z * z ) + c;
++iteration;
}
if( iteration < maxiter )
{
glColor3f( 0.0, 1.0, 0.0 );
glVertex2i( x, y );
}
else
{
glColor3f( 0.0, 0.0, 0.0 );
glVertex2i( x, y );
}
}
}
glEnd();
}
main.cpp
void display(){
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
const int width = glutGet( GLUT_WINDOW_WIDTH );
const int height = glutGet( GLUT_WINDOW_HEIGHT );
glOrtho( 0, width, 0, height, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
Mandelbrot(maxiter);
glutSwapBuffers();
}
void Keyboard(unsigned char key,int x,int y){
switch(key){
case '[':
maxiter--;
glutPostRedisplay();
break;
case ']':
maxiter++;
glutPostRedisplay();
break;
}
}
int main( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
glutCreateWindow( "Mandelbrot" );
glutReshapeWindow( 400,400 );
glutDisplayFunc( display );
glutKeyboardFunc(Keyboard);
glutMainLoop();
return 0;
}
Btw i got skeleton of Mandelbrot set from a thread.
And everything in this code is subject to change.
Maybe even it’s impossible with GL/glut.h and i will need download other extensions for OpenGL ?
Oh and sorry for accidental double post.