void GeomGlut::initGraphicsWin( unsigned int pixelWinX, unsigned int pixelWinY, double _xMin, double _xMax, double _yMin, double _yMax ,long double (*func)(long double))
{
  f = func;

  if(_xMax-_xMin<=0)
        return;

  winFuncPixels.x = pixelWinX;
  winFuncPixels.y = pixelWinY;

  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
  glutInitWindowPosition(0, 0);

  glutInitWindowSize(winFuncPixels.x, winFuncPixels.y);

  // at the begining, the function win pixel and the actual win pixel are identical:
  graphWin.setWinPixels( winFuncPixels.x, winFuncPixels.y );

  minWin.x = _xMin;
  minWin.y = _yMin;
  maxWin.x = _xMax;
  maxWin.y = _yMax;

  glutCreateWindow("Algorithmes numériques: labo#4 - Part 1");

  // Initialiser la couleur du fond (blanc)
  glClearColor(0.9f, 0.9f, 0.9f, 1.0f);

  glutReshapeFunc( Reshape );
  glutDisplayFunc( Display );
  glutMainLoop();
}
void Reshape(int w, int h)
{
  if (h == 0) h = 1;
  if (w == 0) w = 1;
  glViewport(0, 0, w, h);

  graphWin.setWinPixels( w, h );

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  float xRatio = static_cast<float>(w)/static_cast<float>(graphWin.xWinFunc());
  float yRatio = static_cast<float>(h)/static_cast<float>(graphWin.yWinFunc());

  // Volume de clipping : (left, right, bottom, top, near, far)
  glOrtho(graphWin.xMin()*xRatio, graphWin.xMax()*xRatio, graphWin.yMin()*yRatio, graphWin.yMax()*yRatio, -2.0f, 2.0f);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}
Beispiel #3
0
void GeomGlut::initGraphicsWin( unsigned int pixelWinX, double xMin, double xMax, double yMin, double yMax )
{
    if(xMax-xMin<=0)
    {
        cout << "xMax-xMin cannot be < or = to 0" << endl << endl;
        return;
    }

    winFuncPixels.x = pixelWinX;
    winFuncPixels.y = (unsigned int)((yMax-yMin) * (double)winFuncPixels.x/(xMax-xMin));

    int argc = 1;
    char *argv[1] = {(char*)"Glut"};
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA | GLUT_MULTISAMPLE);
    glutInitWindowPosition(0, 0);

    cout << "System coordinate min(" << xMin << ", " << yMin << ") max(" << xMax << ", " << yMax << " give for " << winFuncPixels.x << " pixels in X, a Y pixel number of " << winFuncPixels.y << endl << endl;

    cout << "pixelWin(" << winFuncPixels.x << ", " << winFuncPixels.y << ")...";
    glutInitWindowSize(winFuncPixels.x, winFuncPixels.y);
    cout << " success!" << endl << endl;

    // at the begining, the function win pixel and the actual win pixel are identical:
    graphWin.setWinPixels( winFuncPixels.x, winFuncPixels.y );

    minWin.x = xMin;
    minWin.y = yMin;
    maxWin.x = xMax;
    maxWin.y = yMax;

    glutCreateWindow("Algorithmes numeriques: labo#6");

    // Initialiser la couleur du fond (blanc)
    glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
    glutMouseFunc( Click );
    glutReshapeFunc( Reshape );
    glutDisplayFunc( Display );
    glutMainLoop();
}