删除我的程序的剩余部分围绕glutMainLoop? [英] Excuting the rest of my programme around glutMainLoop?

查看:181
本文介绍了删除我的程序的剩余部分围绕glutMainLoop?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在一个项目,其中一个andoid应用程序,我已经写在我的OpenGL窗口中的控制和对象在PC上。 Ive得到了OpenGL窗口做我想要的和ive从我的Android设备的数据流到一个终端。但是我需要将数据流传输到终端以供OpenGL对象使用。当我尝试和运行它们在同一个脚本,它只是卡在'glutMainLoop',从来没有达到一个点,我的设备的连接建立。我知道这是一个comman问题与glutMainLoop。我在寻找任何建议。我要走错路吗?有更好的方法吗?我已附加我的代码如下:

I'm currently working on a project where an andoid app that I've written controls and object in my OpenGL window on the PC. Ive got the OpenGL window to do what I want and ive got the data from my android device to stream to a terminal. However I need the data being streamed to the terminal to be used by the OpenGL object. When I try and run them in the same script it just gets stuck in the 'glutMainLoop' and never reaches a point where connection to my device is established. I know this is a comman problem with the glutMainLoop. I'm looking for any advice. Am I going about it the wrong way? Is there a better approch? I have attached my code below:

 #include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <strings.h>
#include <vrpn_Shared.h>
#include <vrpn_Analog.h>
#include <vector>

#include <imageviewer.h>

using namespace std;

int done = 0;           // Signals that the program should exit
unsigned tracker_stride = 1;    // Every nth report will be printed


//-------------------------------------
// This section contains the data structure that holds information on
// the devices that are created.  For each named device, a remote of each
// type analog is created.

class device_info {
    public:
    char            *name;

    vrpn_Analog_Remote  *ana;

};
const unsigned MAX_DEVICES = 2;


//-------------------------------------
// This section contains the data structure that is used to determine how
// often to print a report for each sensor of each tracker.  Each element
// contains a counter that is used by the callback routine to keep track
// of how many it has skipped.  There is an element for each possible sensor.
// A new array of elements is created for each new tracker object, and a
// pointer to it is passed as the userdata pointer to the callback handlers.


class t_user_callback {
    public:
    char            t_name[vrpn_MAX_TEXT_LEN];
        vector<unsigned>    t_counts ;
};

//Callback handlers

void    VRPN_CALLBACK handle_analog (void *userdata, const vrpn_ANALOGCB a)
{
    int i;
    const char *name = (const char *)userdata;

    printf("Input from %s:\n  \n        %5.0f", name, a.channel[0]);
    for (i = 1; i < a.num_channel; i++) {
    printf(" %5.0f \n", a.channel[1]);
    }
    printf(" \n");
}


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

  int   print_for_tracker = 1;  // Print tracker reports?
  int   print_for_button = 1;   // Print button reports?
  int   print_for_analog = 1;   // Print analog reports?
  int   print_for_dial = 1; // Print dial reports?
  int   print_for_text = 1; // Print warning/error messages?

  device_info device_list[MAX_DEVICES];
  unsigned num_devices = 0;

  int i;

  // Parse arguments, creating objects as we go.  Arguments that
  // change the way a device is treated affect all devices that
  // follow on the command line.
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-notracker")) {
      print_for_tracker = 0;
    } else if (!strcmp(argv[i], "-nobutton")) {
      print_for_button = 0;
    } else if (!strcmp(argv[i], "-noanalog")) {
      print_for_analog = 0;
    } else if (!strcmp(argv[i], "-nodial")) {
      print_for_dial = 0;
    } else if (!strcmp(argv[i], "-notext")) {
      print_for_text = 0;
    } else if (!strcmp(argv[i], "-trackerstride")) {
      if (tracker_stride <= 0) {
      fprintf(stderr, "-trackerstride argument must be 1 or greater\n");
      return -1;
      }
    } else {    // Create a device and connect to it.
    device_info *dev;

    // Make sure we have enough room for the new device
    if (num_devices == MAX_DEVICES) {
        fprintf(stderr,"Too many devices!\n");
        exit(-1);
    }

    // Name the device and open it as everything
    dev = &device_list[num_devices];
    dev->name = argv[i];

    dev->ana = new vrpn_Analog_Remote(dev->name);

    if ( (dev->ana == NULL) ){         
        fprintf(stderr,"Error opening %s\n", dev->name);
        return -1;
    } else {
        printf("Opened %s as:", dev->name);
    }
    if (print_for_analog) {
        printf(" Analog");
        dev->ana->register_change_handler(dev->name, handle_analog);
    }
    printf(".\n");
    num_devices++;
    }

  }


 // main interactive loop

  printf("Press ^C to exit.\n");
  while ( ! done ) {
      unsigned i;

      // Let all the devices do their things
      for (i = 0; i < num_devices; i++) {

      device_list[i].ana->mainloop();

      glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowSize(400,300);
    glutInitWindowPosition(200,100);
    glutCreateWindow("ImageViewer");


    init();
    glutDisplayFunc(display);
    glutMotionFunc(drag);
    glutMouseFunc(mouse);
    glutMainLoop();


      }
  }
 return 0;
}  



// a.channel[0] =  x
// a.channel[1] =  y
// a.channel[2] =  Zoom?


推荐答案

您可以停止使用GLUT。 GLFW 可让您更好地控制环路,以便更容易进行其他处理。

You could stop using GLUT. GLFW gives you better control over the loop, so that it's easier to do other processing.

如果你坚持使用GLUT,并且你使用FreeGLUT,你可以使用 glutMainLoopEvent 。此函数处理主循环的一次迭代。所以你可以把它在一个无限循环,并重复调用它。作为该循环的一部分,您可以执行其他操作,例如从终端中提取数据或任何内容。

If you insist on using GLUT, and you're using FreeGLUT, then you can use glutMainLoopEvent. This function processes one iteration of the main loop. So you can just stick it in an infinite loop and call it repeatedly. As part of that loop, you can do other things, like pulling data from the terminal or whatever.

这篇关于删除我的程序的剩余部分围绕glutMainLoop?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆