void load() { shader.addShaderFromSourceCode(QOpenGLShader::Vertex, shaderWithHeader(":/shaders/mvp.vert")); shader.addShaderFromSourceCode(QOpenGLShader::Fragment, shaderWithHeader(":/shaders/flat.frag")); shader.link(); cube.load(shader); }
void exposeEvent(QExposeEvent *) { if (!isExposed()) return; if (!gl) { gl = new QOpenGLContext(); gl->setFormat(requestedFormat()); gl->create(); } gl->makeCurrent(this); QOpenGLShaderProgram prog; prog.addShaderFromSourceCode(QOpenGLShader::Vertex, "attribute highp vec4 a_Pos;" "attribute lowp vec4 a_Color;" "varying lowp vec4 v_Color;" "void main() {" " gl_Position = a_Pos;" " v_Color = a_Color;" "}"); prog.addShaderFromSourceCode(QOpenGLShader::Fragment, "varying lowp vec4 v_Color;" "void main() {" " gl_FragColor = v_Color;" "}"); prog.bind(); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); glViewport(0, 0, width(), height()); prog.enableAttributeArray("a_Pos"); prog.enableAttributeArray("a_Color"); float coords[] = { -0.7f, 0.7f, 0.8f, 0.8f, -0.8f, -0.8f, 0.7f, -0.7f }; float colors[] = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0 }; prog.setAttributeArray("a_Pos", GL_FLOAT, coords, 2, 0); prog.setAttributeArray("a_Color", GL_FLOAT, colors, 4, 0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); prog.disableAttributeArray("a_Pos"); prog.disableAttributeArray("a_Color"); gl->swapBuffers(this); }
//! [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 load() { shader.addShaderFromSourceCode(QOpenGLShader::Vertex, shaderWithHeader(":/shaders/mvp.vert")); shader.addShaderFromSourceCode(QOpenGLShader::Fragment, shaderWithHeader(":/shaders/flat.frag")); texture = unique_ptr<QOpenGLTexture>( new QOpenGLTexture(QImage("../resources/sand.jpg").mirrored())); texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear); texture->setMagnificationFilter(QOpenGLTexture::Linear); shader.link(); sphere.load(shader); }
void initShader(QOpenGLShaderProgram& _s, const char *_filename) { QString _vertSrc = ShaderCompiler::compile(":/shaders/" + QString(_filename) + ".vert"); QString _fragmentSrc = ShaderCompiler::compile(":/shaders/" + QString(_filename) + ".frag"); _s.addShaderFromSourceCode(QOpenGLShader::Vertex, _vertSrc); _s.addShaderFromSourceCode(QOpenGLShader::Fragment, _fragmentSrc); _s.link(); }
void DVWindow::loadShader(QOpenGLShaderProgram& shader, const char* vshader, const char* fshader) { /* Load the shaders from the qrc. */ shader.addShaderFromSourceFile(QOpenGLShader::Vertex, vshader); QFile res(fshader); res.open(QIODevice::ReadOnly | QIODevice::Text); QString fshaderSrc = res.readAll(); if (!context()->isOpenGLES()) fshaderSrc.prepend("#version 130\n"); shader.addShaderFromSourceCode(QOpenGLShader::Fragment, fshaderSrc); /* Bind the attribute handles. */ shader.bindAttributeLocation("vertex", vertex); shader.bindAttributeLocation("uv", uv); shader.link(); /* Bind so we set the texture sampler uniform values. */ shader.bind(); /* Left image is TEXTURE0. */ shader.setUniformValue("textureL", 0); /* Right image is TEXTURE1. */ shader.setUniformValue("textureR", 1); }