Ejemplo n.º 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();
}
Ejemplo n.º 2
0
TextObject::TextObject(SDL_Renderer* r, const string& text, int fontSize, const Point& p)
{
	this->renderer = r;
	cout << "TextObject Renderer: " << this->renderer << endl;
	this->fontLocation = DEFAULT_FONT_LOCATION;
	this->fontSize = fontSize;
	this->p = p;
	this->text = text;

	texture = nullptr;

	updateFont();
	createTextTexture();
}
Ejemplo n.º 3
0
void TextObject::setColor(const SDL_Color& color)
{
	this->color = color;
	createTextTexture();
}
Ejemplo n.º 4
0
void TextObject::setFont(const string& fontLocation)
{
	this->fontLocation = fontLocation;
	createTextTexture();
}
Ejemplo n.º 5
0
void TextObject::setText(const string& text)
{
	this->text = text;
	createTextTexture();
}
Ejemplo n.º 6
0
void TextObject::setFontSize(const int fontSize)
{
	this->fontSize = fontSize;
	createTextTexture();
}
Ejemplo n.º 7
0
void TextObject::setPoint(const Point& p)
{
	this->p = p;
	createTextTexture();
}