2011-04-19 38 views
0

我有以下代码,它绘制了mandelbrot set.I创建了一个菜单,其中包含一个选项“black & white”,我想绘制它mandelbrot在黑白的颜色。我还没有想过如何做到这一点(如果可以这样做).mandelbrot通过显示功能调用,但我怎样才能打电话给mandelbrot_black?此外,如果有人知道热点,使我的代码“放大”... ... ... ... ... ... ... ... ... ... ... ... ... ... ... - ...下一步... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... PHD- -mandelbrotopengl - 如何调用函数并从头开始绘制它(从菜单选项)

void mandelbrot();  
void mandelbrot_black(); 

GLsizei width = 600; 
GLsizei height = 600; 
GLfloat AspectRatio; 
int max = 500; 
double xpos=0,ypos=0; 
int CLEARFLAG=1; 


    double xmax = 2.0; 
    double xmin = -2.0; 
    double ymax = 2.0; 
    double ymin = -2.0; 

    using namespace std; 

    void display() 
{ 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    gluOrtho2D(-2, width, -2, height); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
    glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); 
    mandelbrot(); 
    glutSwapBuffers(); 
    } 


    void reshape(GLsizei w, GLsizei h) { 

    width=w; height=h; 
    glViewport(0,0,width,height); 
    glutPostRedisplay(); 
    } 



    void setXYpos(int px, int py) 
    { 
    xpos=xmin+(xmax-xmin)*px/width; 
    ypos=ymax-(ymax-ymin)*py/height; 

    } 



    void mouse(int button, int state, int x, int y) 
    { 
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN) {CLEARFLAG=0; setXYpos(x,y);} 

glutPostRedisplay(); 
    } 

void mandelbrot() 
{ 
...} 

void mandelbrot_black(){ 
...} 

void mymenu(int n) 
{ 
    switch(n) { 

    case 1: zoom_in();break; 
    case 2: zoom_out();break; 
    case 3: mandelbrot_black();break; 
    case 4: exit(0); 
    } 

    glutPostRedisplay(); 
    } 




    void SetupMenu() 
    { 

glutCreateMenu(mymenu); 
glutAddMenuEntry("zoom in",1); 
glutAddMenuEntry("zoom out",2); 
glutAddMenuEntry("black&white",3); 
glutAddMenuEntry("exit",4); 
glutAttachMenu(GLUT_RIGHT_BUTTON); 
    } 

    int main(int argc, char *argv[]) 
    { 

    glutInit(&argc, argv); 
    glutInitWindowSize(600, 600); 
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); 
    glutCreateWindow("Mandelbrot"); 
    glutDisplayFunc(display); 
    glutReshapeFunc(reshape); 
    glutMainLoop(); 

    return 0; 
     } 

回答

1

你的显示功能需要绘制任天壤之别()或根据当前状态(其可以/应当是一个全局变量)mandelbrot_black()。

//in global scope 
static bool black = false; 
    ... 

//in display() 
if(black) 
    mandelbrot_black(); 
else 
    mandelbrot(); 

变化black相应地mymenu()。您仍然需要将菜单附加到鼠标按钮,并致电SetupMenu()

+0

谢谢!它现在工作正常!如果你可以帮助我也这样... ... http://stackoverflow.com/questions/5705554/how-to-do-zoom-in-my-code-mandelbrot – George 2011-04-19 11:58:24

相关问题