Example #1
0
void QGLView::drawTexts()
{
    QList<Parameters*>* parametersList = getDrawableList(Text);

    if (parametersList->isEmpty())
    {
        return;
    }

    m_textVertexBuffer->bind();
    m_textProgram->enableAttributeArray(m_textPositionLocation);
    m_textProgram->enableAttributeArray(m_textTexCoordinateLocation);
    m_textProgram->setAttributeBuffer(m_textPositionLocation, GL_FLOAT, 0, 3, sizeof(TextVertex));
    m_textProgram->setAttributeBuffer(m_textTexCoordinateLocation, GL_FLOAT, 3*sizeof(GLfloat), 2, sizeof(TextVertex));

    for (int i = 0; i < parametersList->size(); ++i)
    {
        TextParameters *textParameters = static_cast<TextParameters*>(parametersList->at(i));
        QStaticText staticText = textParameters->staticText;
        int textureIndex;
        QOpenGLTexture *texture;
        float aspectRatio;

        textureIndex = m_textTextList.indexOf(staticText);
        texture = m_textTextureList.at(textureIndex);
        aspectRatio = m_textAspectRatioList.at(textureIndex);

        if (!texture->isCreated()) // initialize texture on first use
        {
            createTextTexture(textParameters);
        }

        m_textProgram->setUniformValue(m_textAspectRatioLocation, aspectRatio);
        m_textProgram->setUniformValue(m_textAlignmentLocation, (GLint)textParameters->alignment);
        m_textProgram->setUniformValue(m_textColorLocation, textParameters->color);
        m_textProgram->setUniformValue(m_textModelMatrixLocation, textParameters->modelMatrix);
        m_textProgram->setUniformValue(m_textTextureLocation, texture->textureId());

        if (m_selectionModeActive)  // selection mode active
        {
            m_textProgram->setUniformValue(m_textIdColorLocation, QColor(0xFF000000u + m_currentDrawableId));    // color for selection mode
            m_drawableIdMap.insert(m_currentDrawableId, textParameters);
            m_currentDrawableId++;
        }

        texture->bind(texture->textureId());
        glDrawArrays(GL_TRIANGLES, 0, m_textVertexBuffer->size()/sizeof(TextVertex));
        texture->release(texture->textureId());
    }

    m_textProgram->disableAttributeArray(m_textPositionLocation);
    m_textProgram->disableAttributeArray(m_textTexCoordinateLocation);
    m_textVertexBuffer->release();
}
Example #2
0
GLuint NaviCubeImplementation::createCubeFaceTex(QtGLWidget* gl, float gap, float radius, const char* text) {
	int texSize = m_CubeWidgetSize* m_OverSample;
	int gapi = texSize * gap;
	int radiusi = texSize * radius;
	QImage image(texSize, texSize, QImage::Format_ARGB32);
	image.fill(qRgba(255, 255, 255, 0));
	QPainter paint;
	paint.begin(&image);

	if (text) {
		paint.setPen(Qt::white);
		QFont sansFont(str("Helvetica"), 0.1875 * texSize);
		paint.setFont(sansFont);
		paint.drawText(QRect(0, 0, texSize, texSize), Qt::AlignCenter,qApp->translate("Gui::NaviCube",text));
	}
	else {
		QPainterPath path;
		path.addRoundedRect(QRectF(gapi, gapi, texSize - 2 * gapi, texSize - 2 * gapi), radiusi, radiusi);
		paint.fillPath(path, Qt::white);
	}

	paint.end();
#if !defined(HAVE_QT5_OPENGL)
	return gl->bindTexture(image);
#else
    Q_UNUSED(gl);
    QOpenGLTexture *texture = new QOpenGLTexture(image.mirrored());
    m_glTextures.push_back(texture);
    return texture->textureId();
#endif
}
Example #3
0
GLuint NaviCubeImplementation::createMenuTex(QtGLWidget* gl, bool forPicking) {
	int texSize = m_CubeWidgetSize* m_OverSample;
	QImage image(texSize, texSize, QImage::Format_ARGB32);
	image.fill(qRgba(0, 0, 0, 0));
	QPainter painter;
	painter.begin(&image);

	QTransform transform;
	transform.translate(texSize * 12 / 16, texSize * 13 / 16);
	transform.scale(texSize/200.0,texSize/200.0); // 200 == size at which this was designed
	painter.setTransform(transform);

	QPainterPath path;

	if (forPicking) {
		path.addRoundedRect(-25,-8,75,45,6,6);
		painter.fillPath(path, Qt::white);
	}
	else {
		// top
		path.moveTo(0,0);
		path.lineTo(15,5);
		path.lineTo(0,10);
		path.lineTo(-15,5);

		painter.fillPath(path, QColor(240,240,240));

		// left
		QPainterPath path2;
		path2.lineTo(0,10);
		path2.lineTo(-15,5);
		path2.lineTo(-15,25);
		path2.lineTo(0,30);
		painter.fillPath(path2, QColor(190,190,190));

		// right
		QPainterPath path3;
		path3.lineTo(0,10);
		path3.lineTo(15,5);
		path3.lineTo(15,25);
		path3.lineTo(0,30);
		painter.fillPath(path3, QColor(220,220,220));

		// outline
		QPainterPath path4;
		path4.moveTo(0,0);
		path4.lineTo(15,5);
		path4.lineTo(15,25);
		path4.lineTo(0,30);
		path4.lineTo(-15,25);
		path4.lineTo(-15,5);
		path4.lineTo(0,0);
		painter.strokePath(path4, QColor(128,128,128));

		// menu triangle
		QPainterPath path5;
		path5.moveTo(20,10);
		path5.lineTo(40,10);
		path5.lineTo(30,20);
		path5.lineTo(20,10);
		painter.fillPath(path5, QColor(64,64,64));
		}
	painter.end();
#if !defined(HAVE_QT5_OPENGL)
	return gl->bindTexture(image);
#else
    Q_UNUSED(gl);
    QOpenGLTexture *texture = new QOpenGLTexture(image.mirrored());
    m_glTextures.push_back(texture);
    return texture->textureId();
#endif
}
Example #4
0
GLuint NaviCubeImplementation::createButtonTex(QtGLWidget* gl, int button) {
	int texSize = m_CubeWidgetSize * m_OverSample;
	QImage image(texSize, texSize, QImage::Format_ARGB32);
	image.fill(qRgba(255, 255, 255, 0));
	QPainter painter;
	painter.begin(&image);

	QTransform transform;
	transform.translate(texSize / 2, texSize / 2);
	transform.scale(texSize / 2, texSize / 2);
	painter.setTransform(transform);

	QPainterPath path;

	float as1 = 0.12f; // arrow size
	float as3 = as1 / 3;

	switch (button) {
	default:
		break;
	case TEX_ARROW_RIGHT:
	case TEX_ARROW_LEFT: {
		QRectF r(-1.00, -1.00, 2.00, 2.00);
		QRectF r0(r);
		r.adjust(as3, as3, -as3, -as3);
		QRectF r1(r);
		r.adjust(as3, as3, -as3, -as3);
		QRectF r2(r);
		r.adjust(as3, as3, -as3, -as3);
		QRectF r3(r);
		r.adjust(as3, as3, -as3, -as3);
		QRectF r4(r);

		float a0 = 72;
		float a1 = 45;
		float a2 = 38;

		if (TEX_ARROW_LEFT == button) {
			a0 = 180 - a0;
			a1 = 180 - a1;
			a2 = 180 - a2;
		}

		path.arcMoveTo(r0, a1);
		QPointF p0 = path.currentPosition();

		path.arcMoveTo(r2, a2);
		QPointF p1 = path.currentPosition();

		path.arcMoveTo(r4, a1);
		QPointF p2 = path.currentPosition();

		path.arcMoveTo(r1, a0);
		path.arcTo(r1, a0, -(a0 - a1));
		path.lineTo(p0);
		path.lineTo(p1);
		path.lineTo(p2);
		path.arcTo(r3, a1, +(a0 - a1));
		break;
	}
	case TEX_ARROW_EAST: {
		path.moveTo(1, 0);
		path.lineTo(1 - as1, +as1);
		path.lineTo(1 - as1, -as1);
		break;
	}
	case TEX_ARROW_WEST: {
		path.moveTo(-1, 0);
		path.lineTo(-1 + as1, -as1);
		path.lineTo(-1 + as1, +as1);
		break;
	}
	case TEX_ARROW_SOUTH: {
		path.moveTo(0, 1);
		path.lineTo(-as1,1 - as1);
		path.lineTo(+as1,1 - as1);
		break;
	}
	case TEX_ARROW_NORTH: {
		path.moveTo(0, -1);
		path.lineTo(+as1,-1 + as1);
		path.lineTo(-as1,-1 + as1);
		break;
	}
	}

	painter.fillPath(path, Qt::white);

	painter.end();
	//image.save(str(enum2str(button))+str(".png"));

#if !defined(HAVE_QT5_OPENGL)
	return gl->bindTexture(image);
#else
    Q_UNUSED(gl);
    QOpenGLTexture *texture = new QOpenGLTexture(image.mirrored());
    m_glTextures.push_back(texture);
    return texture->textureId();
#endif
}