2012-04-14 13 views
1

Ich arbeite gerade an einem Projekt, wo eine Andoid-App, die ich geschrieben habe, in meinem OpenGL-Fenster auf dem PC steuert und Objekt. Ich habe das OpenGL-Fenster, um zu tun, was ich will, und ich habe die Daten von meinem Android-Gerät, um an ein Terminal zu streamen. Allerdings müssen die Daten an das Terminal gestreamt werden, damit sie vom OpenGL-Objekt verwendet werden können. Wenn ich versuche, sie im selben Skript auszuführen, bleibt sie im "glutMainLoop" hängen und erreicht nie einen Punkt, an dem die Verbindung zu meinem Gerät hergestellt wird. Ich weiß, das ist ein Comman-Problem mit dem glutMainLoop. Ich suche nach einem Rat. Gehe ich falsch herum? Gibt es eine bessere Annäherung? Ich habe meinen Code unten angehängt:Den Rest meines Programms um glutMainLoop ausführen?

#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? 

Antwort

2

Sie könnten aufhören, GLUT zu verwenden. GLFW gibt Ihnen eine bessere Kontrolle über die Schleife, so dass es einfacher ist, andere Verarbeitung zu machen. Wenn Sie darauf bestehen, GLUT zu verwenden, und Sie FreeGLUT verwenden, können Sie glutMainLoopEvent verwenden. Diese Funktion verarbeitet eine Iteration der Hauptschleife. Sie können es einfach in eine Endlosschleife stecken und es wiederholt aufrufen. Als Teil dieser Schleife können Sie andere Dinge tun, wie das Ziehen von Daten vom Terminal oder was auch immer.

+0

Vielen Dank für die Antwort! Leider wird die Anwendung bei meinen Maschinen nur bei GLUT verwendet. Ich versuche deine Lösung und melde dich wieder. Danke noch einmal! – user1194366

+0

@ user1194366: Es gibt keine von GLUT unterstützte Plattform, an der FreeGLUT und GLFW nicht arbeiten. Alles, was Sie tun müssen, ist, die entsprechende DLL mit Ihrer EXE-Datei zu versenden oder einfach nur statisch zu verlinken. –

+0

Ja, ich verstehe das, aber die Anwendung wird auf einer Powerwall ausgeführt, wo Glut-Befehle von Chromium erfasst und auf vielen hochauflösenden Monitoren gerendert werden. Chromium funktioniert nur mit Standardbibliotheken. – user1194366

0

Freeglut Angebote glutMainLoopEvent, so können Sie Ihren Laufmodus wählen.

+0

danke für den Rat, aber das hat nicht für mich funktioniert. Ich bin mit dem glutIdleFuc gegangen. Funktioniert perfekt – user1194366

Verwandte Themen