void Refraction::draw() { _arrayBuf.bind(); QOpenGLShaderProgram *program = GL::refraction(); program->bind(); int vertexLocation = program->attributeLocation("a_position"); program->enableAttributeArray(vertexLocation); program->setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, sizeof(VertexData)); int fragmentLocation = program->attributeLocation("a_texcoord"); program->enableAttributeArray(fragmentLocation); program->setAttributeBuffer(fragmentLocation, GL_FLOAT, sizeof(QVector3D), 2, sizeof(VertexData)); prepareMatrix(); program->setUniformValue("mvp_matrix", GL::projection() * model); program->setUniformValue("refraction", 0); _texture->bind(0); program->setUniformValue("background", 1); GameObjects::background()->bind(1); program->setUniformValue("position", _position); program->setUniformValue("radius", _radius); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, 0); }
//! [4] void TriangleWindow::initialize() { m_program = new QOpenGLShaderProgram(this); m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource); m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); m_program->link(); m_posAttr = m_program->attributeLocation("posAttr"); m_colAttr = m_program->attributeLocation("colAttr"); m_matrixUniform = m_program->uniformLocation("matrix"); }
void OpenGLWidgetPrivate::initialize() { initializeOpenGLFunctions(); m_program = new QOpenGLShaderProgram; m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource); m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); m_program->link(); m_posAttr = m_program->attributeLocation("posAttr"); m_colAttr = m_program->attributeLocation("colAttr"); m_matrixUniform = m_program->uniformLocation("matrix"); }
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(); }
void csSurface::draw(QOpenGLShaderProgram& program) { if( _initRequired ) { initialize(); } if( _meshInfo.isEmpty() ) { return; } glDisable(GL_CULL_FACE); program.setUniformValue("cs_Model", _model); program.setUniformValue("cs_zMin", _meshInfo.zMin()); program.setUniformValue("cs_zInterval", _meshInfo.zInterval()); program.setUniformValue("cs_ColorMap", TMU_COLORMAP); _surface->bind(); const int vertexLoc = program.attributeLocation("cs_Vertex"); program.enableAttributeArray(vertexLoc); program.setAttributeBuffer(vertexLoc, GL_FLOAT, 0, 3); _colorTexture->bind(TMU_COLORMAP, QOpenGLTexture::ResetTextureUnit); _strip->bind(); const int numStrips = _meshInfo.rowCount() -1; const int numVertPerStrip = 2*_meshInfo.columnCount(); for(int y = 0; y < numStrips; y++) { const GLuint offset = sizeof(GLuint)*y*numVertPerStrip; const GLvoid *indices = (GLvoid*)offset; glDrawElements(GL_TRIANGLE_STRIP, numVertPerStrip, GL_UNSIGNED_INT, indices); } _strip->release(); _colorTexture->release(); program.disableAttributeArray(vertexLoc); _surface->release(); }