opengl - 如何调用函数并从头开始绘制它(从菜单选项)

发布于 2024-11-02 19:55:19 字数 2018 浏览 0 评论 0原文

我有以下代码,它绘制曼德布罗集。我创建了一个带有选项“黑与白”的菜单,我想用黑白颜色绘制曼德布罗特。我还没有弄清楚如何做到这一点(如果可以的话)这样做)。通过显示函数调用mandelbrot,但是我如何调用mandelbrot_black?

另外,如果有人知道在我的代码中进行“缩放”...这里...http://stackoverflow.com/questions/5705554/how-to-do-zoom-in-my-code-mandelbrot

 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;
      }

i have the following code ,which draws mandelbrot set.I created a menu with an option "black&white" which i want to draw the mandelbrot in black and white color.I haven't figured how to do this (if it can be done this way).mandelbrot is called through the display function ,but how can i call mandelbrot_black?

Also, if someone knows hot to make "zoom" in my code...here...http://stackoverflow.com/questions/5705554/how-to-do-zoom-in-my-code-mandelbrot

 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;
      }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┼── 2024-11-09 19:55:19

您的显示函数需要根据当前状态(可以/应该是全局变量)绘制 mandelbrot() 或 mandelbrot_black() 。

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

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

mymenu() 中相应地更改 black。您仍然需要将菜单附加到鼠标按钮并调用 SetupMenu()

Your display function needs to draw either mandelbrot() or mandelbrot_black() depending on the current state (which can/should be a global variable).

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

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

Change black accordingly in mymenu(). You still need to attach your menu to a mouse button and call SetupMenu().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文