iCub-main
Loading...
Searching...
No Matches
subtitilessthread.h
Go to the documentation of this file.
1#ifndef SUBTITLESTHREAD_H
2#define SUBTITLESTHREAD_H
3
4#include <qthread.h>
5#include <yarp/os/BufferedPort.h>
6#include <qgl.h>
7
8
9#ifdef __APPLE__
10#include <OpenGL/glu.h>
11#else
12#include <GL/glu.h>
13#endif
14
15#include <string.h>
16extern std::string GUI_NAME;
17
19{
20 yarp::os::BufferedPort<yarp::os::Bottle> mTxtMsgPort;
21 yarp::os::BufferedPort<yarp::os::Bottle> mTxtDbgPort;
22
23public:
24 SubtitlesManager(const char *objPortName,const char *texPortName)
25 {
26 mTxtMsgPort.open((GUI_NAME+objPortName).c_str());
27 mTxtDbgPort.open((GUI_NAME+texPortName).c_str());
28
29 mTxtMsgPort.setStrict();
30 mTxtDbgPort.setStrict();
31
32 /*
33 mPx=mPy=mPz=0.0;
34 mRx=mRy=mRz=0.0;
35 for (int i=0; i<3; ++i)
36 for (int j=0; j<3; ++j)
37 R[i][j]=(double)(i==j);
38 */
39 }
40
42 {
43 mTxtMsgPort.interrupt();
44 mTxtMsgPort.close();
45
46 mTxtDbgPort.interrupt();
47 mTxtDbgPort.close();
48 }
49
50 void draw()
51 {
52 static double txtWatchDogStart = yarp::os::Time::now();
53 static double dbgWatchDogStart = yarp::os::Time::now();
54 static std::string txtMsg;
55 static std::string dbgMsg;
56
57 Bottle* msg = mTxtMsgPort.read(false);
58 Bottle* dbg = mTxtDbgPort.read(false);
59
60 if (msg !=0)
61 {
62 txtMsg= msg->get(0).asString().c_str();
63 txtWatchDogStart = yarp::os::Time::now();
64 }
65 if (dbg !=0)
66 {
67 dbgMsg = dbg->get(0).asString().c_str();
68 dbgWatchDogStart = yarp::os::Time::now();
69 }
70
71 if (yarp::os::Time::now()-txtWatchDogStart < 3.0 && !txtMsg.empty())
72 {
73 drawText("iCub: ",txtMsg.c_str(),1.0f,1.0f,1.0f);
74 }
75
76 if (yarp::os::Time::now()-dbgWatchDogStart < 3.0 && !dbgMsg.empty())
77 {
78 drawText("Dbg: ",dbgMsg.c_str(),1.0f,1.0f,1.0f);
79 }
80
81 }
82
83 void drawText(const char* speaker, const char* text, float r, float g, float b)
84 {
85 glLoadIdentity();
86 glColor3f(r, g, b);
87 glTranslatef(-4.0f, -2.5f, -5.0f);
88 glRasterPos2i(0,0);
89
90 glDisable(GL_LIGHTING);
91 //glRasterPos3f(0,0,0);
92
93 static char tmp[1024];
94 strcpy (tmp,speaker);
95 strcat (tmp,text);
96 for (int i=0; tmp[i]!='\0'; ++i)
97 {
98 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,tmp[i]);
99 }
100 glEnable(GL_LIGHTING);
101 }
102
103};
104
105
106#endif
SubtitlesManager(const char *objPortName, const char *texPortName)
void drawText(const char *speaker, const char *text, float r, float g, float b)
std::string GUI_NAME