20 #ifdef FARSA_USE_YARP_AND_ICUB
23 #include <QApplication>
24 #include <QGLPixelBuffer>
29 # include <GLUT/glut.h>
34 using namespace yarp::dev;
35 using namespace yarp::sig;
36 using namespace yarp::os;
38 #define GLMultMatrix glMultMatrixf
43 RenderCamera::RenderCamera( WCamera* wcamera, WObject* attachTo,
unsigned int width,
unsigned int height )
44 : RenderWObjectContainer() {
45 connect( world(), SIGNAL( removedObject( WObject* ) ),
46 this, SLOT( slotRemoveObject( WObject* ) ), Qt::DirectConnection );
47 connect( world(), SIGNAL( addedObject( WObject* ) ),
48 this, SLOT( slotAddObject( WObject* ) ), Qt::DirectConnection );
50 this->attachTo = attachTo;
52 this->heightv = height;
53 aspectRatio = 112.0f/94.0f;
54 this->wcamera = wcamera;
56 frameBuffer =
new unsigned char[width*height*3];
57 frameImage.setQuantum(1);
58 frameImage.setExternal( frameBuffer, width, height );
59 frameImage.setTopIsLowIndex(
true );
60 pbuffer =
new QGLPixelBuffer( width, height );
64 RenderCamera::~RenderCamera() {
71 QMutexLocker locker(&
mutex);
76 eyep = tm.w_pos + tm.z_ax.
scale(0.021f);
82 pbuffer->makeCurrent();
86 glDisable(GL_LIGHTING);
87 glDisable(GL_COLOR_MATERIAL);
89 glEnable(GL_DEPTH_TEST);
90 glClearColor( 0.2f, 0.2f, 0.2f, 1.0f );
91 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
92 glViewport( 0, 0, GLint(widthv), GLint(heightv) );
93 pbuffer->doneCurrent();
99 QMutexLocker locker(&
mutex);
102 pbuffer->makeCurrent();
103 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
105 glMatrixMode(GL_PROJECTION);
107 gluPerspective( 94.0, aspectRatio, 0.001 , 1000.0 );
109 glMatrixMode(GL_MODELVIEW);
111 gluLookAt( eyep[0], eyep[1], eyep[2], atp[0], atp[1], atp[2], upv[0], upv[1], upv[2] );
117 for(
int i=0; i<
graphics().size(); i++ ) {
119 if ( r->
object() == attachTo )
continue;
120 if ( r->
object() == wcamera )
continue;
123 r->render( (QGLContext*)(QGLContext::currentContext()) );
125 glReadPixels( 0, 0, widthv, heightv, GL_RGB, GL_UNSIGNED_BYTE, frameBuffer );
126 pbuffer->doneCurrent();
129 void RenderCamera::slotRemoveObject(
WObject* w ) {
133 void RenderCamera::slotAddObject( WObject* w ) {
149 int RenderCamera::height()
const {
153 int RenderCamera::width()
const {
157 bool RenderCamera::getImage( yarp::sig::ImageOf<yarp::sig::PixelRgb>& image ) {
158 image.setTopIsLowIndex(
false );
159 image.copy( frameImage );
171 images =
new RenderCamera(
this, attachTo, width, height );
175 this->attachTo = attachTo;
177 w->pushObject(
this );
179 porty.open( QString(
"/%1/%2" ).arg(
world()->
name() ).arg( name ).toAscii().data() );
193 this->attachTo = NULL;
195 w->pushObject(
this );
197 porty.open( QString(
"/%1/%2" ).arg(
world()->
name() ).arg( name ).toAscii().data() );
211 if ( !images )
return;
213 ImageOf<PixelRgb>& frame = porty.prepare();
214 images->getImage( frame );
220 #endif // FARSA_USE_YARP_AND_ICUB