   HELP!! Problem with handlers and my graphic window is too slow...
  Hi there!I'm really inexperienced with graphic programing. I'm using SDL/openGL to do my graphical interface of a robotics mapping algorithm (SLAM). One problem is that my algorithm is very complex and heavy and it slows down the graphic part but that i'm working in making my algorithm lighter.The other problem is that the program doesn't respond to my mouse or keyboard actions as it should. For example: I have 2 buttons to increase/decrease a variable but when i click on them, it get "stucked" and increases non-stop. or in other ocasions it won't do nothing. Is it because my code is to hevy? By the way, My map is keeped in an array witch every m[j] is the probability of that space being occupeid. I'm drawing it as a sequence of openGL squares but my array as 200*200 cells. is there a better way?thanks in advance for your help,André
  It's hard to know what's going on without being able to see your code. Is there any way you could post some of the relevant sections, especially for the input handling?   ;  Hi! thanks for the fast reply. I use a GUI library called AntTweakBar ( http://www.antisphere.com/Wiki/tools:anttweakbar?sb=tools ). But I don't think the problem comes from it. My code:int main(int argc, char** argv){  using namespace std;  using namespace PlayerCc;  srand ( time(NULL) ); //para que o rand seja mm aleatório   //flags  bool move_flag=TRUE, save_flag=FALSE;    /// Definition of the variables to use in the main function  player_pose_t ut, u_ant, xt1; /// poses  float Neff=0, sum=0;  int k=0;  int i=0;///iterator  int M=10;///Number of Particles (default 10)   int i_max=0;  /// Call of Veiwer function  int width = WINDOWWIDTH;  int height= WINDOWHEIGHT;  CGridMapping map, grid[M];/// maps   std::vector<player_pose_t> xt(M);  std::vector<player_pose_t> x_ant(M); // struct pose x_ant[M], xt[M]; /// M particles of pose  double pz[M];Until here is just some var declarations...Now, I start to initialize SDL:    const SDL_VideoInfo* video = NULL;  int bpp, flags;  // Initialize SDL, then get the current video mode and use it to create a SDL window.  if( SDL_Init(SDL_INIT_VIDEO)<0 )  {    fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError());    SDL_Quit();    exit(1);  }  video = SDL_GetVideoInfo();  if( !video )   {    fprintf(stderr, "Video query failed: %s\n", SDL_GetError());    SDL_Quit();    exit(1);  }/*if( !video ) */  SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);  // SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 1);  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);    bpp = 32;//video->vfmt->BitsPerPixel;  flags = SDL_OPENGL | SDL_HWSURFACE | SDL_RESIZABLE;   if( !SDL_SetVideoMode(width, height, bpp, flags) )    {   fprintf(stderr, "Video mode set failed: %s", SDL_GetError());   SDL_Quit();   exit(1);    }    SDL_WM_SetCaption("Mapeamento & Odometria","Map & Odo");// Enable SDL unicode and key-repeat  SDL_EnableUNICODE(1);  SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);// Set OpenGL viewport and states  glViewport(0, 0, width, height);  glEnable(GL_DEPTH_TEST);  glEnable(GL_LIGHTING);  glEnable(GL_LIGHT0); // use default light diffuse and position  glEnable(GL_NORMALIZE);  glEnable(GL_COLOR_MATERIAL);  glDisable(GL_CULL_FACE);  glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); The GUI Definition (AntTweakBar)see www.antisphere.com  TwInit(TW_OPENGL, NULL);  TwWindowSize(width, height);  //return 0;  TwBar *myBar;  myBar = TwNewBar("Particles");  TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with SDL and OpenGL.\nPress [Space] to toggle fullscreen.' "); // Message added to the help bar./////=== Var's of the bar    TwAddVarRO(myBar, "Width", TW_TYPE_INT32, &width, " label='Window width' help='Width of the graphics window (in pixels)' ");    TwAddVarRO(myBar, "Height", TW_TYPE_INT32, &height, " label='Window height' help='Height of the graphics window (in pixels)' "); TwAddVarRO(myBar, "Neff", TW_TYPE_FLOAT, &Neff, " label='Neff' help='Dispersion of the particle cloud' precision=3 ");   // Add Num of particles to 'bar': this is a modifiable variable of type TW_TYPE_INT32.TwAddVarRW(myBar, "NumPart", TW_TYPE_INT32, &M, " label='Number of particles' min=1 max=100 keyIncr=m keyDecr=M help='Defines the number of particle in the scene.' ");    TwAddVarRW(myBar, "NumMap", TW_TYPE_INT32, &k, " label='Particle Map No' min=0 max=10 keyIncr=p keyDecr=P help='Defines what particle map will appear in the scene.' ");    TwAddVarRW(myBar, "Move", TW_TYPE_BOOLCPP, &move_flag, " label='Move?' true='Moving' false='Stopped' key='R' help='Start/Stop movement of the robot' ");char s1[64] = "foo.bmp";    // ...    TwAddVarRW(myBar, "s1", TW_TYPE_CSSTRING(sizeof(s1)), s1, "label='Save As:'"); // here, sizeof(s1) is 64    TwAddVarRW(myBar, "save", TW_TYPE_BOOLCPP, &save_flag,   " label='Save?' true='Saving' false='' key='s' help='Saves current map' ");    TwAddButton(myBar, "Quit", QuitCB, NULL, " label='Quit?' help='Quit program.' key ='ESC'");///// ======End of Tweak stuff =============   Here starts the Main loop while( !quit ){    num++;SDL_Event event;  int handled;  //clear old image  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    //set the translation matrix(?)  glLoadIdentity();  glTranslatef(0.0f,0.0f,0.0f);Here starts the SLAM stuffI think the problem is that some of this functions are really heavy///reinicialize the speed var's    double newspeed = 0.3;    double newturnrate = 0;//char chk=static_cast <char>(k+48);    s1={'m','a','p',static_cast <char>(k+48),'.','b','m','p'};    u_ant=ut;///Read from robot    bot.Read();    //Get the pose from the odometer    ut.px=pos.GetXPos();    ut.py=pos.GetYPos();    ut.pa=pos.GetYaw();    //create M pose particles    for (i=0; i<M; i++){ x_ant=xt; xt=odo_model(ut,u_ant,x_ant,map);   map.UpdateMap(i, xt, laser); pz+=error(laser,xt,map,i);    }//for (i)    ///Call the map function    map.UpdateMap(-1, ut, laser);    ///Call the movement functionif (move_flag==TRUE)    wallfollow(newspeed, newturnrate, laser);   /// Send the calculated speeds to the robot    pos.SetSpeed(newspeed, newturnrate);   /// The Resampling Step    sum=0;    for (int i=0; i<M; i++){ sum=(pz*pz);    }//for    Neff=1.0/sum;if (Neff>M)   myresample(xt,pz,M);Here is where I call my drawing functions   drawlimits(map);///Call function to Draw the particles of posefloat max=pz[0]; for (int j=0; j<M;j++){    if (pz[j]>max){ max=pz[j]; i_max=j;    }}for (int j=0; j<M;j++){ float color = pz[j]/max;  plotXt(xt, j, color);}//for  DrawRobot(ut,2*map.GetResolution());  plotLaser(laser,ut);  DrawMap(map,k);TwDraw();  // draw the tweak bar(s)  //send to monitor  /////////////////////////The HANDLE PART ///////////////////////////////////////////////search for user envent  SDL_PollEvent(&event);    // Process incoming events   while( SDL_PollEvent(&event) )    {//   // Send event to AntTweakBar   handled = TwEventSDL(&event);  // If event has not been handled by AntTweakBar, process it  if( !handled )  { switch( event.type ) { case SDL_QUIT:  // Window is closedquit = 1;break; case SDL_VIDEORESIZE:   // Window size has changed// Resize SDL video modewidth = event.resize.w;height = event.resize.h;if( !SDL_SetVideoMode(width, height, bpp, flags) )    fprintf(stderr, "WARNING: Video mode set failed: %s", SDL_GetError());// Resize OpenGL viewportglViewport(0, 0, width, height);// Restore OpenGL states (SDL seems to lost them)glEnable(GL_DEPTH_TEST);glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_NORMALIZE);glEnable(GL_COLOR_MATERIAL);glDisable(GL_CULL_FACE);glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);// TwWindowSize has been called by TwEventSDL, // so it is not necessary to call it again here.break; case SDL_KEYDOWN:if( event.key.keysym.sym==' ' ) // toggle fullscreen if Space key is pressed{    flags ^= SDL_FULLSCREEN;    SDL_SetVideoMode(800, 600, bpp, flags);    // Push a resize event because SDL do not do it for us    event.type = SDL_VIDEORESIZE;    event.resize.w = 800;    event.resize.h = 600;    SDL_PushEvent(&event);}break;default: continue; }//switch  }//if( !handled )  }// while(SDL_PollEvent(&event))The buffer swapping and the terminate partSDL_GL_SwapBuffers();}//main cicle    TwTerminate();    // Terminate SDL    SDL_Quit();  int image [map.GetSizeX()][map.GetSizeX()]; for (int i=0;i<map.GetSizeX(); i++){  for (int j=0;j<map.GetSizeY(); j++){    image[j]=map.GetProbValue(i,j,i_max)*10;   // cout<<map.GetProbValue(i,j,0)<<" ";  } }  //    bool result = intarray2bmp::intarray2bmp( "foo.bmp", image, 50, 50, MYMIN, MYMAX );  bool result = float2bmp2::floats_to_bitmap_file( "bestmap.bmp", &(image[0][0]),   &(image[200][200]),  map.GetSizeX(),    map.GetSizeY(),   1.0);cout<<result;}//mainI know this is a lot to digest but I can't seem to find a solution to my problem.thanks a lot for your help