本文整理汇总了C++中QOpenGLShaderProgram::setAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLShaderProgram::setAttributeValue方法的具体用法?C++ QOpenGLShaderProgram::setAttributeValue怎么用?C++ QOpenGLShaderProgram::setAttributeValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLShaderProgram
的用法示例。
在下文中一共展示了QOpenGLShaderProgram::setAttributeValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Exception
/******************************************************************************
* Renders a 2d polyline in the viewport.
******************************************************************************/
void ViewportSceneRenderer::render2DPolyline(const Point2* points, int count, const ColorA& color, bool closed)
{
OVITO_STATIC_ASSERT(sizeof(points[0]) == 2*sizeof(GLfloat));
// Load OpenGL shader.
QOpenGLShaderProgram* shader = loadShaderProgram("line", ":/core/glsl/lines/line.vs", ":/core/glsl/lines/line.fs");
if(!shader->bind())
throw Exception(tr("Failed to bind OpenGL shader."));
bool wasDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);
GLint vc[4];
glGetIntegerv(GL_VIEWPORT, vc);
QMatrix4x4 tm;
tm.ortho(vc[0], vc[0] + vc[2], vc[1] + vc[3], vc[1], -1, 1);
OVITO_CHECK_OPENGL(shader->setUniformValue("modelview_projection_matrix", tm));
QOpenGLBuffer vertexBuffer;
if(glformat().majorVersion() >= 3) {
if(!vertexBuffer.create())
throw Exception(tr("Failed to create OpenGL vertex buffer."));
if(!vertexBuffer.bind())
throw Exception(tr("Failed to bind OpenGL vertex buffer."));
vertexBuffer.allocate(points, 2 * sizeof(GLfloat) * count);
OVITO_CHECK_OPENGL(shader->enableAttributeArray("position"));
OVITO_CHECK_OPENGL(shader->setAttributeBuffer("position", GL_FLOAT, 0, 2));
vertexBuffer.release();
}
else {
OVITO_CHECK_OPENGL(glEnableClientState(GL_VERTEX_ARRAY));
OVITO_CHECK_OPENGL(glVertexPointer(2, GL_FLOAT, 0, points));
}
if(glformat().majorVersion() >= 3) {
OVITO_CHECK_OPENGL(shader->disableAttributeArray("color"));
OVITO_CHECK_OPENGL(shader->setAttributeValue("color", color.r(), color.g(), color.b(), color.a()));
}
else {
OVITO_CHECK_OPENGL(glColor4(color));
}
OVITO_CHECK_OPENGL(glDrawArrays(closed ? GL_LINE_LOOP : GL_LINE_STRIP, 0, count));
if(glformat().majorVersion() >= 3) {
shader->disableAttributeArray("position");
}
else {
OVITO_CHECK_OPENGL(glDisableClientState(GL_VERTEX_ARRAY));
}
shader->release();
if(wasDepthTestEnabled) glEnable(GL_DEPTH_TEST);
}
示例2: drawMesh
void csSurface::drawMesh(QOpenGLShaderProgram& program)
{
if( _initRequired ) {
initialize();
}
if( _meshInfo.isEmpty() ) {
return;
}
program.setUniformValue("cs_DepthOffset", csCoordinateBox::DepthOffset);
program.setUniformValue("cs_Model", _model);
_surface->bind();
const int vertexLoc = program.attributeLocation("cs_Vertex");
program.enableAttributeArray(vertexLoc);
program.setAttributeBuffer(vertexLoc, GL_FLOAT, 0, 3);
const int colorLoc = program.attributeLocation("cs_Color");
program.setAttributeValue(colorLoc, QColor(Qt::black));
// Along x-Axis
for(int y = 0; y < _meshInfo.rowCount(); y++) {
glDrawArrays(GL_LINE_STRIP,
y*_meshInfo.columnCount(), _meshInfo.columnCount());
}
// Along y-Axis
_meshY->bind();
for(int x = 0; x < _meshInfo.columnCount(); x++) {
const GLuint offset = sizeof(GLuint)*x*_meshInfo.rowCount();
const GLvoid *indices = (GLvoid*)offset;
glDrawElements(GL_LINE_STRIP, _meshInfo.rowCount(), GL_UNSIGNED_INT, indices);
}
_meshY->release();
program.disableAttributeArray(vertexLoc);
_surface->release();
}
示例3: computeElements
// Wireframe OpenGL drawing
void
Scene_polylines_item::drawEdges(CGAL::Three::Viewer_interface* viewer) const {
if(!are_buffers_filled)
{
computeElements();
initializeBuffers(viewer);
}
vaos[Edges]->bind();
attribBuffers(viewer, PROGRAM_NO_SELECTION);
QOpenGLShaderProgram *program = getShaderProgram(PROGRAM_NO_SELECTION);
program->bind();
program->setAttributeValue("colors", this->color());
viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(nb_lines/4));
program->release();
vaos[Edges]->release();
if(d->draw_extremities)
{
Scene_group_item::drawEdges(viewer);
}
}
示例4: drawVisualHints
void Viewer::drawVisualHints()
{
CGAL::QGLViewer::drawVisualHints();
if(d->distance_is_displayed)
{
glDisable(GL_DEPTH_TEST);
QMatrix4x4 mvpMatrix;
double mat[16];
camera()->getModelViewProjectionMatrix(mat);
for(int i=0; i < 16; i++)
{
mvpMatrix.data()[i] = (float)mat[i];
}
if(!isOpenGL_4_3())
{
//draws the distance
//nullifies the translation
d->rendering_program_dist.bind();
d->rendering_program_dist.setUniformValue("mvp_matrix", mvpMatrix);
d->rendering_program_dist.setUniformValue("point_size", GLfloat(6.0f));
d->vao.bind();
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(2));
glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(2));
d->vao.release();
d->rendering_program_dist.release();
glEnable(GL_DEPTH_TEST);
}
else
{
QOpenGLShaderProgram* program = getShaderProgram(PROGRAM_SOLID_WIREFRAME);
program->bind();
QVector2D vp(width(), height());
program->setUniformValue("viewport", vp);
program->setUniformValue("near",(GLfloat)camera()->zNear());
program->setUniformValue("far",(GLfloat)camera()->zFar());
program->setUniformValue("width", GLfloat(3.0f));
program->setAttributeValue("colors", QColor(Qt::black));
program->setUniformValue("mvp_matrix", mvpMatrix);
QMatrix4x4 f_mat;
f_mat.setToIdentity();
program->setUniformValue("f_matrix", f_mat);
d->vao.bind();
glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(2));
d->vao.release();
program->release();
program = getShaderProgram(PROGRAM_NO_SELECTION);
program->bind();
program->setAttributeValue("colors", QColor(Qt::black));
program->setAttributeValue("point_size", 6.0f);
program->setUniformValue("mvp_matrix", mvpMatrix);
program->setUniformValue("f_matrix", f_mat);
d->vao.bind();
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(2));
d->vao.release();
program->release();
}
}
if (!d->painter->isActive())
d->painter->begin(this);
//So that the text is drawn in front of everything
d->painter->beginNativePainting();
glDisable(GL_DEPTH_TEST);
d->painter->endNativePainting();
//Prints the displayMessage
QFont font = QFont();
QFontMetrics fm(font);
TextItem *message_text = new TextItem(float(10 + fm.width(d->message)/2),
float(height()-20),
0, d->message, false,
QFont(), Qt::gray );
if (d->_displayMessage)
{
d->textRenderer->addText(message_text);
}
d->textRenderer->draw(this);
if (d->_displayMessage)
d->textRenderer->removeText(message_text);
}