示例#1
0
        void drawSceneToTarget()
        {
            if (!targetTexture_ ||
                targetTexture_->getWidth() != 2 * window_->getWidth() ||
                targetTexture_->getHeight() != 2 * window_->getHeight())
            {
                targetTexture_ = window_->getContext()->createTexture();
                targetTexture_->setSize(2 * window_->getWidth(),
                                        2 * window_->getHeight());
                targetTexture_->setMinFilter(GL_LINEAR);
                targetTexture_->setMagFilter(GL_LINEAR);

                targetFrameBuffer_ = window_->getContext()->createFrameBuffer();
                targetFrameBuffer_->setColorAttachment(targetTexture_);
            }
            
            targetFrameBuffer_->create();

            glViewport(0, 0, window_->getWidth() * 2,
                       window_->getHeight() * 2);
            glBindFramebuffer(GL_FRAMEBUFFER, targetFrameBuffer_->getName());
            glClearColor(0.0, 0.0, 0.0, 0.0);
            glClear(GL_COLOR_BUFFER_BIT);
            drawScene();
            glBindFramebuffer(GL_FRAMEBUFFER, 0);
            glViewport(0, 0, window_->getWidth(), window_->getHeight());
        }
示例#2
0
    void drawLogoToTarget()
    {
        logoTexture_->create();
        targetFrameBuffer_->create();

        glViewport(0, 0, targetTexture_->getWidth(),
                   targetTexture_->getHeight());

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        float aspectRatio = (float(logoTexture_->getWidth()) /
                             float(logoTexture_->getHeight()));
        float scale = 0.2f;

        glBindFramebuffer(GL_FRAMEBUFFER, targetFrameBuffer_->getName());
        glClearColor(0.0, 0.0, 0.0, 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, logoTexture_->getName());
        glPushMatrix();
        glRotatef(angle_, 0.0f, 0.0f, 1.0f);
        glColor3f(1.0f, 0.8f, 0.2f);
        glBegin(GL_QUADS);
        {
            glTexCoord2i(0, 0);
            glVertex2f(-scale * aspectRatio, -scale);
            glTexCoord2i(1, 0);
            glVertex2f(scale * aspectRatio, -scale);
            glTexCoord2i(1, 1);
            glVertex2f(scale * aspectRatio, scale);
            glTexCoord2i(0, 1);
            glVertex2f(-scale * aspectRatio, scale);
        }
        glEnd();
        glPopMatrix();
        glBindTexture(GL_TEXTURE_2D, 0);
        glDisable(GL_TEXTURE_2D);
        glDisable(GL_BLEND);
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
    }