void Application::createDisplay(uint width, uint height, uint redBits, uint greenBits, uint blueBits, uint alphaBits, uint depthBits, uint stencilBits, DisplayMode mode, const std::string &title) { GLboolean status; status = glfwOpenWindow(width, height, redBits, greenBits, blueBits, alphaBits, depthBits, stencilBits, mode == DISP_FULLSCREEN ? GLFW_FULLSCREEN : GLFW_WINDOW); if(status == GL_FALSE) { throw APIError("Failed to create display."); } // fetch window size (fixes X11 fullscreen bug) glfwGetWindowSize(reinterpret_cast<int*>(&displayWidth_), reinterpret_cast<int*>(&displayHeight_)); glfwSetWindowTitle(title.c_str()); // title is set separately initOpenGL(); setOrthoView(); // register the callbacks (after a window is open) glfwSetKeyCallback(Application::keyCallback); //glfwSetCharCallback(Application::charCallback); glfwSetMouseButtonCallback(Application::mouseButtonCallback); glfwSetMousePosCallback(Application::mouseMoveCallback); glfwSetMouseWheelCallback(Application::mouseWheelCallback); quit_ = false; }
ccViewer::ccViewer(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) , m_glWindow(0) , m_selectedObject(0) , m_3dMouseInput(0) { ui.setupUi(this); //insert GL window in a vertical layout QVBoxLayout* verticalLayout_2 = new QVBoxLayout(ui.GLframe); verticalLayout_2->setSpacing(0); const int margin = 10; verticalLayout_2->setContentsMargins(margin,margin,margin,margin); QGLFormat format; format.setSwapInterval(0); m_glWindow = new ccGLWindow(ui.GLframe,format); verticalLayout_2->addWidget(m_glWindow); updateGLFrameGradient(); m_glWindow->setRectangularPickingAllowed(false); //multiple entities picking not supported //UI/display synchronization ui.actionFullScreen->setChecked(false); ui.menuSelected->setEnabled(false); reflectLightsState(); reflectPerspectiveState(); reflectPivotVisibilityState(); #ifdef CC_3DXWARE_SUPPORT enable3DMouse(true,true); #else ui.actionEnable3DMouse->setEnabled(false); #endif //Signals & slots connection connect(m_glWindow, SIGNAL(filesDropped(const QStringList&)), this, SLOT(addToDB(const QStringList&))); connect(m_glWindow, SIGNAL(entitySelectionChanged(int)), this, SLOT(selectEntity(int))); //connect(m_glWindow, SIGNAL(entitiesSelectionChanged(std::set<int>)), this, SLOT(selectEntities(std::set<int>))); //not supported! //connect(m_glWindow, SIGNAL(newLabel(ccHObject*), this, SLOT(handleNewEntity(ccHObject*))); //nothing to do in ccViewer! //"Options" menu connect(ui.actionDisplayParameters, SIGNAL(triggered()), this, SLOT(showDisplayParameters())); connect(ui.actionEditCamera, SIGNAL(triggered()), this, SLOT(doActionEditCamera())); //"Display > Standard views" menu connect(ui.actionSetViewTop, SIGNAL(triggered()), this, SLOT(setTopView())); connect(ui.actionSetViewBottom, SIGNAL(triggered()), this, SLOT(setBottomView())); connect(ui.actionSetViewFront, SIGNAL(triggered()), this, SLOT(setFrontView())); connect(ui.actionSetViewBack, SIGNAL(triggered()), this, SLOT(setBackView())); connect(ui.actionSetViewLeft, SIGNAL(triggered()), this, SLOT(setLeftView())); connect(ui.actionSetViewRight, SIGNAL(triggered()), this, SLOT(setRightView())); connect(ui.actionSetViewIso1, SIGNAL(triggered()), this, SLOT(setIsoView1())); connect(ui.actionSetViewIso2, SIGNAL(triggered()), this, SLOT(setIsoView2())); //"Options > Perspective" menu connect(ui.actionSetOrthoView, SIGNAL(triggered()), this, SLOT(setOrthoView())); connect(ui.actionSetCenteredPerspectiveView, SIGNAL(triggered()), this, SLOT(setCenteredPerspectiveView())); connect(ui.actionSetViewerPerspectiveView, SIGNAL(triggered()), this, SLOT(setViewerPerspectiveView())); //"Options > Rotation symbol" menu connect(ui.actionSetPivotAlwaysOn, SIGNAL(triggered()), this, SLOT(setPivotAlwaysOn())); connect(ui.actionSetPivotRotationOnly, SIGNAL(triggered()), this, SLOT(setPivotRotationOnly())); connect(ui.actionSetPivotOff, SIGNAL(triggered()), this, SLOT(setPivotOff())); //"Options > 3D mouse" menu connect(ui.actionEnable3DMouse, SIGNAL(toggled(bool)), this, SLOT(setup3DMouse(bool))); //"Display > Lights & Materials" menu connect(ui.actionToggleSunLight, SIGNAL(toggled(bool)), this, SLOT(toggleSunLight(bool))); connect(ui.actionToggleCustomLight, SIGNAL(toggled(bool)), this, SLOT(toggleCustomLight(bool))); //"Options" menu connect(ui.actionGlobalZoom, SIGNAL(triggered()), this, SLOT(setGlobalZoom())); connect(ui.actionFullScreen, SIGNAL(toggled(bool)), this, SLOT(toggleFullScreen(bool))); //"Options > Selected" menu connect(ui.actionShowColors, SIGNAL(toggled(bool)), this, SLOT(toggleColorsShown(bool))); connect(ui.actionShowNormals, SIGNAL(toggled(bool)), this, SLOT(toggleNormalsShown(bool))); connect(ui.actionShowScalarField, SIGNAL(toggled(bool)), this, SLOT(toggleScalarShown(bool))); connect(ui.actionShowColorRamp, SIGNAL(toggled(bool)), this, SLOT(toggleColorbarShown(bool))); connect(ui.actionZoomOnSelectedEntity, SIGNAL(triggered()), this, SLOT(zoomOnSelectedEntity())); connect(ui.actionDelete, SIGNAL(triggered()), this, SLOT(doActionDeleteSelectedEntity())); //"Help" menu connect(ui.actionAbout, SIGNAL(triggered()), this, SLOT(doActionAbout())); connect(ui.actionHelpShortctus, SIGNAL(triggered()), this, SLOT(doActionDisplayShortcuts())); }
ccViewer::ccViewer(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) , m_glWindow(0) , m_selectedObject(0) , m_3dMouseInput(0) { ui.setupUi(this); #ifdef Q_OS_LINUX //we reset the whole stylesheet but we keep the StatusBar style setStyleSheet(""); setStyleSheet("QStatusBar{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 rgb(200,200,200), stop:1 rgb(255,255,255));}"); #endif setWindowTitle(QString("ccViewer V%1").arg(CC_VIEWER_VERSION.title)); //insert GL window in a vertical layout { QVBoxLayout* verticalLayout = new QVBoxLayout(ui.GLframe); verticalLayout->setSpacing(0); const int margin = 10; verticalLayout->setContentsMargins(margin, margin, margin, margin); bool stereoMode = QSurfaceFormat::defaultFormat().stereo(); QWidget* glWidget = 0; CreateGLWindow(m_glWindow, glWidget, stereoMode); assert(m_glWindow && glWidget); verticalLayout->addWidget(glWidget); } updateGLFrameGradient(); m_glWindow->setRectangularPickingAllowed(false); //multiple entities picking not supported //UI/display synchronization ui.actionFullScreen->setChecked(false); ui.menuSelected->setEnabled(false); reflectLightsState(); reflectPerspectiveState(); reflectPivotVisibilityState(); #ifdef CC_3DXWARE_SUPPORT enable3DMouse(true); #else ui.actionEnable3DMouse->setEnabled(false); #endif //Signals & slots connection connect(m_glWindow, SIGNAL(filesDropped(QStringList)), this, SLOT(addToDB(QStringList))); connect(m_glWindow, SIGNAL(entitySelectionChanged(ccHObject*)), this, SLOT(selectEntity(ccHObject*))); connect(m_glWindow, SIGNAL(exclusiveFullScreenToggled(bool)), this, SLOT(onExclusiveFullScreenToggled(bool))); //connect(m_glWindow, SIGNAL(entitiesSelectionChanged(std::unordered_set<int>)), this, SLOT(selectEntities(std::unordered_set<int>))); //not supported! //connect(m_glWindow, SIGNAL(newLabel(ccHObject*), this, SLOT(handleNewEntity(ccHObject*))); //nothing to do in ccViewer! //"Options" menu connect(ui.actionDisplayParameters, SIGNAL(triggered()), this, SLOT(showDisplayParameters())); connect(ui.actionEditCamera, SIGNAL(triggered()), this, SLOT(doActionEditCamera())); //"Display > Standard views" menu connect(ui.actionSetViewTop, SIGNAL(triggered()), this, SLOT(setTopView())); connect(ui.actionSetViewBottom, SIGNAL(triggered()), this, SLOT(setBottomView())); connect(ui.actionSetViewFront, SIGNAL(triggered()), this, SLOT(setFrontView())); connect(ui.actionSetViewBack, SIGNAL(triggered()), this, SLOT(setBackView())); connect(ui.actionSetViewLeft, SIGNAL(triggered()), this, SLOT(setLeftView())); connect(ui.actionSetViewRight, SIGNAL(triggered()), this, SLOT(setRightView())); connect(ui.actionSetViewIso1, SIGNAL(triggered()), this, SLOT(setIsoView1())); connect(ui.actionSetViewIso2, SIGNAL(triggered()), this, SLOT(setIsoView2())); //"Options > Perspective" menu connect(ui.actionSetOrthoView, SIGNAL(triggered()), this, SLOT(setOrthoView())); connect(ui.actionSetCenteredPerspectiveView, SIGNAL(triggered()), this, SLOT(setCenteredPerspectiveView())); connect(ui.actionSetViewerPerspectiveView, SIGNAL(triggered()), this, SLOT(setViewerPerspectiveView())); //"Options > Rotation symbol" menu connect(ui.actionSetPivotAlwaysOn, SIGNAL(triggered()), this, SLOT(setPivotAlwaysOn())); connect(ui.actionSetPivotRotationOnly, SIGNAL(triggered()), this, SLOT(setPivotRotationOnly())); connect(ui.actionSetPivotOff, SIGNAL(triggered()), this, SLOT(setPivotOff())); //"Options > 3D mouse" menu connect(ui.actionEnable3DMouse, SIGNAL(toggled(bool)), this, SLOT(enable3DMouse(bool))); //"Display > Lights & Materials" menu connect(ui.actionToggleSunLight, SIGNAL(toggled(bool)), this, SLOT(toggleSunLight(bool))); connect(ui.actionToggleCustomLight, SIGNAL(toggled(bool)), this, SLOT(toggleCustomLight(bool))); //"Options" menu connect(ui.actionGlobalZoom, SIGNAL(triggered()), this, SLOT(setGlobalZoom())); connect(ui.actionEnableStereo, SIGNAL(toggled(bool)), this, SLOT(toggleStereoMode(bool))); connect(ui.actionFullScreen, SIGNAL(toggled(bool)), this, SLOT(toggleFullScreen(bool))); connect(ui.actionLockRotationVertAxis, SIGNAL(triggered()), this, SLOT(toggleRotationAboutVertAxis())); //"Options > Selected" menu connect(ui.actionShowColors, SIGNAL(toggled(bool)), this, SLOT(toggleColorsShown(bool))); connect(ui.actionShowNormals, SIGNAL(toggled(bool)), this, SLOT(toggleNormalsShown(bool))); connect(ui.actionShowMaterials, SIGNAL(toggled(bool)), this, SLOT(toggleMaterialsShown(bool))); connect(ui.actionShowScalarField, SIGNAL(toggled(bool)), this, SLOT(toggleScalarShown(bool))); connect(ui.actionShowColorRamp, SIGNAL(toggled(bool)), this, SLOT(toggleColorbarShown(bool))); connect(ui.actionZoomOnSelectedEntity, SIGNAL(triggered()), this, SLOT(zoomOnSelectedEntity())); connect(ui.actionDelete, SIGNAL(triggered()), this, SLOT(doActionDeleteSelectedEntity())); //"Shaders" menu connect(ui.actionNoFilter, SIGNAL(triggered()), this, SLOT(doDisableGLFilter())); //"Help" menu connect(ui.actionAbout, SIGNAL(triggered()), this, SLOT(doActionAbout())); connect(ui.actionHelpShortctus, SIGNAL(triggered()), this, SLOT(doActionDisplayShortcuts())); loadPlugins(); }
void FlowShower::draw() { update(); setOrthoView(); glClear(GL_COLOR_BUFFER_BIT); float invRatio = float(game->getResY()) / float(game->getResX()); float hs = 0.02f; //mouse horizontal size //float vs = hs * invRatio; //mouse vertical size float x = float(game->getMouseX()) / float(game->getResX()); float y = 1.0f - float(game->getMouseY()) / float(game->getResY()); float left = (1.0f - invRatio) / 2.0f; float right = 1.0f - left; float osx = (x - left) / (right - left); if (painting && (game->isLeftDown() || game->isMiddleDown() || game->isKeyDown('n') || game->isRightDown())) { flower.bindMat(); glDisable(GL_TEXTURE_2D); if (game->isLeftDown()) glColor3f(0.1, 0.0f, 0.0f); else if (game->isMiddleDown() || game->isKeyDown('m')) glColor3f(0.2, 0.0f, 0.0f); else if (game->isRightDown()) glColor3f(0.0, 0.0f, 0.0f); /*glBegin(GL_QUADS); osx -= 1.0f; oldMouseOSX -= 1.0f; for (int j = 0; j < 3; j++) { glVertex2f(osx - hs, y - hs); glVertex2f(osx + hs, y - hs); glVertex2f(osx + hs, y + hs); glVertex2f(osx - hs, y + hs); glVertex2f(osx + hs, y - hs); glVertex2f(osx - hs, y - hs); glVertex2f(oldMouseOSX - hs, oldMouseY - hs); glVertex2f(oldMouseOSX + hs, oldMouseY - hs); glVertex2f(osx + vs, y + hs); glVertex2f(osx + vs, y - hs); glVertex2f(oldMouseOSX + hs, oldMouseY - hs); glVertex2f(oldMouseOSX + hs, oldMouseY + hs); glVertex2f(osx - vs, y + hs); glVertex2f(osx + vs, y + hs); glVertex2f(oldMouseOSX + hs, oldMouseY + hs); glVertex2f(oldMouseOSX - hs, oldMouseY + hs); glVertex2f(osx - vs, y - hs); glVertex2f(osx - vs, y + hs); glVertex2f(oldMouseOSX - hs, oldMouseY + hs); glVertex2f(oldMouseOSX - hs, oldMouseY - hs); osx += 1.0f; oldMouseOSX += 1.0f; } glEnd();*/ drawMouseOffScreen(); osx -= 2.0f; oldMouseOSX -= 2.0f; Fbo::unbind(); } if (game->isKeyDown('g')) { flower.bindMat(); glColor3f(0.0f, 0.0f, 0.0f); glDisable(GL_BLEND); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f); glEnd(); Fbo::unbind(); } if (!paused) flower.iterate(iterations, this); if (streamlining) { flower.bindVel(); float sx = float(game->getMouseX()) / float(game->getResY()); float sy = 1.0f - float(game->getMouseY()) / float(game->getResY()); float x = (sx-0.5* float(game->getResX())/ float(game->getResY()))/scale+ viewX; float y = (sy-0.5)/scale+ viewY; if(x>0) x=x-static_cast<int>(x); else x=x-static_cast<int>(x)+1.0f; if(y>0) y=y-static_cast<int>(y); else y=y-static_cast<int>(y)+1.0f; slx[0] = x; sly[0] = y; while (slx[0] < 0.0f) slx[0] += 1.0f; while (sly[0] < 0.0f) sly[0] += 1.0f; while (slx[0] >= 1.0f) slx[0] -= 1.0f; while (sly[0] >= 1.0f) sly[0] -= 1.0f; for (int i = 1; i < slpnum; i++) { float pixel[3], xv, yv; float px = slx[i - 1], py = sly[i - 1]; while (px < 0.0f) px += 1.0f; while (py < 0.0f) py += 1.0f; while (px >= 1.0f) px -= 1.0f; while (py >= 1.0f) py -= 1.0f; //glReadPixels(int(px*float(size)),int(py*float(size)),1,1,GL_RGB,GL_FLOAT,(void *)pixel); getSpeed(size, pixel, px, py); xv = pixel[0]; yv = pixel[1]; float v = sqrt(xv * xv + yv * yv); if (v == 0.0f) v = 1.0f; float dl = 0.005f/scale; getSpeed(size, pixel, px + dl * xv / v / 2.0f, py + dl * yv / v / 2.0f); xv = pixel[0]; yv = pixel[1]; v = sqrt(xv * xv + yv * yv); if (v == 0.0f) v = 1.0f; slx[i] = slx[i - 1] + dl * xv / v; sly[i] = sly[i - 1] + dl * yv / v; } Fbo::unbind(); } if (game->isRightDown() && !painting) { flower.bindInk(); Shader::disable(); glActiveTextureARB(GL_TEXTURE2_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); glColor3f(inkRed*(1.0f-inkNew)+inkRedNew*inkNew,inkGreen*(1.0f-inkNew)+inkGreenNew*inkNew,inkBlue*(1.0f-inkNew)+inkBlueNew*inkNew); // glColor3f(1.0,1.0,1.0); drawMouseOffScreen(); Fbo::unbind(); } if (game->isKeyDown('t')) { if(!coordInk) { flower.bindInk(); Shader::disable(); glActiveTextureARB(GL_TEXTURE2_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); glVertex2f(0.0f, 0.0f); glVertex2f(1.0f, 0.0f); glVertex2f(1.0f, 1.0f); glVertex2f(0.0f, 1.0f); glEnd(); Fbo::unbind(); } else { TexGroup::getSingleton()->bind(flowerTex, 0); initFromFGMat.enable(); flower.bindInk(); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f); glEnd(); Fbo::unbind(); Shader::disable(); } } if (game->isKeyDown('r')) { flower.bindVel(); Shader::disable(); glActiveTextureARB(GL_TEXTURE2_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); glVertex2f(0.0f, 0.0f); glVertex2f(1.0f, 0.0f); glVertex2f(1.0f, 1.0f); glVertex2f(0.0f, 1.0f); glEnd(); Fbo::unbind(); } displayResult(); float sx = float(game->getMouseX()) / float(game->getResY()); float sy = 1.0f - float(game->getMouseY()) / float(game->getResY()); x = (sx-0.5* float(game->getResX())/ float(game->getResY()))/scale+ viewX; y = (sy-0.5)/scale+ viewY; if(x>0) x=x-static_cast<int>(x); else x=x-static_cast<int>(x)+1.0f; if(y>0) y=y-static_cast<int>(y); else y=y-static_cast<int>(y)+1.0f; float s = 0.02/scale; oldx1=x - s; oldx2=x + s; oldy1=y - s; oldy2=y + s; }