Esempio n. 1
0
void gemglutwindow :: destroyMess(void)
{
  if(makeCurrent()) {
    s_windowmap.erase(m_window);

    int window=m_window;
    m_window=0; // so that we no longer receive any event
    glutCloseFunc     (NULL);
    glutDestroyWindow(window);
    glutMainLoopEvent();
    glutMainLoopEvent();

  }
  destroy();
}
Esempio n. 2
0
void gemglutwindow :: destroyMess(void)
{
  if(makeCurrent()) {
    int window=m_window;
    m_window=0; // so that we no longer receive any event
    glutCloseFunc     (NULL);
    glutDestroyWindow(window);
    glutMainLoopEvent();
    glutMainLoopEvent();

    /* now that the window is destroyed, remove it from the list of available windows */
    s_windowmap.erase(window);
  }
  destroy();
}
    void EnvironmentDisplay::Redraw(Environment *env)
    {
      char *string = (char *) "Your environment doesn't have it's own EnvironmentDisplay";
      int   x = 5;
      int   y = height/2;
      GLfloat whiteMaterial[] = {1.0, 1.0, 1.0, 1.0};
      char  buf[128];
      sprintf(buf,
	      "You have %d objects and %d agents.",
	      env->objects.size(), env->agents.size());

      glutSetWindow(window);
      glViewport(0, 0, width, height);
	
      // go into 2D mode
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluOrtho2D(0, width, height, 0);
      glMatrixMode(GL_MODELVIEW);


      // redraw
      glClear(GL_COLOR_BUFFER_BIT);

      SetColor(whiteMaterial);

      DrawText(x, y, string);
      y -= 25;
      DrawText(x, y, buf);

      glutSwapBuffers();
      glutMainLoopEvent();
    }
Esempio n. 4
0
void Sim::run() {
  running = true;
  float t0 = 0, t1 = 0, dt = 0;
  float ft = 0, f = 0, fps = 0;
  clock_t start_time = raw_time();
  while (running) {
    t1 = (float) (raw_time() - start_time) * 1e-9;
    dt = t1 - t0;
    t0 = t1;

    if (f > 60) {
      fps = f / (t1 - ft);
      printf("%.1lf fps\n", fps);
      ft = t0;
      f = 0;
    }
    f++;

    keyboard_clear();
    glutMainLoopEvent();
    look();
    if (callback)
      callback(dt, cb_data);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    list<Geometry*>::iterator g, end = geoms.end();
    for(g = geoms.begin(); g != end; g++) {
      (*g)->draw(dt);
    }

    glutSwapBuffers();
  }
}
Esempio n. 5
0
int 
main(int argc, char *argv[])
{
  int fractal_window ;

  glutInitWindowSize(500, 250);
  glutInitWindowPosition ( 140, 140 );
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE );
  glutInit(&argc, argv);

  if ( argc > 1 )
    readConfigFile ( argv[1] ) ;
  else
    readConfigFile ( "fractals.dat" ) ;

  fractal_window = glutCreateWindow( window_title );

  glClearColor(1.0, 1.0, 1.0, 1.0);

  glutReshapeFunc(Reshape);
  glutKeyboardFunc(Key);
  glutSpecialFunc(Special);
  glutDisplayFunc(Display);

#ifdef WIN32
#endif

  while ( continue_in_main_loop )
    glutMainLoopEvent();

  printf ( "Back from the 'freeglut' main loop\n" ) ;

  return 0;             /* ANSI C requires main to return int. */
}
	void Update() const
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glDrawPixels(static_cast<int>(_width), static_cast<int>(_height), GL_RGB, GL_FLOAT, _pixels.data());
		glutSwapBuffers();
		glutMainLoopEvent();
	}
Esempio n. 7
0
void drawPoints2D(float *u_x, float *u_y, int u_n, char *title, int block){
	
    n = u_n;
    x = u_x;
    y = u_y;
    int argc2 = 0;
    if (!set){
	printf("Initializing glut\n");
	glutInit(&argc2, NULL);
	set = 1;
    }
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    //printf("n %d\n", n);
	glEnable(GL_POINT_SMOOTH);
	win = glutCreateWindow(title);
	printf("win %d\n", win);
	glutSetWindow(win);
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
    	glutKeyboardFunc(keyboard);
	if (block){
    		printf("Entering bloking loop. Press 'c' key to resume, 'e' to exit pogram\n");
		glutMainLoop();
		set = 0;
	}else{
    		glutMainLoopEvent();
    		glutDestroyWindow(win);
	}

}
Esempio n. 8
0
void compositorDispatch( WstCompositor *wctx, void *userData )
{
   AppCtx *appCtx= (AppCtx*)userData;
   
   #if !defined (WESTEROS_PLATFORM_EMBEDDED)
   glutMainLoopEvent();
   #endif
}
Esempio n. 9
0
// Rotina Principal do programa
int main(int argc, char **argv) {

  double start, finish;
  int i;

  if(argc != 2){
    printf("Usage: %s <number of particles>\n",argv[0]);
    return 0;
  }

  // Recebe o número de partículas que devem ser processadas
  // e posteriormente renderizadas
  nParticulas = atoi(argv[1]);

  // Define a quantidade de partículas que não estão no chão (inicialmente nenhuma delas está)
  nParticulasAux = nParticulas;

  // Define posição inicial das particulas
  iniciarParticula();

  // Funções necessárias para inicializar o OpenGL
  // e criar a janela que ficará renderizando
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  glutInitWindowPosition(100,100);
  glutInitWindowSize(640,640);
  glutCreateWindow("Trabalho Final - Computação Paralela");
  glEnable(GL_DEPTH_TEST);

  // Inicializa a contagem do tempo
  GET_TIME(start);

  // Registrando CallBacks
  glutDisplayFunc(renderScene);
  glutReshapeFunc(changeSize);
  glutIdleFunc(renderScene);

  // Função que mantém o loop do evento de renderização
  // funcionado
  // Foi escolhido a função glutMainLoopEvent ao invés de glutMainLoop
  // pelo simples fato de que a segunda não pára até o programa finalizar
  // e a que escolhemos funciona como apenas uma iteração dessa função
  while(!Flag)
  {
    glutMainLoopEvent();
    renderScene();
  }

  // Finaliza o timer
  GET_TIME(finish);

  // Printa o tempo
  printf("Tempo gasto: %f\n", (finish - start));

  free(vetor2);

  return 1;
}
Esempio n. 10
0
int main() 
{
	Animation a;
	while(1)
	{
		glutMainLoopEvent();		// Run the OpenGL event loop forever
		GLUT_Port::idle();
	}
}
Esempio n. 11
0
void glWindow::run_events()
{
	if ( glWindow::glutinitialized ) {
#ifdef __linux__
		glutMainLoopEvent();
		idleFunc();
#endif
#ifdef __APPLE__
		glutCheckLoop();
#endif
	}
}
bool c_RendererViewer::solve(bool _is_decoding)
{
    m_p_renderer->initiate_model(m_width, m_height);
    if (_is_decoding)
    {
        glutMainLoop();
    }
    else
    {
        glutMainLoopEvent();
    }
    return true;
}
Esempio n. 13
0
void gemglutwindow :: dispatch()
{
  if(!m_window)return;

  // mark the render-buffer as dirty, so the displayCb() gets called
  // other things that mark dirty are (e.g.) resizing, making (parts of) the window visible,...
  glutSetWindow(m_window);
#if 0
  // setting glutPostRedisplay() here will emit a render-bang for each dispatch-cycle...
  // ...NOT what we want
  glutPostRedisplay();
#endif
  glutMainLoopEvent();
}
Esempio n. 14
0
bool animSleep(int ms) {
	if (sleepInterrupted) {
		return false;
	}
	scriptReleaseGIL();
	int time = glutGet(GLUT_ELAPSED_TIME);
	int returnAt = time + ms;
	int wakeAt, wakeAfter;
	animSleepActive=true;

	while ((ms=returnAt-time)>0) {
		wakeAfter=animFrameDelay;
		if (wakeAfter > animResponseDelay)
			wakeAfter=animResponseDelay;
		if (wakeAfter > ms)
			wakeAfter=ms;
		wakeAt=time+wakeAfter;

		updateStatus(0, true, "script");
		glutMainLoopEvent();
		if (sleepInterrupted)
			break;

		time = glutGet(GLUT_ELAPSED_TIME);
		wakeAfter=wakeAt-time;
		if (wakeAfter>0) {
			utilSleep(wakeAfter);
		}
		time = glutGet(GLUT_ELAPSED_TIME);
	}
	glutMainLoopEvent();
	animSleepActive=false;
	scriptAcquireGIL();
	scriptEventsSchedulePending();
	hidInvokeWaitingEvents();
	return !sleepInterrupted;
}
Esempio n. 15
0
	void runEventLoop()
	{
		initGlut();

		glutThreadId = boost::this_thread::get_id();

		mainLoopRunning = true;
		while (mainLoopRunning) {
#ifdef TARGET_OSX
			glutCheckLoop();
#elif TARGET_LINUX
			glutMainLoopEvent();
#endif
		}
	}
Esempio n. 16
0
        SgRdrBackend::~SgRdrBackend()
        {
          //The Sg Renderer must be destroyed prior to destroying the window
          m_renderer = dp::sg::renderer::rix::gl::SceneRendererSharedPtr::null;
          if ( m_windowId )
          {
            glutDestroyWindow( m_windowId );
            glutLeaveMainLoop();
            glutMainLoopEvent();
#if defined(DP_OS_WINDOWS)
            // As long as DPTRiXGL.bkd gets loaded and unloaded several times during test
            // execution this workaround is necessary to prevent freeglut from crashing.
            UnregisterClass( _T("FREEGLUT"), NULL);
#endif
          }
        }
Esempio n. 17
0
void ODEDrawer::Draw(char* caption)
{
    SetWindowCaption(caption);

    // clear the window
    glClearColor (0.4,0.4,0.4,0);
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // set the light position (for some reason we have to do this in model view.
    GLfloat light_position[] = { LIGHTX, LIGHTY, 1.0, 0.0 };
    glLightfv (GL_LIGHT0, GL_POSITION, light_position);


     // snapshot camera position
    double view2_xyz[3];
    double view2_hpr[3];
    memcpy (view2_xyz,view_xyz,sizeof(double)*3);
    memcpy (view2_hpr,view_hpr,sizeof(double)*3);

    // go to GL_MODELVIEW matrix mode and set the camera
    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity();
    setCamera (view2_xyz[0],view2_xyz[1],view2_xyz[2], view2_hpr[0],view2_hpr[1],view2_hpr[2]);

    DrawHeightfields();
    DrawTriMeshes();
    DrawKinematicBodies();
    DrawDynamicBodies();

    drawGrid();
    drawAxes();

    DrawText(caption);
    
    /*char *pg_info;
    for(ParticleGenerator *pg: domain->getParticleGenerators())
    {
        pg_info=pg->getInfo();
        DrawCaption(pg_info);
        delete[] pg_info; 
    }*/
    
    m_textLine=DRAW_STRING_NEW_LINE;
    glutSwapBuffers();

    glutMainLoopEvent();
}
Esempio n. 18
0
int main(int argc, char **argv)
{
	Server::getInstance();

    unsigned int i;

    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DEPTH|GLUT_DOUBLE );
    main_window = glutCreateWindow( "OpenGL Remote Rendering Server" );
    glutDisplayFunc( cb_display );
    glutReshapeFunc( cb_reshape );
    glutIdleFunc( cb_idle );

    glutCreateMenu( cb_menu );
    for( i = 0; i < NUMBEROF( font_map ); ++i )
        glutAddMenuEntry( font_map [ i ].name, i );
    glutAddMenuEntry( "Quit", i );
    glutAttachMenu( 2 );

	font = GLUT_BITMAP_HELVETICA_12; //GLUT_BITMAP_8_BY_13;

    printf("glut window id: %d\n", glutGetWindow());

	/* ffmpeg init */
	width = glutGet(GLUT_WINDOW_WIDTH);
	height = glutGet(GLUT_WINDOW_HEIGHT);
	ffmpeg = fopen("output.h264", "wb");

	encoder = new Encoder();
	if (!encoder->bootstrap(AV_CODEC_ID_H264, width, height, 25)) //MPEG1VIDEO
		exit(EXIT_FAILURE);
	buffer = new uint8_t[3*width*height];

    for (;;)
    {
        glutPostRedisplay();
        glutMainLoopEvent();
    }

	encoder->writeEndFile(ffmpeg);
	fclose(ffmpeg);
	delete[] buffer;

    return EXIT_SUCCESS;
}
Esempio n. 19
0
/**
 * main freeGLUT loop
 * waits for global signals to create windows & make other actions
 */
void *Redraw(_U_ void *arg){
//	pthread_cond_t fakeCond = PTHREAD_COND_INITIALIZER;
//	struct timeval tv;
//	struct timespec timeToWait;
//	struct timeval now;
	while(1){
		pthread_mutex_lock(&winini_mutex);
		if(!initialized){
			DBG("!initialized");
			pthread_mutex_unlock(&winini_mutex);
			pthread_exit(NULL);
		}
		if(wannacreate){ // someone asks to create window
			DBG("call for window creating, id: %d", wininiptr->ID);
			createWindow(wininiptr);
			DBG("done!");
			wininiptr = NULL;
			wannacreate = 0;
		}
		if(wannakill_GL_ID){
			usleep(10000); // wait a little to be sure that caller is closed
			killwindow(wannakill_GL_ID);
			wannakill_GL_ID = 0;
		}
		forEachWindow(redisplay);
/*		gettimeofday(&now,NULL);
		timeToWait.tv_sec = now.tv_sec;
		timeToWait.tv_nsec = now.tv_usec * 1000UL + 10000000UL;
		pthread_cond_timedwait(&fakeCond, &winini_mutex, &timeToWait);*/
		pthread_mutex_unlock(&winini_mutex);
		//pthread_testcancel();
		if(totWindows) glutMainLoopEvent(); // process actions if there are windows
/*		gettimeofday(&now,NULL);
		timeToWait.tv_sec = now.tv_sec;
		timeToWait.tv_nsec = now.tv_usec * 1000UL + 10000000UL;
		pthread_mutex_lock(&fakeMutex);
		pthread_cond_timedwait(&fakeCond, &fakeMutex, &timeToWait);
		pthread_mutex_unlock(&fakeMutex);*/
/*		tv.tv_sec = 0;
		tv.tv_usec = 10000;
		select(0, NULL, NULL, NULL, &tv);*/
		usleep(10000);
	}
	return NULL;
}
Esempio n. 20
0
int main(int argc, char **argv) {
	ros::init(argc, argv, "zulumapping"); 	// Initialize ROS. Node name = zulumapping
	ros::NodeHandle n; 						// Handle to this process node
	// Subscribe to "odom" topic
	ros::Subscriber odom_sub = n.subscribe("odom", 50, odomCallback);
	//Subscribe to "base_scan" topic
	ros::Subscriber base_scan = n.subscribe("base_scan", 50, scanCallback);
	InitGLUT();
	CreateGlutWindow("My GL Window", 800, 600);

	ros::Rate rate(10); 	// 10 hz
	while (true) {
		ros::spinOnce();
		glutMainLoopEvent();
		Draw();
		rate.sleep();
	}
	return 0;
}
Esempio n. 21
0
/* view thread function */
static void* view_thread_func(void* param)
{
  ThreadInfo* thread_info = (ThreadInfo*)param;

  //initize GLUT
  init_glut();

  //run message loop
  while(1)
  {
    //handle glut messages
    glutMainLoopEvent();

    //check whether to quit
    if (thread_info->should_quit)
      break;

    //handle CTC
    view_sync.enter();
    if (ctc_function != NULL)
    {
      ctc_result = ctc_function(ctc_param);
      ctc_function = NULL;
      view_sync.signal_cross_thread_call();
    }
    view_sync.leave();

    //wait for 10 ms
#ifdef WIN32
    Sleep(10);
#else
    usleep(10*1000);
#endif
  }

  //cleanup
  shutdown_glut();

  //cleanup
  delete thread_info;
  return NULL;
}
Esempio n. 22
0
//=============================================================
// OpenGL functionality
// http://www.andyofniall.net/2d-graphics-with-opengl/
//=============================================================
void plot_init_opengl(){
  int argc = 1;
  char *argv = (char*)malloc(sizeof(char)*42);
  sprintf(argv, "./entbody");

  glutInit(&argc, &argv);	         
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
  glutInitWindowSize(plot_sizex, plot_sizey);
  glutInitWindowPosition(100,100);
  win = glutCreateWindow("EntBody Simulation");	

  glDisable(GL_DEPTH_TEST);
  glClearColor(1.0, 1.0, 1.0, 0.0);	/* set background to white */
  glutKeyboardFunc(key_down);
  glutKeyboardUpFunc(key_up);
  glViewport(0,0,plot_sizex, plot_sizey);

  glutMainLoopEvent();
  free(argv);
}
Esempio n. 23
0
	void GlutApp::run()
	{
		onRun();

		const DWORD SKIP_TICKS = 1000 / fps_;
		game_is_running_ = true;
		
		while(game_is_running_){
			DWORD start_time = GetTickCount();

			glutMainLoopEvent();
			update();
			render();

			// lock FPS
			while((GetTickCount() - start_time) < SKIP_TICKS);
		}

		onStop();
	}
Esempio n. 24
0
/////////////////////////////////////////////////////////
// dimensionsMess
//
/////////////////////////////////////////////////////////
void gemglutwindow :: dimensionsMess(unsigned int width, unsigned int height)
{
  if (width <= 0) {
    error("width must be greater than 0");
    return;
  }

  if (height <= 0 ) {
    error ("height must be greater than 0");
    return;
  }
  m_width = width;
  m_height = height;
  if(makeCurrent()){
    glutReshapeWindow(width, height);
    glutHideWindow();glutShowWindow();
    glutPositionWindow(m_xoffset, m_yoffset);
    glutMainLoopEvent();
  }
}
Esempio n. 25
0
 void InputControl::processEvents(void) {
   Lock<MutexSys> lock(inputControlMutex);
   if (UNLIKELY(inputControl == NULL)) {
     init();
     this->dt = inf;
     this->time = lastTime = getSeconds();
   } else {
     this->time = getSeconds();
     this->dt = this->time - lastTime;
     lastTime = this->time;
   }
   inputControl = this;
   glutMainLoopEvent();
   glutWarpPointer(this->w/2, this->h/2);
   const int w0 = glutGet(GLUT_WINDOW_WIDTH);
   const int h0 = glutGet(GLUT_WINDOW_HEIGHT);
   if (w0 != this->w || h0 != this->h) this->isResized = 1;
   this->w = w0;
   this->h = h0;
   previousInput = this;
 }
Esempio n. 26
0
void calc_and_publish_BWMask(const ros::Time time_stamp, const std::string frame_id)
{
    robmod->updateRobotLinks(time_stamp);
#ifdef USE_GLUT_RENDERING
    glutPostRedisplay();
    glutMainLoopEvent();
#else
    displayFunc();
#endif // USE_GLUT_RENDERING
    cvCvtColor(ipl_maskBGRA, ipl_maskBW, CV_BGRA2GRAY);
    cvFlip(ipl_maskBW);
    if (inverted)
        cvNot(ipl_maskBW,ipl_maskBW);


    if(publish_mask){
        sensor_msgs::ImagePtr img_msg = sensor_msgs::CvBridge::cvToImgMsg(ipl_maskBW);
        img_msg->header.frame_id = frame_id;
        img_msg->header.stamp = time_stamp;
        mask_publisher.publish(img_msg);
    }

}
Esempio n. 27
0
void freeglut::StartMainLoop() {
    running = true;
    if (MainLoopLock->TryLock() == wxMUTEX_NO_ERROR) {
        int tmpWindow = glutCreateWindow("GLEW init");
        glutShowWindow();
        initGlew();
        std::cout << "OpenGL: " << glGetString(GL_VENDOR) << std::endl;
        std::cout << "OpenGL: " << glGetString(GL_RENDERER) << std::endl;
        std::cout << "OpenGL: " << glGetString(GL_VERSION) << std::endl;
        glutHideWindow();
        glutDestroyWindow(tmpWindow);
        
        unsigned int displayMode = GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL;
        glutInitDisplayMode (displayMode);
        glutInitContextVersion (3, 0);
        glutInitContextProfile(GLUT_CORE_PROFILE);
        
        glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
        
        while (running) {
            glutMainLoopEvent();
            QueueLock->Lock();
            if (!callbackQueue.empty()) {
                callbackQueue.front()->callback();
                callbackQueue.pop();
            }
            QueueLock->Unlock();
        }
        
        for (std::map<int,freeglutWindow*>::iterator it=windows.begin(); it!=windows.end(); ++it) {
            glutDestroyWindow(it->first);
        }
        windows.clear();
    
        MainLoopLock->Unlock();
    }
}
Esempio n. 28
0
/** Documented at declaration */
int
view_glut(struct view* view)
{
    int argc = 0;
    glutInit(&argc, NULL);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA);
    glutCreateWindow("OpenGL and CUDA");
    glutReshapeWindow(view->window_width, view->window_height);
    glutDisplayFunc(view_glut_render);
    glutKeyboardFunc(view_glut_keyboard);
    glutIdleFunc(view_glut_render);

    view_init(view);
    
    g_glut_view = view;
    
    glutPostRedisplay();
    while( g_glut_view != NULL ) {
        glutMainLoopEvent();
    }
    glutHideWindow();
    
    return 0;
}
Esempio n. 29
0
void Window::update() {
    glutMainLoopEvent();
}
Esempio n. 30
0
void Window::render()
{
	glutSwapBuffers();
	glutMainLoopEvent();
}