コード例 #1
0
ファイル: ogl.cpp プロジェクト: jcxz/DIP
bool loadSkyBoxTexture(QOpenGLTexture & tex,
                       const char *posx, const char *negx,
                       const char *posy, const char *negy,
                       const char *posz, const char *negz)
{
  if (!tex.create())
  {
    ERRORM("Failed to create skybox texture's OpenGL object name");
    return false;
  }

  tex.bind();
  utils::misc::ScopedGuard guard([&tex] { tex.release(); });
  (void) guard;

  if (!loadTextureHelper(posx, GL_TEXTURE_CUBE_MAP_POSITIVE_X)) return false;
  if (!loadTextureHelper(negx, GL_TEXTURE_CUBE_MAP_NEGATIVE_X)) return false;
  if (!loadTextureHelper(posy, GL_TEXTURE_CUBE_MAP_POSITIVE_Y)) return false;
  if (!loadTextureHelper(negy, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y)) return false;
  if (!loadTextureHelper(posz, GL_TEXTURE_CUBE_MAP_POSITIVE_Z)) return false;
  if (!loadTextureHelper(negz, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)) return false;

  OGLF->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  OGLF->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  OGLF->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
  OGLF->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  OGLF->glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

  return true;
}
コード例 #2
0
ファイル: qglview.cpp プロジェクト: hekav/QtQuickVcp
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();
}
コード例 #3
0
ファイル: ogl.cpp プロジェクト: jcxz/DIP
bool load2DTexture(QOpenGLTexture & tex,
                   const char *name,
                   GLint internal_format,
                   GLint filter_mode, GLint clamp_mode)
{
  if (!tex.create())
  {
    ERRORM("Failed to create 2D texture's OpenGL object name");
    return false;
  }

  tex.bind();
  utils::misc::ScopedGuard guard([&tex] { tex.release(); });
  (void) guard;

  if (!loadTextureHelper(name, GL_TEXTURE_2D, internal_format)) return false;

  OGLF->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_mode);
  OGLF->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_mode);
  OGLF->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp_mode);
  OGLF->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp_mode);

  return true;
}
コード例 #4
0
ファイル: sceneobject.cpp プロジェクト: GPUWorks/calliper
void SceneObject::draw(ShaderStack *stack)
{
    bool shaderOverridden = false;
    if ( !geometry()->isEmpty() )
    {
        // If we have a shader override, push the override.
        QString shaderOverrideName = geometry()->shaderOverride();
        if ( !shaderOverrideName.isNull() )
        {
            ShaderProgram* program = resourceManager()->shader(shaderOverrideName);
            if ( program )
            {
                shaderOverridden = true;
                stack->shaderPush(program);
            }
        }
    }

    // Multiply the modelWorld matrix by our current one.
    // This updates the shader uniform too.
    // We do this even if the geometry is empty, so that the
    // transformation will apply recursively.
    // It is the caller's responsibility to manage pushing
    // and popping of the m2w matrix.
    stack->modelToWorldPostMultiply(localToParent());

    if ( !geometry()->isEmpty() )
    {
        // Upload and bind the geometry.
        geometry()->upload();
        geometry()->bindVertices(true);
        geometry()->bindIndices(true);

        // Apply the data format.
        geometry()->applyDataFormat(stack->shaderTop());

        // If we're selected, set the global colour.
        bool pushedColor = false;
        MapDocument* doc = m_pScene->document();
        if ( doc->selectedSet().contains(this) )
        {
            pushedColor = true;
            stack->globalColorPush();
            stack->globalColorSetTop(doc->selectedColor());
        }

        // Apply the texture.
        QOpenGLTexture* tex = resourceManager()->texture(geometry()->texture(0));
        tex->bind(0);

        // Draw.
        geometry()->draw();

        if ( pushedColor )
        {
            stack->globalColorPop();
        }

        // Pop the shader if we pushed one earlier.
        if ( shaderOverridden )
        {
            stack->shaderPop();
        }
    }
}
コード例 #5
0
void AnimeGLWidget::paintGL()
{
    QColor col = m_pSetting->getAnimeBGColor();
    if (m_pEditData->isExportPNG())
    {
        col.setAlphaF(0);
    }
    glClearColor(col.redF(), col.greenF(), col.blueF(), col.alphaF());
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    m_matProj.setToIdentity();
    m_matProj.ortho(-m_DrawWidth / 2, m_DrawWidth / 2, m_DrawHeight / 2, -m_DrawHeight / 2, -10000, 10000);

    m_lineShaderProgram.bind();
    m_lineShaderProgram.setUniformValue("mvp_matrix", m_matProj);

    if (m_pSetting->getUseDepthTest())
    {
        glEnable(GL_DEPTH_TEST);
    }
    else
    {
        glDisable(GL_DEPTH_TEST);
    }

    // 背景画像描画
    if (m_backImageTex)
    {
        RectF rect;
        RectF uvF;
        QColor col = QColor(255, 255, 255, 255);

        m_textureShaderProgram.bind();

        QOpenGLTexture *pTex = m_pTextureCacheManager->get(m_backImageTex);
        if (pTex)
        {
            pTex->bind();
        }

        m_textureShaderProgram.setUniformValue("mvp_matrix", m_matProj);

        rect.setRect(-m_backImageW / 2, m_backImageH / 2, m_backImageW, -m_backImageH);
        uvF.setRect(0.0, (float)(m_BackImage.height() - m_backImageH) / m_BackImage.height(), (float)m_backImageW / m_BackImage.width(), (float)m_backImageH / m_BackImage.height());
        drawRect(rect, uvF, -9999.9, col);
    }

    if (m_pEditData)
    {
        drawLayers();
    }

    bool bDepth = glIsEnabled(GL_DEPTH_TEST);
    glDisable(GL_DEPTH_TEST);

    if (m_bDrawGrid)
    {
        if (!m_pEditData->isExportPNG())
        {
            drawGrid();
        }
    }

    // センター
    if (m_pSetting->getDrawCenter())
    {
        if (!m_pEditData->isExportPNG())
        {
            drawCenter();
        }
    }

    // PNG吐き出しモード
    if (m_pEditData->getEditMode() == EditData::kEditMode_ExportPNG && !m_pEditData->isExportPNG())
    {
        int rect[4];
        QColor col = QColor(255, 0, 0, 255);
        m_pEditData->getExportPNGRect(rect);
        drawLine(QPoint(rect[0], rect[1]), QPoint(rect[2], rect[1]), col, 1.0);
        drawLine(QPoint(rect[2], rect[1]), QPoint(rect[2], rect[3]), col, 1.0);
        drawLine(QPoint(rect[2], rect[3]), QPoint(rect[0], rect[3]), col, 1.0);
        drawLine(QPoint(rect[0], rect[3]), QPoint(rect[0], rect[1]), col, 1.0);
    }
    if (bDepth)
    {
        glEnable(GL_DEPTH_TEST);
    }
}