Exemple #1
0
void GLWidget::paintGL() {
    QPainter painter;
    painter.begin(this);

    painter.beginNativePainting();
    if (this->scene != NULL){
               direct_render();

    }
    painter.endNativePainting();


    painter.setPen(Qt::white);

    int fps = tFPS->restart();

    if(NULL != this->camera){
        this->camera->setYRotation(this->camera->getYRot() + (float)fps/60.0);
    }

    painter.drawText(20, 40, QString::number(1000/fps) + " fps");

    painter.end();

   swapBuffers();


}
void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
{
    m_context->markLayerComposited();
    blitMultisampleFramebufferAndRestoreContext();

    if (textureMapper->accelerationMode() == TextureMapper::OpenGLMode) {
        TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper);
        TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture | (m_context->m_attrs.alpha ? TextureMapperGL::ShouldBlend : 0);
        IntSize textureSize(m_context->m_currentWidth, m_context->m_currentHeight);
        texmapGL->drawTexture(m_context->m_texture, flags, textureSize, targetRect, matrix, opacity);
        return;
    }

    // Alternatively read pixels to a memory buffer.
    GraphicsContext* context = textureMapper->graphicsContext();
    QPainter* painter = context->platformContext();
    painter->save();
    painter->setTransform(matrix);
    painter->setOpacity(opacity);

    const int height = m_context->m_currentHeight;
    const int width = m_context->m_currentWidth;

    painter->beginNativePainting();
    makeCurrentIfNeeded();
    glBindFramebuffer(GL_FRAMEBUFFER, m_context->m_fbo);
    QImage offscreenImage = qt_gl_read_framebuffer(QSize(width, height), true, true);
    glBindFramebuffer(GL_FRAMEBUFFER, m_context->m_state.boundFBO);

    painter->endNativePainting();

    painter->drawImage(targetRect, offscreenImage);
    painter->restore();
}
Exemple #3
0
void OGLWidget::paintGL()
{
	QPainter painter;
	painter.begin(this);

	painter.beginNativePainting();

	static const GLfloat black[] ={0.2, 0.3, 0.4, 1.0f};
	static const GLfloat one[] ={1.0f};
	glClearBufferfv(GL_COLOR, 0, black);
	glClearBufferfv(GL_DEPTH, 0, one);

	m_Camera.update();

	m_Model = glm::rotate(glm::mat4(1.0f), 30.0f, glm::vec3(1.0f, 1.0f, 1.0f));
	m_View  = m_Camera.GetView();
	m_Proj  = m_Camera.GetProj();

	cube.render(m_Model, m_View, m_Proj);


	painter.endNativePainting();


	static bool startFlag = true;
	if ( startFlag )
	{
		time.start();
		startFlag = false;
	}
	static int frame = 0;
	static float lastTime = 0.0f;
	float currentTime = time.elapsed()/1000.0f;
	static int cnt = 0;
	std::cout<<currentTime<<std::endl;

	if ( currentTime-lastTime>1.0f )
	{
		lastTime = currentTime;
		cnt = frame;
		frame = 0;
	}
	else
	{
		++frame;
	}

	QString fps  = QString::number(cnt);
	painter.setPen(Qt::white);
	painter.drawText(50.0, 50.0, QString("FPS:"+fps));

	painter.end();

	update();
}
void ImageBufferDataPrivateAccelerated::commitChanges() const
{
    if (!m_fboDirty)
        return;

    // this will flush pending QPainter operations and force ensureActiveTarget() to be called on the next paint
    QPainter* painter = m_pdev->paintEngine()->painter();
    painter->beginNativePainting();
    painter->endNativePainting();

    m_fboDirty = false;
}
Exemple #5
0
void QSceneWidget::paintGL()
{
  //makeCurrent();
  QPainter painter;
  painter.begin(this);
  painter.setRenderHint(QPainter::Antialiasing);
  
  /*glGenTextures(1, &m_leftTexture);*/
  m_leftTexture = bindTexture(QImage((data_pointer)left->data, left->width, 
                               left->height, QImage::Format_RGB888),
                               GL_TEXTURE_2D
                             );
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  /*glGenTextures(1, &m_rightTexture);*/
  m_rightTexture = bindTexture(QImage((data_pointer)right->data, right->width, 
                               right->height, QImage::Format_RGB888),
                               GL_TEXTURE_2D
                              );
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  
  painter.beginNativePainting();
  //glGetIntegerv(GL_VIEWPORT, params);
  //glGetFloatv(GL_DEPTH_RANGE, depth);
  //glDepthRangef(1.0f, 500.0f);

  /* may need to remove clearing color buffer if draw image */
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  
  glFrontFace(GL_CCW);
  
  glCullFace(GL_FRONT);
  glEnable(GL_CULL_FACE);
  glEnable(GL_DEPTH_TEST);
  //glEnable(GL_BLEND);
  
  double ipd = 0.064;
  double leftEye[3] = { -0.5*ipd, 0.15, 0.1 };
  double rightEye[3] = { 0.5*ipd, 0.15, 0.1 };
  
  float hscreensize = 0.14976f;
  float lensseparation = 0.0635f;
  float viewCenter = hscreensize * 0.25f;
  float eyeProjectionShift = viewCenter - lensseparation*0.5f;
  double offs = 4.0f * eyeProjectionShift / hscreensize;
  GLsizei halfwidth = this->width() / 2;
  GLsizei yoff = (this->height() - halfwidth) / 2;
  QMatrix4x4 mproj, mview, mobj;
  
  /* render left eye view */
  glViewport(0, yoff, halfwidth, halfwidth);
  //std::cout << offs << std::endl;
  mproj.setToIdentity();
  // offset translate operation for left eye
  mproj.translate(offs, 0.0f, 0.0f);
  mproj *= perspectiveMatrix;
  
  mview.setToIdentity();
  /*mview.translate(offs, 0.1f, -0.2f);*/
  
  mobj.setToIdentity();
  //mobj.translate(0.1f, 0.1f, 0.1f);
  mobj *= mview;
  mobj *= mproj;
  
  program2.bind();
  program2.setUniformValue(matrixUniform2, mobj);
  paintTexturedQuad(m_leftTexture);
  program2.release();

  mobj.setToIdentity();
  mobj.translate(-0.1f, -0.1f, 0.1f);
  mobj *= mview;
  mobj *= mproj;
  program1.bind();
  program1.setUniformValue(matrixUniform1, mobj);
  paintTriangle();
  program1.release();
  
  mobj.setToIdentity();
  mobj.translate(0.4f, 0.2f, 0.3f);
  mobj *= mview;
  mobj *= mproj;
  program1.bind();
  program1.setUniformValue(matrixUniform1, mobj);
  paintTriangle();
  program1.release();
  
  glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
  glPushMatrix();
  glTranslatef(10.0f, 100.0f, 0.8f);
  //glScalef(0.5, -0.5, 0.5);
  glutStrokeCharacter(GLUT_STROKE_ROMAN, 'T');
  glutStrokeCharacter(GLUT_STROKE_ROMAN, 'e');
  glutStrokeCharacter(GLUT_STROKE_ROMAN, 's');
  glutStrokeCharacter(GLUT_STROKE_ROMAN, 't');
  glPopMatrix();
  
  /* render right eye view */
  glViewport(halfwidth, yoff, halfwidth, halfwidth);
  
  mproj.setToIdentity();
  // offset translate operation for left eye
  mproj.translate(-offs, 0.0f, 0.0f);
  mproj *= perspectiveMatrix;
  
  mview.setToIdentity();
  /*mview.translate(0.0f, 0.1f, -0.2f);*/
  
  mobj.setToIdentity();
  //mobj.translate(0.1f, 0.1f, 0.1f);
  mobj *= mview;
  mobj *= mproj;
  
  program2.bind();
  program2.setUniformValue(matrixUniform2, mobj);
  paintTexturedQuad(m_rightTexture);
  program2.release();
  
  mobj.setToIdentity();
  mobj.translate(-0.1f, -0.1f, 0.1f);
  mobj *= mview;
  mobj *= mproj;
  program1.bind();
  program1.setUniformValue(matrixUniform1, mobj);
  paintTriangle();
  program1.release();
  
  mobj.setToIdentity();
  mobj.translate(0.4f, 0.2f, 0.3f);
  mobj *= mview;
  mobj *= mproj;
  program1.bind();
  program1.setUniformValue(matrixUniform1, mobj);
  paintTriangle();
  program1.release();
  
  glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
  glPushMatrix();
  glTranslatef(10.0f, 100.0f, 0.8f);
  //glScalef(0.5, -0.5, 0.5);
  glutStrokeCharacter(GLUT_STROKE_ROMAN, 'T');
  glutStrokeCharacter(GLUT_STROKE_ROMAN, 'e');
  glutStrokeCharacter(GLUT_STROKE_ROMAN, 's');
  glutStrokeCharacter(GLUT_STROKE_ROMAN, 't');
  glPopMatrix();

  //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  
  //glFrontFace(GL_CCW);
  
  //glCullFace(GL_FRONT);
  //glEnable(GL_CULL_FACE);
  //glEnable(GL_DEPTH_TEST);
  //glEnable(GL_BLEND);

  // load identity matrix
  // set the viewport (should be set already?)
  // disable stencil buffer (?)
  
  //glDisable(GL_BLEND);
  //glDisable(GL_DEPTH_TEST);
  //glDisable(GL_CULL_FACE);

  painter.endNativePainting();
  
  //painter.setPen(QPen(Qt::yellow));
  //painter.drawText(QPoint(5, 20), this->fps);
  
  painter.end();
  swapBuffers();
}
Exemple #6
0
void MainWidget::paintGL()
{

    makeCurrent();

    QPainter painter;
    painter.begin(this);
    painter.beginNativePainting();

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    // Enable depth buffer

    if(bDepthTest)
        glEnable(GL_DEPTH_TEST);

    QQuaternion quat = this->trackball.rotation();

    // Calculate model view transformation
    QMatrix4x4 modelviewearth;
    modelviewearth.translate(0.0, 0.0, distance);
    modelviewearth.rotate(quat);

    QMatrix4x4 rotmatrix;
    rotmatrix.rotate(quat);

    programskybox.bind();
    skybox->render(projection, modelviewearth, rotmatrix);
    programskybox.release();


    if(bWireFrame) // Draw as wireframe
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    else
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    if(bTexture)
    {
        if(bNoBump)
        {
            programearthnobump.bind();
            textureearth->bind(0);
            geometries->render(projection, modelviewearth, bNoBump);
            textureearth->release();
            programearthnobump.release();
        }
        else
        {
            programearth.bind();
            textureearth->bind(0);
            texturenormal->bind(1);
            geometries->render(projection, modelviewearth, bNoBump);

            texturenormal->release();
            textureearth->release();
            programearth.release();
        }
    }

    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    if(bBorders)
    {
        programgshhs.bind();
        gshhs->render(projection, modelviewearth);
        gshhs->rendersoc(projection, modelviewearth);
        programgshhs.release();
    }

    glDisable(GL_DEPTH_TEST);

    painter.endNativePainting();

    QString framesPerSecond;
    if (const int elapsed = m_time.elapsed()) {
        framesPerSecond.setNum(m_frames /(elapsed / 1000.0), 'f', 2);
        painter.setPen(Qt::white);
        painter.drawText(20, 40, framesPerSecond + " paintGL calls / s");
    }

    //this->setWindowTitle(framesPerSecond + " paintGL calls / s" );

    painter.end();

    if (!(m_frames % 100)) {
        m_time.start();
        m_frames = 0;
    }
    ++m_frames;

}
Exemple #7
0
void KisMirrorAxis::drawDecoration(QPainter& gc, const QRectF& updateArea, const KisCoordinatesConverter* converter, KisCanvas2* canvas)
{
    Q_UNUSED(updateArea);
    Q_UNUSED(converter);
    Q_UNUSED(canvas);

    gc.setPen(QPen(QColor(0, 0, 0, 128), 1));
    gc.setBrush(Qt::white);
    gc.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

    QOpenGLContext *ctx = QOpenGLContext::currentContext();
    bool hasMultisample = ((gc.paintEngine()->type() == QPaintEngine::OpenGL2) &&
                           (ctx->hasExtension("GL_ARB_multisample")));

    // QPainter cannot anti-alias the edges of circles etc. when using OpenGL
    // So instead, use native OpenGL anti-aliasing when available.
    if (hasMultisample) {
        gc.beginNativePainting();
        ctx->functions()->glEnable(GL_MULTISAMPLE);
        gc.endNativePainting();
    }

    float halfHandleSize = d->handleSize / 2;

    d->recomputeVisibleAxes(gc.viewport());

    if(d->mirrorHorizontal) {
        if (!d->horizontalAxis.isNull()) {
           // QPointF horizontalIndicatorCenter = d->horizontalAxis.unitVector().pointAt(15);
           // QRectF horizontalIndicator = QRectF(horizontalIndicatorCenter.x() - halfHandleSize, horizontalIndicatorCenter.y() - halfHandleSize, d->handleSize, d->handleSize);

            float horizontalHandlePosition = qBound<float>(d->minHandlePosition, d->horizontalHandlePosition, d->horizontalAxis.length() - d->minHandlePosition);
            QPointF horizontalHandleCenter = d->horizontalAxis.unitVector().pointAt(horizontalHandlePosition);
            d->horizontalHandle = QRectF(horizontalHandleCenter.x() - halfHandleSize, horizontalHandleCenter.y() - halfHandleSize, d->handleSize, d->handleSize);

            gc.setPen(QPen(QColor(0, 0, 0, 64), 2, Qt::DashDotDotLine, Qt::RoundCap, Qt::RoundJoin));
            gc.drawLine(d->horizontalAxis);

           // gc.drawEllipse(horizontalIndicator);
          //  gc.drawPixmap(horizontalIndicator.adjusted(5, 5, -5, -5).toRect(), d->horizontalIcon);

            gc.setPen(QPen(QColor(0, 0, 0, 128), 2));
            gc.drawEllipse(d->horizontalHandle);
            gc.drawPixmap(d->horizontalHandle.adjusted(5, 5, -5, -5).toRect(), d->horizontalIcon);

        } else {
            d->horizontalHandle = QRectF();
        }
    }

    if(d->mirrorVertical) {
        if (!d->verticalAxis.isNull()) {

            gc.setPen(QPen(QColor(0, 0, 0, 64), 2, Qt::DashDotDotLine, Qt::RoundCap, Qt::RoundJoin));
            gc.drawLine(d->verticalAxis);


           // QPointF verticalIndicatorCenter = d->verticalAxis.unitVector().pointAt(15);
           // QRectF verticalIndicator = QRectF(verticalIndicatorCenter.x() - halfHandleSize, verticalIndicatorCenter.y() - halfHandleSize, d->handleSize, d->handleSize);

            float verticalHandlePosition = qBound<float>(d->minHandlePosition, d->verticalHandlePosition, d->verticalAxis.length() - d->minHandlePosition);
            QPointF verticalHandleCenter = d->verticalAxis.unitVector().pointAt(verticalHandlePosition);
            d->verticalHandle = QRectF(verticalHandleCenter.x() - halfHandleSize, verticalHandleCenter.y() - halfHandleSize, d->handleSize, d->handleSize);

           // gc.drawEllipse(verticalIndicator);
          //  gc.drawPixmap(verticalIndicator.adjusted(5, 5, -5, -5).toRect(), d->verticalIcon);
            gc.setPen(QPen(QColor(0, 0, 0, 128), 2));
            gc.drawEllipse(d->verticalHandle);
            gc.drawPixmap(d->verticalHandle.adjusted(5, 5, -5, -5).toRect(), d->verticalIcon);
        } else {
            d->verticalHandle = QRectF();
        }
    }

    if (hasMultisample) {
        gc.beginNativePainting();
        ctx->functions()->glDisable(GL_MULTISAMPLE);
        gc.endNativePainting();
    }

}
Exemple #8
0
void Viewport::drawBins(QPainter &painter, QTimer &renderTimer,
                        unsigned int &renderedLines, unsigned int renderStep,
                        bool highlight)
{
	SharedDataLock ctxlock(ctx->mutex);
	// TODO: this also locks shuffleIdx implicitely, better do it explicitely?
	SharedDataLock setslock(sets->mutex);

	// Stopwatch watch("drawBins");

	/* initialize painting in GL, vertex buffer */
	target->makeCurrent();
	painter.beginNativePainting();
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	bool success = vb.bind();
	if (!success) {
		GerbilApplication::internalError(
		            "Vertex buffer could not be bound in viewport drawBins().",
		            false);
		painter.endNativePainting();
		return;
	}
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(2, GL_FLOAT, 0, 0);
	size_t iD = renderedLines * (*ctx)->dimensionality;

	/* determine drawing range. could be expanded to only draw spec. labels */
	// make sure that viewport draws "unlabeled" data in ignore-label case
	int start = ((showUnlabeled || (*ctx)->ignoreLabels == 1) ? 0 : 1);
	int end = (showLabeled ? (int)(*sets)->size() : 1);

	size_t total = shuffleIdx.size();
	size_t first = renderedLines;
	size_t last = std::min((size_t)(renderedLines + renderStep), total);

	// loop over all elements in vertex index, update element and vector indices
	for (size_t i = first; i < last;
	     ++i, iD += (*ctx)->dimensionality) {
		std::pair<int, BinSet::HashKey> &idx = shuffleIdx[i];

		// filter out according to label
		bool filter = ((idx.first < start || idx.first >= end));
		// do not filter out highlighted label(s)
		if (!(*ctx)->ignoreLabels) {
			filter = filter && !highlightLabels.contains(idx.first);
		}
		if (filter) {
			// increase loop count to achieve renderStep
			if (last < total)
				++last;
			continue;
		}

		BinSet::HashKey &K = idx.second;

		// highlight mode (foreground buffer)
		if (highlight) {

			//test if we are part of the highlight
			bool highlighted = false;
			if (limiterMode) {
				highlighted = true;
				for (size_t i = 0; i < (*ctx)->dimensionality; ++i) {
					unsigned char k = K[i];
					if (k < limiters[i].first || k > limiters[i].second)
						highlighted = false;
				}
			} else if ((unsigned char)K[selection] == hover) {
				highlighted = true;
			}

			// filter out
			if (!highlighted) {
				// increase loop count to achieve renderStep
				if (last < total)
					++last;
				continue;
			}
		}

		// grab binset and bin according to key
		BinSet &s = (**sets)[idx.first];
		std::pair<BinSet::HashMap::const_iterator, BinSet::HashMap::const_iterator> binitp =
		        s.bins.equal_range(K);
		if (s.bins.end() == binitp.first) {
			// FIXME this is an error and should be treated accordingly
			GGDBGM("no bin"<< endl);
			return;
		}
		Bin const &b = s.bins.equal_range(K).first->second;

		// set color
		QColor color = determineColor((drawRGB->isChecked() ? b.rgb : s.label),
		                              b.weight, s.totalweight,
		                              highlight,
		                              highlightLabels.contains(idx.first));
		target->qglColor(color);

		// draw polyline
		glDrawArrays(GL_LINE_STRIP, (GLsizei)iD, (GLint)(*ctx)->dimensionality);
	}
	vb.release();
	painter.endNativePainting();

	// setup succeeding incremental drawing
	renderedLines += (unsigned int)(last - first);
	if (renderedLines < total) {
		if (renderedLines <= renderStep) {
			renderTimer.start(150);
		} else {
			renderTimer.start(0);
		}
	}
}
void GLWidget::paintGL()
{

    QPainter painter;
    painter.begin(this);

    painter.beginNativePainting();


    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glFrontFace(GL_CW);
    glCullFace(GL_FRONT);
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    /* Disable for opaque colors. */
    glEnable(GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);



    mainModelView = QMatrix4x4(); // reset
    mainModelView.perspective(45.0, aspectRatio, 1.0, 400.0);
    mainModelView.lookAt(camera,QVector3D(0,0,0),QVector3D(0.0,1.0,0.0));

    mainModelView.translate(0,-1,0);


    dragX += gyroX * 0.008 * (1-dragging) * (headMovementOn);
    dragY += gyroY * 0.008 * (1-dragging) * (headMovementOn);

    if (zeroRotation && !dragging)
    {
	if (dragX > 0) dragX -= 0.01*dragX;
	if (dragX < 0) dragX -= 0.01*dragX;

	if (dragX < 0.009 && dragX > -0.009) dragX = 0;

	if (dragY > 0) dragY -= 0.01*dragY;
	if (dragY < 0) dragY -= 0.01*dragY;

	if (dragY < 0.009 && dragY > -0.009) dragY = 0;
    }

    if (dragX > 360) dragX -= 360;
    if (dragX < -360) dragX += 360;

    if (dragY > 360) dragY -= 360;
    if (dragY < -360) dragY += 360;

    mainModelView.rotate(dragY,1,0,0);
    mainModelView.rotate(dragX,0,0,1);

    mainModelView.rotate(180,0.0,0.0,1.0);
    mainModelView.translate(0,1,0);
    mainModelView.scale(1/4.5);


    model->draw(mainModelView);

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    glDisable(GL_BLEND);

    painter.endNativePainting();


    //Onscreen control


#ifdef Q_OS_MAC
#else
    painter.fillRect(quitRect,QColor(255,0,0,20));
    painter.drawRect(quitRect);
#endif


    if (sourceRecOn == 0)
    {
#ifdef Q_OS_MAC
	painter.setFont(QFont("helvetica",42,QFont::Bold));
#endif
	painter.setPen(QColor("white"));

	painter.fillRect(toggleRect,QColor(49,154,49));
	painter.drawText(toggleRect, Qt::AlignCenter, "start");
    }


    if (sourceRecOn)
    {
#ifdef Q_OS_MAC
	painter.setFont(QFont("helvetica",36,QFont::Bold));
#endif
	painter.setPen(QColor("white"));

	if (!deltaOn)
	    painter.fillRect(deltaRect,QColor(239,150,8));
	else
	    painter.fillRect(deltaRect,QColor(49,154,49));

	painter.drawText(deltaRect,Qt::AlignCenter,"1-4Hz"); //delta

	if (!thetaOn)
	    painter.fillRect(thetaRect,QColor(239,150,8));
	else
	    painter.fillRect(thetaRect,QColor(49,154,49));
	painter.drawText(thetaRect,Qt::AlignCenter,"4-8Hz"); //theta

	if (!alphaOn)
	    painter.fillRect(alphaRect,QColor(239,150,8));
	else
	    painter.fillRect(alphaRect,QColor(49,154,49));
	painter.drawText(alphaRect,Qt::AlignCenter,"8-12Hz"); //alpha

	if (!lowBetaOn)
	    painter.fillRect(lowBetaRect,QColor(239,150,8));
	else
	    painter.fillRect(lowBetaRect,QColor(49,154,49));
	painter.drawText(lowBetaRect,Qt::AlignCenter,"12-16Hz"); //low beta

	if (!betaOn)
	    painter.fillRect(betaRect,QColor(239,150,8));
	else
	    painter.fillRect(betaRect,QColor(49,154,49));
	painter.drawText(betaRect,Qt::AlignCenter,"16-20Hz"); //beta

    }

#ifdef Q_OS_MAC
    painter.setFont(QFont("helvetica",36,QFont::Bold));
#endif
    painter.setPen(QColor("white"));

    painter.fillRect(rotationRect,QColor(156,81,0));

    if (!headMovementOn)
	painter.drawText(rotationRect,Qt::AlignCenter,"rotation 1");
    if (headMovementOn && !zeroRotation)
	painter.drawText(rotationRect,Qt::AlignCenter,"rotation 2");
    if (headMovementOn && zeroRotation)
	painter.drawText(rotationRect,Qt::AlignCenter,"rotation 3");



#ifdef Q_OS_MAC
    painter.setFont(QFont("helvetica",36,QFont::Bold));
#endif
    painter.setPen(QColor(165,0,255));
    painter.drawText(infoTextRect,Qt::AlignCenter, infoText);



    painter.drawPixmap(logoRect, logoPixmap);
    painter.setPen(QColor(255,255,255,40));
    painter.drawRect(logoRect.x()-5, logoRect.y()-5, logoRect.width()+10, logoRect.height()+20);
#ifdef Q_OS_MAC
    painter.setFont(QFont("helvetica",28,QFont::Bold));
#endif
    painter.drawText(websiteRect,QString("github.com/SmartphoneBrainScanner"));


    if (infoPressed)
    {
	painter.fillRect(infoRect,QColor(0,0,0,180));
	painter.setPen(QColor(255,255,255));
	painter.drawRect(infoRect);
	painter.drawText(infoRect,Qt::AlignCenter, QString("Technical University of Denmark \n\n SmartphoneBrainScanner2: Tech Demo \n\n Jakob Eg Larsen, [email protected] \n Arkadiusz Stopczynski, [email protected] \n Carsten Stahlhut, [email protected] \n Michael Kai Petersen, [email protected] \n Lars Kai Hansen, [email protected]"));
    }

    painter.end();
    swapBuffers();

}
void DemoGLWidget::paintGL()
{
    // Render scene to FBO
    //render_fbo->bind();
    //glBindFramebuffer(GL_FRAMEBUFFER, fbo->frame);


    QPainter painter;
    painter.begin(this);
    Utils::setPainter(&painter);

    painter.beginNativePainting();

    float r = 0.05f;
    float g = 0.05f;
    float b = 0.2f;

    // Flash screen on snare hit
    float snareEnv = synth_get_current_envelope_for_instrument(4);

    if (snareEnv > 0.001f)
    {
        r += snareEnv * 0.2f;
        g += snareEnv * 0.2f;
        b += snareEnv * 0.2f;
    }

    glClearColor(r, g, b, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

    glFrontFace(GL_CW);
    glCullFace(GL_FRONT);

    painter.endNativePainting();


    // Create entities when an instrument is first played
    if (synth_get_current_note_for_instrument(0) != 0 &&
        critter == 0)
    {
        critter = new Critter(QPointF(500,200), 10, CRITTER_SPEED);
    }

    if (synth_get_current_note_for_instrument(1) != 0 &&
        entity1 == 0)
    {
        entity1 = new Entity(QPointF(300,200), 6, 3, 1);
        entities.append(entity1);
        entities.append(new Entity(QPointF(200,300), 10, 3, 1));
    }

    if (synth_get_current_note_for_instrument(2) != 0 &&
        entity2 == 0)
    {
        entity2 = new Entity(QPointF(300,200), 8, 3, 2);
        entities.append(entity2);
        entities.append(new Entity(QPointF(200,400), 10, 3, 2));
    }

    if (synth_get_current_note_for_instrument(3) != 0 &&
        entity3 == 0)
    {
        entity3 = new Entity(QPointF(300,200), 8, 3, 3);
        entities.append(entity3);
        entities.append(new Entity(QPointF(400,300), 12, 3, 3));
        entities.append(new Entity(QPointF(100,100), 7, 3, 3));
    }

    if (synth_get_current_note_for_instrument(4) != 0 &&
        entity4 == 0)
    {
        entity4 = new Entity(QPointF(300,200), 8, 3, 4);
        entities.append(entity4);
        entities.append(new Entity(QPointF(200,400), 12, 3, 4));
    }


    // Draw Entities and Critter    
    painter.setBrush(QBrush());

    // Move entities
    qreal minDistToCritter = 8000;
    static Entity* closestToCritter = 0;
    static int critterEnemyDetectionDelayer = 0;
    for(int i = 0; i < entities.size(); i++)
    {
        Entity *entity = entities[i];
        qreal distToCritter = 10000;

        // Use all entities as local flock for now
        QMutableListIterator<Entity*> localFlock(entities);

        entity->clearSteering();
        if (critter != 0)
        {
            entity->steerToTarget(critter->pos(), STEER_TO_TARGET_STRENGTH);
            distToCritter = entity->steerToAvoindWithinDistance(critter->pos(), STEER_AVOID_WITHIN_DISTANCE_STRENGTH);
        }
        entity->steerWithFlock(localFlock, STEER_SEPARATION_STRENGTH, STEER_COHESION_STRENGTH);
        entity->move();

        if(critterEnemyDetectionDelayer == 0 && distToCritter < minDistToCritter)
        {
            closestToCritter = entity;
            minDistToCritter = distToCritter;
        }
    }

    foreach (Entity *entity, entities)
    {
        entity->drawEntity(&painter);
    }