bool Reflection::paintGL() { // Pass 1. Draw scene reversed and store it to the texture glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); m_pProgram->bind(); m_pProgram->setUniformValue("factor", (float)-1.0); m_pProgram->setUniformValue("texture", false); m_pProgram->setUniformValue("colorMap", 0); m_pProgram->setUniformValue("SIZE", QVector2D(glwidget()->width(), glwidget()->height())); Box b = scene()->boundingBox(); m_pProgram->setUniformValue("radius", b.radius()); m_pProgram->setUniformValue("boundingMin", b.min()); m_pProgram->setUniformValue("boundingMax", b.max()); m_pProgram->setUniformValue("modelViewProjectionMatrix", camera()->projectionMatrix() * camera()->modelviewMatrix()); m_pProgram->setUniformValue("modelViewMatrix", camera()->modelviewMatrix()); m_pProgram->setUniformValue("normalMatrix", camera()->modelviewMatrix().normalMatrix()); // Ligth specs m_pProgram->setUniformValue("lightAmbient", QVector4D(1., 1., 1., 1.)); m_pProgram->setUniformValue("lightDiffuse", QVector4D(1., 1., 1., 1.)); m_pProgram->setUniformValue("lightSpecular", QVector4D(1., 1., 1., 1.)); m_pProgram->setUniformValue("lightPosition", QVector4D(100., 100., 100., 1.)); m_pProgram->setUniformValue("matAmbient", QVector4D(.5, .4, .0, 1.)); m_pProgram->setUniformValue("matDiffuse", QVector4D(.5, .4, .0, 1.)); m_pProgram->setUniformValue("matSpecular", QVector4D(1., 1., 1., 1.)); m_pProgram->setUniformValue("matShininess", (float) 30.); drawPlugin()->drawScene(); // Get texture glBindTexture(GL_TEXTURE_2D, m_textureId); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, glwidget()->width(), glwidget()->height()); glGenerateMipmap(GL_TEXTURE_2D); // Pass 2 Draw Scene normal glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); m_pProgram->setUniformValue("factor", (float)1.0); drawPlugin()->drawScene(); // Pass 3 Draw quad using texture m_pProgram->setUniformValue("texture", true); glBindVertexArray(m_VAO_rect); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindVertexArray(0); m_pProgram->release(); glBindTexture(GL_TEXTURE_2D, 0); return true; }
void Reflection::onPluginLoad() { // Resize to power-of-two viewport //glwidget()->resize(IMAGE_WIDTH, IMAGE_HEIGHT); // Carregar shader, compile & link m_pVs = new QGLShader(QGLShader::Vertex, this); m_pVs->compileSourceFile(":/reflection.vert"); m_pFs = new QGLShader(QGLShader::Fragment, this); m_pFs->compileSourceFile(":/reflection.frag"); m_pProgram = new QGLShaderProgram(this); m_pProgram->addShader(m_pVs); m_pProgram->addShader(m_pFs); m_pProgram->link(); // Setup texture glActiveTexture(GL_TEXTURE0); glGenTextures( 1, &m_textureId); glBindTexture(GL_TEXTURE_2D, m_textureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, glwidget()->width(), glwidget()->height(), 0, GL_RGB, GL_FLOAT, NULL); glBindTexture(GL_TEXTURE_2D, 0); // Create & bind empty VAO glGenVertexArrays(1, &m_VAO_rect); glBindVertexArray(m_VAO_rect); // Create VBO with (x,y,z) coordinates float coords[] = { -1, -1, -1, 1, -1, -1, -1, -1, 1, 1, -1, 1 }; GLuint VBO_coords; glGenBuffers(1, &VBO_coords); glBindBuffer(GL_ARRAY_BUFFER, VBO_coords); glBufferData(GL_ARRAY_BUFFER, sizeof(coords), coords, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); glBindVertexArray(0); }
void Glowing::onPluginLoad() { // Resize to power-of-two viewport glwidget()->resize(IMAGE_WIDTH,IMAGE_HEIGHT); // Carregar shader, compile & link vs = new QGLShader(QGLShader::Vertex, this); vs->compileSourceFile(":/glowing.vert"); fs = new QGLShader(QGLShader::Fragment, this); fs->compileSourceFile(":/glowing.frag"); program = new QGLShaderProgram(this); program->addShader(vs); program->addShader(fs); program->link(); // Setup texture glActiveTexture(GL_TEXTURE0); glGenTextures( 1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, IMAGE_WIDTH, IMAGE_HEIGHT, 0, GL_RGB, GL_FLOAT, NULL); glBindTexture(GL_TEXTURE_2D, 0); }
void ShowHelp::postFrame() { const int SIZE = 1024; // 1. Create image with text QImage image(SIZE,SIZE,QImage::Format_RGB32); image.fill(Qt::white); QPainter painter(&image); QFont font; font.setPixelSize(32); painter.setFont(font); painter.setPen(QColor(50,50,50)); int x = 15; int y = 50; painter.drawText(x, y, QString("L - Load object A - Add plugin")); painter.end(); // 2. Create texture const int textureUnit = 5; glActiveTexture(GL_TEXTURE0+textureUnit); QImage im0 = QGLWidget::convertToGLFormat(image); glGenTextures( 1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, im0.width(), im0.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im0.bits()); glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); // Pass 2. Draw quad using texture program->bind(); program->setUniformValue("colorMap", textureUnit); program->setUniformValue("WIDTH", float(glwidget()->width())); program->setUniformValue("HEIGHT", float(glwidget()->height())); // quad covering viewport drawRect(); program->release(); glBindTexture(GL_TEXTURE_2D, 0); glDeleteTextures(1, &textureID); }
void AlphaBlending::mouseMoveEvent(QMouseEvent * e) { glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Llegir posicio del cursor int x = e->x(); int y = glwidget()->height()-e->y(); program->bind(); program->setUniformValue("mouse", QVector2D(x, y)); program->release(); }
void DrawBoundingBox::onPluginLoad() { // Carregar shader, compile & link vs = new QGLShader(QGLShader::Vertex, this); vs->compileSourceFile("draw-bounding-box.vert"); fs = new QGLShader(QGLShader::Fragment, this); fs->compileSourceFile("draw-bounding-box.frag"); program = new QGLShaderProgram(this); program->addShader(vs); program->addShader(fs); program->link(); cout << "Link log:" << program->log().toStdString() << endl; createBuffers(); glwidget()->clearScene(); }
void AlphaBlending::onPluginLoad() { // Carregar shader, compile & link vs = new QGLShader(QGLShader::Vertex, this); vs->compileSourceFile("alphablending.vert"); fs = new QGLShader(QGLShader::Fragment, this); fs->compileSourceFile("alphablending.frag"); program = new QGLShaderProgram(this); program->addShader(vs); program->addShader(fs); program->link(); cout << "Link log:" << program->log().toStdString() << endl; QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), glwidget(), SLOT(updateGL())); timer->start(); }
void SeleccioTeclat::setSelectedObject(int selected) { if (selected < 0 || selected >= (int)scene()->objects().size()) selected = -1; scene()->setSelectedObject(selected); glwidget()->updateGL(); }