Exemplo n.º 1
0
void AppWindow::keyPressEvent(QKeyEvent *event) {
    if (event->key() == Qt::Key_Escape) {
        QCoreApplication::instance()->quit();
    } else if (event->key() == Qt::Key_O) {
     viewRotate();
     viewRotateAct->setChecked(true);
 } else if (event->key() == Qt::Key_N) {
    viewTranslate();
    viewTranslateAct->setChecked(true);
} else if (event->key() == Qt::Key_P) {
    viewPerspective();
    viewPerspectiveAct->setChecked(true);
} else if (event->key() == Qt::Key_R) {
    modelRotate();
    modelRotateAct->setChecked(true);
} else if (event->key() == Qt::Key_T) {
    modelTranslate();
    modelTranslateAct->setChecked(true);
} else if (event->key() == Qt::Key_S) {
    modelScale();
    modelScaleAct->setChecked(true);
} else if (event->key() == Qt::Key_A) {
    resetView();
} else if (event->key() == Qt::Key_V) {
    viewPortMode();
    viewPortModeAct->setChecked(true);
}
}
void LLPostProcess::doEffects(void)
{
	/// Save GL State
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glPushClientAttrib(GL_ALL_ATTRIB_BITS);

	/// Copy the screen buffer to the render texture
	{
		U32 tex = mSceneRenderTexture->getTexName() ;
		copyFrameBuffer(tex, screenW, screenH);
	}

	/// Clear the frame buffer.
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	
	/// Change to an orthogonal view
	viewOrthogonal(screenW, screenH);
	
	checkError();
	applyShaders();
	
	LLGLSLShader::bindNoShader();
	checkError();

	/// Change to a perspective view
	viewPerspective();	

	/// Reset GL State
	glPopClientAttrib();
	glPopAttrib();
	checkError();
}
Exemplo n.º 3
0
// 绘制模糊的图象
void MyGLWidget::drawBlur(int times, float inc)
{
    float spost = 0.0f;// 纹理坐标偏移量
    float alphainc = 0.9f / times;// alpha混合的衰减量
    float alpha = 0.2f;// Alpha初值
    // 禁用自动生成纹理坐标
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);
    glEnable(GL_TEXTURE_2D);// 启用 2D 纹理映射
    glDisable(GL_DEPTH_TEST);// 深度测试不可用
    glBlendFunc(GL_SRC_ALPHA,GL_ONE);// 设置混合模式
    glEnable(GL_BLEND);// 启用混合
    glBindTexture(GL_TEXTURE_2D,m_blurTexture);// 绑定混合纹理
    viewOrtho();// 切换到标准视图
    alphainc = alpha / times;// 减少alpha值
    //我们多次绘制这个纹理用于创建那个辐射效果, 缩放这个纹理坐标并且每次我们做另一个关口时增大混合因数 。
    //我们绘制25个方块,每次按照0.015f拉伸这个纹理。
    glBegin(GL_QUADS);// 开始绘制方块
        // 着色模糊物的次数
        for (int num = 0;num < times;num++)
        {
            glColor4f(1.0f, 1.0f, 1.0f, alpha);// 调整alpha值
            glTexCoord2f(0+spost,1-spost);
            glVertex2f(0,0);
            glTexCoord2f(0+spost,0+spost);
            glVertex2f(0,480);
            glTexCoord2f(1-spost,0+spost);
            glVertex2f(640,480);
            glTexCoord2f(1-spost,1-spost);
            glVertex2f(640,0);
            spost += inc;// 逐渐增加 spost (快速靠近纹理中心)
            alpha = alpha - alphainc;// 逐渐增加 alpha (逐渐淡出纹理)
        }
    glEnd();// 完成绘制方块
    viewPerspective();// 转换到一个透视视图
    glEnable(GL_DEPTH_TEST);// 深度测试可用
    glDisable(GL_TEXTURE_2D);// 2D纹理映射不可用
    glDisable(GL_BLEND);// 混合不可用
    glBindTexture(GL_TEXTURE_2D,0);// 释放模糊纹理
}
Exemplo n.º 4
0
void AppWindow::createActions() {
    // Creates a new action for quiting and pushes it onto the menu actions vector
    menuBar()->setNativeMenuBar(false);
    QAction* quitAct = new QAction(tr("&Quit"), this);
    m_menu_actions.push_back(quitAct);

    // We set the accelerator keys
    // Alternatively, you could use: setShortcuts(Qt::CTRL + Qt::Key_P);
    quitAct->setShortcuts(QKeySequence::Quit);

    // Set the tip
    quitAct->setStatusTip(tr("Exits the file"));

    // Connect the action with the signal and slot designated
    connect(quitAct, SIGNAL(triggered()), this, SLOT(close()));

    QAction* resetAct = new QAction(tr("Reset (A)"), this);
    m_menu_actions.push_back(resetAct);
    connect(resetAct, SIGNAL(triggered()), this, SLOT(resetView()));



     viewRotateAct = new QAction(tr("View Rotate (O)"), this);
    m_mode_actions.push_back(viewRotateAct);
    viewRotateAct->setCheckable(true);
    connect(viewRotateAct, SIGNAL(triggered()), this, SLOT(viewRotate()));

     viewTranslateAct = new QAction(tr("View Translate (N)"), this);
    m_mode_actions.push_back(viewTranslateAct);
    viewTranslateAct->setCheckable(true);
    connect(viewTranslateAct, SIGNAL(triggered()), this, SLOT(viewTranslate()));


     viewPerspectiveAct = new QAction(tr("View Perspective (P)"), this);
    m_mode_actions.push_back(viewPerspectiveAct);
    viewPerspectiveAct->setCheckable(true);
    connect(viewPerspectiveAct, SIGNAL(triggered()), this, SLOT(viewPerspective()));

     modelRotateAct = new QAction(tr("Model Rotate (R)"), this);
    m_mode_actions.push_back(modelRotateAct);
    modelRotateAct->setCheckable(true);
    connect(modelRotateAct, SIGNAL(triggered()), this, SLOT(modelRotate()));

     modelTranslateAct = new QAction(tr("Model Translate (T)"), this);
    m_mode_actions.push_back(modelTranslateAct);
    modelTranslateAct->setCheckable(true);
    connect(modelTranslateAct, SIGNAL(triggered()), this, SLOT(modelTranslate()));

     modelScaleAct = new QAction(tr("Model Scale (S)"), this);
    m_mode_actions.push_back(modelScaleAct);
    modelScaleAct->setCheckable(true);
    connect(modelScaleAct, SIGNAL(triggered()), this, SLOT(modelScale()));


     viewPortModeAct = new QAction(tr("Viewport Mode (V)"), this);
    m_mode_actions.push_back(viewPortModeAct);
    viewPortModeAct->setCheckable(true);
    connect(viewPortModeAct, SIGNAL(triggered()), this, SLOT(viewPortMode()));


    QActionGroup* modeGroup = new QActionGroup(this);

    modeGroup->setExclusive(true);
    modeGroup->addAction(viewRotateAct);
    modeGroup->addAction(viewTranslateAct);
    modeGroup->addAction(viewPerspectiveAct);
    modeGroup->addAction(modelRotateAct);
    modeGroup->addAction(modelTranslateAct);
    modeGroup->addAction(modelScaleAct);
    modeGroup->addAction(viewPortModeAct);

    modelRotate();
    modelRotateAct->setChecked(true);


}
void LLPostProcess::changeOrthogonal(unsigned int width, unsigned int height)
{
	viewPerspective();
	viewOrthogonal(width, height);
}