BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0), m_animation(this, "index") { setBackgroundBrush(QPixmap(":/images/background.jpg")); setScene(new QGraphicsScene(this)); setupScene(); setIndex(0); m_animation.setDuration(400); m_animation.setEasingCurve(QEasingCurve::InOutSine); setRenderHint(QPainter::Antialiasing, true); setFrameStyle(QFrame::NoFrame); }
//------------------------------------------------------------------------------ int main(int argc, char *argv[]) { osg::setNotifyLevel( osg::WARN ); osg::ArgumentParser arguments(&argc, argv); osgViewer::Viewer viewer(arguments); viewer.getCamera()->setComputeNearFarMode( osg::Camera::DO_NOT_COMPUTE_NEAR_FAR ); viewer.getCamera()->setClearColor( osg::Vec4(0.15, 0.15, 0.15, 1.0) ); viewer.setUpViewInWindow( 50, 50, 640, 480); viewer.addEventHandler(new osgViewer::StatsHandler); viewer.addEventHandler(new osgViewer::HelpHandler); // Use 'c'-key to display CUDA stats viewer.addEventHandler(new osgCuda::StatsHandler); ////////////////// // SETUP VIEWER // ////////////////// osgCuda::setupOsgCudaAndViewer( viewer ); ///////////////////// // PARTICLE BUFFER // ///////////////////// unsigned int numPtcls = 64000; osg::ref_ptr<osgCuda::Geometry> geom = new osgCuda::Geometry; geom->setName("Particles"); geom->addIdentifier( "PARTICLE BUFFER" ); osg::Vec4Array* coords = new osg::Vec4Array(numPtcls); for( unsigned int v=0; v<coords->size(); ++v ) (*coords)[v].set(-1,-1,-1,0); geom->setVertexArray(coords); geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS,0,coords->size())); ///////////////// // SETUP SCENE // ///////////////// osg::Vec3f bbmin = osg::Vec3f(0,0,0); osg::Vec3f bbmax = osg::Vec3f(4,4,4); // In this example we use an osg::Operation to update the // particle geometry during the Update Traversal. viewer.addUpdateOperation( new PtclOperation(*viewer.getFrameStamp(),geom->getMemory(),bbmin,bbmax) ); viewer.setSceneData( setupScene(geom,bbmin,bbmax) ); /////////////// // RUN SCENE // /////////////// return viewer.run(); }
int main (int argc, char ** argv) { GLenum type; glutInit(&argc, argv); glutInitWindowSize(CurrentWidth,CurrentHeight); type = GLUT_RGB; type |= GLUT_DOUBLE; type |= GLUT_DEPTH; type |= GLUT_MULTISAMPLE; glutInitDisplayMode(type); glutCreateWindow(""); #ifdef _WIN32 GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); } fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); #endif const GLubyte* glslVersion = glGetString(GL_SHADING_LANGUAGE_VERSION); printf("GLSL Version: %s\n",glslVersion); const GLubyte* glVersion = glGetString(GL_VERSION); printf("GL Version: %s\n",glVersion); glClearColor(0.0, 1.0, 0.0, 1.0); // Z-Buffer i aciyoruz glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); setupScene(); timerCallback(0); glutReshapeFunc(ResizeFunction); glutDisplayFunc(Draw); glutKeyboardFunc(Key); glutIdleFunc(IdleFunction); glutMainLoop(); return 0; }
int main (int argc, char ** argv) { GLenum type; glutInit(&argc, argv); glutInitWindowSize(CurrentWidth,CurrentHeight); type = GLUT_RGB; type |= GLUT_DOUBLE; type |= GLUT_DEPTH; type |= GLUT_MULTISAMPLE; glutInitDisplayMode(type); glutCreateWindow(""); glewInit(); glClearColor(0.0, 0.0, 0.0, 1.0); // Z-Buffer i aciyoruz glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); const GLubyte* glslVersion = glGetString(GL_SHADING_LANGUAGE_VERSION); printf("GLSL Version: %s\n",glslVersion); const GLubyte* glVersion = glGetString(GL_VERSION); printf("GL Version: %s\n",glVersion); setupScene(); timerCallback(0); glutReshapeFunc(ResizeFunction); glutDisplayFunc(Draw); glutKeyboardFunc(Key); glutIdleFunc(IdleFunction); printf("\n\n\tControls:\n"); printf("\t---------\n"); printf("\tQ: Increase power\n"); printf("\tA: Decrease power\n"); printf("\tW: Increase reflectance\n"); printf("\tS: Decrease reflectance\n\n"); glutMainLoop(); return 0; }
int main(int argc, char* argv[]) { OSG::osgInit(argc,argv); setupGlut(&argc, argv); setupScene(); OSG::commitChanges(); glutReshapeWindow(600, 600); glutMainLoop(); return EXIT_SUCCESS; }
void GraphicsManager::rebuildContext() { // Reintroduce glew to the surface GLenum glewErr = glewInit(); if (glewErr != GLEW_OK) throw Common::Exception("Failed initializing glew: %s", glewGetErrorString(glewErr)); // Reintroduce OpenGL to the surface setupScene(); // And reload/rebuild all GL containers rebuildGLContainers(); // Wait for everything to settle RequestMan.sync(); }
Lighting::Lighting(QWidget *parent): QGraphicsView(parent), angle(0.0) { setWindowTitle("Lighting and Shadows"); setScene(&m_scene); setupScene(); QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(animate())); timer->setInterval(30); timer->start(); setRenderHint(QPainter::Antialiasing, true); setFrameStyle(QFrame::NoFrame); }
FadeMessage::FadeMessage(QWidget *parent): QGraphicsView(parent) { setScene(&m_scene); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setupScene(); m_animation = new QPropertyAnimation(m_effect, "strength", this); m_animation->setDuration(500); m_animation->setEasingCurve(QEasingCurve::InOutSine); m_animation->setStartValue(0); m_animation->setEndValue(1); setRenderHint(QPainter::Antialiasing, true); setFrameStyle(QFrame::NoFrame); }
void StateLevel::init() { // Setup callbacks to user input setupInput(); // Setup message callbacks setupMessages(); // Setup level scene nodes setupScene(); setupLevel(); setupTrackers(); m_waveManager.setup( GAME_MANAGER.getLevelData() ); m_waveManager.start(); m_iKeyEscape = INPUT_MANAEGER.addCallback( InputManager::Event_KeyUp, sf::Keyboard::Escape, [this](){ MSG_SYSTEM.sendPost( c_msgStateChange, StateType::State_map ); } ); }
void LoadingScene::Enter() { RaceScene* scene = new RaceScene(mDevice, mVideoDriver); mRaceScene = scene; //CSceneLoader::load("main.scene", mRaceScene); //mFinishLoading = true; setupScene(); std::thread t([this]{ CSceneLoader::load("main.scene", mRaceScene, mPhysicalInfo); mFinishLoading = true; }); t.detach(); //CSceneLoader::load("main.scene", mRaceScene, mPhysicalInfo); //mFinishLoading = true; }
ScreenshotGrabber::ScreenshotGrabber() : QObject() , mKeysBlocked(false) , scene(0) , mQToxVisible(true) { window = new QGraphicsView(scene); // Top-level widget window->setWindowFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint); window->setContentsMargins(0, 0, 0, 0); window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); window->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); window->setFrameShape(QFrame::NoFrame); window->installEventFilter(this); #if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)) pixRatio = QApplication::primaryScreen()->devicePixelRatio(); #endif setupScene(); }
ThumbnailList::ThumbnailList(QWidget * parent) : QGraphicsView(parent), packet_(NULL), current_page_(NULL), scene_(NULL), layout_(NULL), context_thumb_(NULL), act_select_all_(NULL), act_recognize_(NULL), act_save_as_(NULL), act_properties_(NULL), act_delete_(NULL), act_open_external_(NULL) { setAcceptDrops(true); setupLayout(); setupScrollBars(); setupActions(); setupScene(); }
void Application::run() { initialize(); setupScene(); Ogre::Timer timer; timer.reset(); mRunning = true; while (mRunning) { const Ogre::Real delta= timer.getMicroseconds() * static_cast<Ogre::Real>(0.000001f); timer.reset(); runOneFrame(delta); } finalize(); }
int main(int argc, char *argv[]) { // Initialise OpenGL glutInit(&argc, argv); // Set window position, size & create window glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); if (fullscreen) { glutGameModeString("1900x1080:24"); glutEnterGameMode(); } else { glutInitWindowPosition(50,50); glutInitWindowSize(1600,1200); windowId = glutCreateWindow("Lab 4: Loading a textured model"); } // Set GLUT callback functions glutReshapeFunc(setViewport); glutDisplayFunc(renderScene); glutIdleFunc(updateScene); glutKeyboardFunc(keypress); glutKeyboardUpFunc(keyup); glutPassiveMotionFunc(mouseMove); glutMouseFunc(mouseClick); // Setup OpenGL state & scene resources (models, textures etc) setupScene(); importSkybox(); // Show window & start update loop glutMainLoop(); return 0; }
static void initWindow() { LOGI("------->initWindow() >>>>>>>>"); LOGI("Calling AConfiguration_new()"); AConfiguration* config = AConfiguration_new(); LOGI("AConfiguration_new() %p", config); AConfiguration_fromAssetManager(config, gAssetManager); LOGI("AConfiguration_fromAssetManager(config, gAssetManager) %p", config); if (!gRenderWnd) { Ogre::ArchiveManager::getSingleton().addArchiveFactory( new Ogre::APKFileSystemArchiveFactory(gAssetManager) ); Ogre::ArchiveManager::getSingleton().addArchiveFactory( new Ogre::APKZipArchiveFactory(gAssetManager) ); Ogre::NameValuePairList opt; LOGI("Ogre::StringConverter::toString((int)mRendereWindow) %s", Ogre::StringConverter::toString((int )mRendereWindow).c_str()); LOGI("Ogre::StringConverter::toString((int)config) %s", Ogre::StringConverter::toString((int )config).c_str()); opt["externalWindowHandle"] = Ogre::StringConverter::toString((int) mRendereWindow); opt["androidConfig"] = Ogre::StringConverter::toString((int) config); gRenderWnd = gRoot->createRenderWindow("OgreWindow", 0, 0, false, &opt); setupScene(); } else { static_cast<Ogre::AndroidEGLWindow*>(gRenderWnd)->_createInternalResources(mRendereWindow, config); } AConfiguration_delete(config); LOGI("<-------initWindow()"); }
void GraphicsManager::init() { Common::enforceMainThread(); uint32 sdlInitFlags = SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK; // TODO: Is this actually needed on any systems? It seems to make MacOS X fail to // receive any events, too. /* // Might be needed on unixoid OS, but it crashes Windows. Nice. #ifndef WIN32 sdlInitFlags |= SDL_INIT_EVENTTHREAD; #endif */ if (SDL_Init(sdlInitFlags) < 0) throw Common::Exception("Failed to initialize SDL: %s", SDL_GetError()); int width = ConfigMan.getInt ("width" , 800); int height = ConfigMan.getInt ("height" , 600); bool fs = ConfigMan.getBool("fullscreen", false); initSize(width, height, fs); setupScene(); // Try to change the FSAA settings to the config value if (_fsaa != ConfigMan.getInt("fsaa")) if (!setFSAA(ConfigMan.getInt("fsaa"))) // If that fails, set the config to the current level ConfigMan.setInt("fsaa", _fsaa); // Set the gamma correction to what the config specifies if (ConfigMan.hasKey("gamma")) setGamma(ConfigMan.getDouble("gamma", 1.0)); // Set the window title to our name setWindowTitle(PACKAGE_STRING); _ready = true; }
int main(int argc, char* argv[]) { //test(); //test2(); //return 0; //setup the scene printf("Setup...\n"); setupScene(); //render stuff printf("Begin Render\n"); #ifdef __linux__ struct timeval start, end; gettimeofday(&start, NULL); #endif render(); #ifdef __linux__ gettimeofday(&end, NULL); long seconds = end.tv_sec - start.tv_sec; long useconds = end.tv_usec - start.tv_usec; long mtime = static_cast<long>((seconds * 1000 + useconds / 1000.0f) + 0.5f); printf("Render Complete, Time Taken: %ld ms\n", mtime); #else printf("Render Complete\n"); #endif //output the render result printf("Writing Image\n"); outputImage(); //cleanup everything printf("Cleanup\n"); cleanupScene(); return 0; }
bool AppDemarrage::start() { //création du root mRoot = new Ogre::Root("plugins.cfg", "ogre.cfg", "Ogre.log"); //chargement des ressources Ogre::ConfigFile configFile; configFile.load("resources.cfg"); //Ajout des path des ressources dans le ResourceGroupManager Ogre::ConfigFile::SectionIterator seci = configFile.getSectionIterator(); Ogre::String secName, typeName, archName; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); } } //----------------------------------- //Chargement du moteur en lui-même : //----------------------------------- if(!(mRoot->restoreConfig() || mRoot->showConfigDialog())) //showConfigDialog = fenêtre choix de configuration qui renvoie true si utilisateur clique sur OK { return false; } //Configuration manuelle du RenderSystem : /*Ogre::RenderSystem *rs = mRoot->getRenderSystemByName("Direct3D9 Rendering Subsystem"); // Pour OpenGL : "OpenGL Rendering Subsystem" mRoot->setRenderSystem(rs); rs->setConfigOption("Full Screen", "No"); rs->setConfigOption("Video Mode", "1280 x 800 @ 32-bit colour"); rs->setConfigOption("VSync", "Yes");*/ // Création de la fenêtre mWindow = mRoot->initialise(true, "3DGameProject"); // 1er param : ogre crée la fenêtre lui-même ou pas, 2e param: titre de la fenêtre // Initialisation des resources et du nombre de MipMap par défaut: Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // Création du scene manager : mSceneMgr = mRoot->createSceneManager("DefaultSceneManager", "SceneManager"); // création de la scene avec le viewport, la camera et le player setupScene(); //remplissage de la scene remplirScene(); // instancie le FrameListener createFrameListener(); // Boucle infinie "toute faite" par Ogre // mRoot->startRendering(); //Boucle infinie manuelle : while(true) { // Methode qui prend en charge le raffraichissement de la fenêtre : Ogre::WindowEventUtilities::messagePump(); // Pour stopper le processus quand on ferme la fenêtre: if(mWindow->isClosed()) return false; // Pour faire le rendu if(!mRoot->renderOneFrame()) // Fait le rendu d'une image return false; } return true; }
Scene *loadScene(char *aFilename) { Scene *t = new Scene; json_stream json; FILE * f = fopen(aFilename, "rb"); json_open_stream(&json, f); json_type type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END && json_peek(&json) != JSON_ERROR) { type = json_next(&json); assert(type == JSON_STRING); const char *otype = json_get_string(&json, 0); if (strcmp(otype, "material") == 0) { const char *name = "[untitled]"; glm::vec3 diffuse(1); glm::vec3 specular(0); glm::vec3 ambient(0); float opacity = 1; float reflection = 0; type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END) { type = json_next(&json); assert(type == JSON_STRING); otype = json_get_string(&json, 0); if (!getJSONString(&json, "name", otype, (char**)&name)) if (!getJSONVec3(&json, "diffuse", otype, diffuse)) if (!getJSONVec3(&json, "ambient", otype, ambient)) if (!getJSONVec3(&json, "specular", otype, specular)) if (!getJSONNumber(&json, "opacity", otype, opacity)) if (!getJSONNumber(&json, "reflection", otype, reflection)) assert(0 && "error parsing material"); } type = json_next(&json); assert(type == JSON_OBJECT_END); Material *m = new Material(); m->mName = (char*)name; m->mDiffuse = diffuse; m->mAmbient = ambient; m->mSpecular = specular; m->mOpacity = opacity; m->mReflection = reflection; m->mNext = t->mMaterial; t->mMaterial = m; } else if (strcmp(otype, "box") == 0) { const char *name = "[untitled]"; const char *material = "default"; glm::vec3 center; glm::vec3 size; float dynamic = 0; type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END) { type = json_next(&json); assert(type == JSON_STRING); otype = json_get_string(&json, 0); if (!getJSONString(&json, "name", otype, (char**)&name)) if (!getJSONString(&json, "material", otype, (char**)&material)) if (!getJSONNumber(&json, "dynamic", otype, dynamic)) if (!getJSONVec3(&json, "position", otype, center)) if (!getJSONVec3(&json, "center", otype, center)) if (!getJSONVec3(&json, "size", otype, size)) assert(0 && "error parsing box"); } type = json_next(&json); assert(type == JSON_OBJECT_END); SceneObject *so; t->insert(so = new Box((char*)name, center, size, t->getMaterialByName((char*)material))); so->mDynamic = dynamic != 0; } else if (strcmp(otype, "plane") == 0) { const char *name = "[untitled]"; const char *material = "default"; glm::vec3 point; glm::vec3 normal; float dynamic = 0; type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END) { type = json_next(&json); assert(type == JSON_STRING); otype = json_get_string(&json, 0); if (!getJSONString(&json, "name", otype, (char**)&name)) if (!getJSONString(&json, "material", otype, (char**)&material)) if (!getJSONNumber(&json, "dynamic", otype, dynamic)) if (!getJSONVec3(&json, "point", otype, point)) if (!getJSONVec3(&json, "normal", otype, normal)) assert(0 && "error parsing box"); } type = json_next(&json); assert(type == JSON_OBJECT_END); SceneObject *so; t->insert(so = new Plane((char*)name, point, normal, t->getMaterialByName((char*)material))); so->mDynamic = dynamic != 0; } else if (strcmp(otype, "sphere") == 0) { const char *name = "[untitled]"; const char *material = "default"; glm::vec3 center; float radius = 5; float dynamic = 0; type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END) { type = json_next(&json); assert(type == JSON_STRING); otype = json_get_string(&json, 0); if (!getJSONString(&json, "name", otype, (char**)&name)) if (!getJSONString(&json, "material", otype, (char**)&material)) if (!getJSONNumber(&json, "dynamic", otype, dynamic)) if (!getJSONVec3(&json, "center", otype, center)) if (!getJSONVec3(&json, "position", otype, center)) if (!getJSONNumber(&json, "radius", otype, radius)) assert(0 && "error parsing sphere"); } type = json_next(&json); assert(type == JSON_OBJECT_END); SceneObject *so; t->insert(so = new Sphere((char*)name, center, radius, t->getMaterialByName((char*)material))); so->mDynamic = dynamic != 0; } else if (strcmp(otype, "light") == 0) { const char *name = "[untitled]"; const char *material = "default"; glm::vec3 position; type = json_next(&json); assert(type == JSON_OBJECT); while (json_peek(&json) != JSON_OBJECT_END) { type = json_next(&json); assert(type == JSON_STRING); otype = json_get_string(&json, 0); if (!getJSONString(&json, "name", otype, (char**)&name)) if (!getJSONString(&json, "material", otype, (char**)&material)) if (!getJSONVec3(&json, "position", otype, position)) assert(0 && "error parsing light"); } type = json_next(&json); assert(type == JSON_OBJECT_END); t->insert(new Light((char*)name, position, t->getMaterialByName((char*)material))); } else { assert(0); } } type = json_next(&json); if (type == JSON_ERROR) { const char * err = json_get_error(&json); err = err; } assert(type == JSON_OBJECT_END); type = json_next(&json); assert(type == JSON_DONE); json_close(&json); setupScene(t); t->optimize(); return t; };
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setupScene(); setCentralWidget(m_view); }
void TimeScene::refresh() { initialize(); setupScene(); }
void TimeScene::setModel(TaskModel* model) { initialize(); _model = model; connect(_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(refresh())); setupScene(); }
void ofApp::windowResized(int w, int h) { setupScene(w, h); }
void LogScene::refresh() { initialize(); setupScene(); }
void ParticleDemo::initPhysics(const ConstructionInfo& ci) { setupScene(ci); }
//-------------------------------------------------------------- void kinectApp::setup() { ofSetWindowTitle("KinectA"); //-- initialize generals --// width = 640; height = 480; nrHand = 8; nrBody = 4; nrObjects = 20; for (int i = 0; i < nrHand; i++){ idHand[i] = 0; } for (int i = 0; i < nrBody; i++){ idBody[i] = 0; } for (int i = 0; i < nrObjects; i++){ idObject[i] = 0; } ofBackground(50, 50, 50); // TODO: make this work with sandbox background.loadImage("background/Interface.png"); background.allocate(905, 730, OF_IMAGE_COLOR_ALPHA); //-- initialize gui classes & variables --// // TODO: make this work with sandbox usedFont.loadFont("fonts/Questrial-Regular.ttf", 9); usedFont.setLineHeight(14); statusConfig = "new"; //-- initialize ofxOpenNI --// isLive = true; setupScene(); maskPixels = new unsigned char[width * height]; kinectImage.allocate(width, height); kinectImage.setUseTexture(false); for (int i = 0; i < nrBody; i++){ userImg[i].allocate(width, height); } //-- initialize classes & variables for ofxOpenCV --// filters = NULL; filters = new applyfilter(); processedImg.allocate(640, 480); processedImg.setUseTexture(false); filters->allocate(640, 480); sourceImg.allocate(640, 480); sourceImg.setUseTexture(false); for (int i = 0; i < nrObjects; i++){ singleSourceImg[i].allocate(640, 480); singleSourceImg[i].setUseTexture(false); blobImg[i].allocate(640, 480); blobImg[i].setUseTexture(false); } fullsize = width * height; nearThreshold = 500; farThreshold = 1000; minBlobSize = 1500; maxBlobSize = 10000; //-- initialize OSC --// host = "127.0.0.1"; port = 3333; sender.setup(host, port); }
void Game::create_level() { delete current_level; current_level = LevelFactory::create(level, main_scene, spoony_message, sound_handler, global_timer, this); setupScene(); }
bool MyApp::initialise(HINSTANCE hInstance, int cmdShow) { if (!DxApp::initialise(hInstance, cmdShow, 1024, 768)) return false; // Build FXs if (FAILED(buildFX())) { MessageBox(hWnd(), L"Cannot create effects", L"Error", MB_OK|MB_ICONERROR); return false; } // Build Geometry if (FAILED(buildGeometry())) { MessageBox(hWnd(), L"Cannot create geometry", L"Error", MB_OK|MB_ICONERROR); return false; } // Textures HRESULT hr = D3DX11CreateShaderResourceViewFromFileA(_dxDev, (PATH_MEDIA+string("noise_texture.jpg")).c_str(), 0, 0, &m_srvRandom, 0); if (FAILED(hr)) { MessageBoxA(0, "Error loading random texture", 0, 0); return false; } // flags for heightmap texture D3DX11_IMAGE_LOAD_INFO loadInfo; loadInfo.Width = D3DX11_DEFAULT; loadInfo.Height = D3DX11_DEFAULT; loadInfo.Depth = D3DX11_DEFAULT; loadInfo.FirstMipLevel = D3DX11_DEFAULT; loadInfo.MipLevels = D3DX11_DEFAULT; loadInfo.Usage = (D3D11_USAGE)D3DX11_DEFAULT; loadInfo.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; //D3DX11_DEFAULT; loadInfo.CpuAccessFlags = loadInfo.MiscFlags = D3DX11_DEFAULT; loadInfo.Format = DXGI_FORMAT_R32G32B32A32_FLOAT ; loadInfo.Filter = D3DX11_DEFAULT; loadInfo.MipFilter = D3DX11_DEFAULT; loadInfo.pSrcInfo = NULL; hr = D3DX11CreateShaderResourceViewFromFileA(_dxDev, (PATH_MEDIA+string("heightmap.jpg")).c_str(), &loadInfo, 0, &m_srvTerrainHmap, 0); if (FAILED(hr)) { MessageBoxA(0, "Error loading terrain heightmap", 0, 0); return false; } hr = D3DX11CreateShaderResourceViewFromFileA(_dxDev, (PATH_MEDIA+string("normalmap.bmp")).c_str(), 0, 0, &m_srvTerrainNmap, 0); if (FAILED(hr)) { MessageBoxA(0, "Error loading terrain normalmap", 0, 0); return false; } hr = D3DX11CreateShaderResourceViewFromFileA(_dxDev, (PATH_MEDIA+string("space_ship.jpg")).c_str(), 0, 0, &m_srvSpaceship, 0); if (FAILED(hr)) { MessageBoxA(0, "Error loading spaceship texture", 0, 0); return false; } // Dynamic terrain ID3D11Resource* resHmap = 0; m_srvTerrainHmap->GetResource(&resHmap); D3D11_RENDER_TARGET_VIEW_DESC rtd; rtd.Format = DXGI_FORMAT_R32G32B32A32_FLOAT ; rtd.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; rtd.Texture2D.MipSlice = 0; hr = _dxDev->CreateRenderTargetView(resHmap, &rtd, &m_rtvDynamicHmap); if (FAILED(hr)) { MessageBoxA(0, "Error creating hmap rtv", 0, 0); return false; } //////////////////////////////////// //rs_Wireframe D3D11_RASTERIZER_DESC rsd; ZeroMemory(&rsd, sizeof(rsd)); rsd.FillMode = D3D11_FILL_WIREFRAME; rsd.CullMode = D3D11_CULL_BACK; rsd.DepthClipEnable = true; hr = _dxDev->CreateRasterizerState(&rsd, &rs_Wireframe); if (FAILED(hr)) MessageBoxA(0, "error creating rs Wireframe", 0, 0); // Camera m_camera.setProjection(0.7f, width()/(float)height(), 1.0f, 500.0f); m_camera.setPosVector(0.0f, 30.0f, 0.0f); m_camera.setRightVector(1.0f, 0.0f, 0.0f); m_camera.setUpVector(0.0f, 1.0f, 0.0f); m_camera.setLookVector(0.0f, 0.0f, 1.0f); // myAlien myAlien.setPos(0,5,0); myAlien.type = AlienTypes::GS_ALIEN; myAlien.mesh = alienMesh; // Textures/Views for Implicit surfaces if (!createImplicitResources()) return false; // Tessellation - control point(s) buffer //____ check for DX11 support__ if (dx11Support()) { // Single control point vertex buffer D3D11_BUFFER_DESC bdsc; bdsc.BindFlags = D3D11_BIND_VERTEX_BUFFER; bdsc.CPUAccessFlags = 0; bdsc.MiscFlags = 0; bdsc.StructureByteStride = 0; bdsc.Usage = D3D11_USAGE_IMMUTABLE; #ifdef _TESS_INDEX_BUFFER // Version 2 : 6 vertices - W/ Index Buffer const int numVertices = 6; Vertex ctrl_point[numVertices]; bdsc.ByteWidth = sizeof(Vertex)*numVertices; ZeroMemory(ctrl_point, sizeof(Vertex)*numVertices); ctrl_point[0].position = XMFLOAT3( 0.0f, 1.0f, 0.0f); // top ctrl_point[1].position = XMFLOAT3(-1.0f, 0.0f, 1.0f); // 1 ------> 2 (+,+) ctrl_point[2].position = XMFLOAT3( 1.0f, 0.0f, 1.0f); // ctrl_point[3].position = XMFLOAT3(-1.0f, 0.0f, -1.0f); // ctrl_point[4].position = XMFLOAT3( 1.0f, 0.0f, -1.0f); // (-,-) 3 ------> 4 ctrl_point[5].position = XMFLOAT3( 0.0f, -1.0f, 0.0f); // bottom UINT indices[24]; // top-front indices[0] = 0; indices[1] = 4; indices[2] = 3; // top-right indices[3] = 0; indices[4] = 2; indices[5] = 4; // top-left indices[6] = 0; indices[7] = 3; indices[8] = 1; // top-back indices[9] = 0; indices[10] = 1; indices[11] = 2; // bottom-front indices[12] = 5; indices[13] = 3; indices[14] = 4; // bottom-right indices[15] = 5; indices[16] = 4; indices[17] = 2; // bottom-left indices[18] = 5; indices[19] = 1; indices[20] = 3; // bottom-back indices[21] = 5; indices[22] = 2; indices[23] = 1; D3D11_BUFFER_DESC idsc; idsc.BindFlags = D3D11_BIND_INDEX_BUFFER; idsc.CPUAccessFlags = 0; idsc.MiscFlags = 0; idsc.StructureByteStride = 0; idsc.Usage = D3D11_USAGE_IMMUTABLE; idsc.ByteWidth = sizeof(UINT) * 24; D3D11_SUBRESOURCE_DATA ibdata; ibdata.pSysMem = indices; ibdata.SysMemPitch = ibdata.SysMemSlicePitch = 0; // create index buffer hr = _dxDev->CreateBuffer(&idsc, &ibdata, &m_ibControlPoints); #else // Version 1 : 24 vertices - No Index Buffer const int numVertices = 3*8; // triangle list - 8 triangles Vertex ctrl_point[numVertices]; bdsc.ByteWidth = sizeof(Vertex) * numVertices; // three control points ZeroMemory(ctrl_point, sizeof(Vertex)*numVertices); // octahedron // CW // top - front ctrl_point[0].position = XMFLOAT3( 0.0f, 1.0f, 0.0f); ctrl_point[1].position = XMFLOAT3( 1.0f, 0.0f, -1.0f); ctrl_point[2].position = XMFLOAT3(-1.0f, 0.0f, -1.0f); // top - right ctrl_point[3].position = XMFLOAT3( 0.0f, 1.0f, 0.0f); ctrl_point[4].position = XMFLOAT3( 1.0f, 0.0f, 1.0f); ctrl_point[5].position = XMFLOAT3( 1.0f, 0.0f, -1.0f); // top - left ctrl_point[6].position = XMFLOAT3( 0.0f, 1.0f, 0.0f); ctrl_point[7].position = XMFLOAT3(-1.0f, 0.0f, -1.0f); ctrl_point[8].position = XMFLOAT3( -1.0f, 0.0f, 1.0f); // top - back ctrl_point[9].position = XMFLOAT3( 0.0f, 1.0f, 0.0f); ctrl_point[10].position = XMFLOAT3(-1.0f, 0.0f, 1.0f); ctrl_point[11].position = XMFLOAT3( 1.0f, 0.0f, 1.0f); // bottom - front ctrl_point[12].position = XMFLOAT3( 0.0f, -1.0f, 0.0f); ctrl_point[13].position = XMFLOAT3(-1.0f, 0.0f, -1.0f); ctrl_point[14].position = XMFLOAT3( 1.0f, 0.0f, -1.0f); // bottom - right ctrl_point[15].position = XMFLOAT3( 0.0f, -1.0f, 0.0f); ctrl_point[16].position = XMFLOAT3( 1.0f, 0.0f, -1.0f); ctrl_point[17].position = XMFLOAT3( 1.0f, 0.0f, 1.0f); // bottom - left ctrl_point[18].position = XMFLOAT3( 0.0f, -1.0f, 0.0f); ctrl_point[19].position = XMFLOAT3(-1.0f, 0.0f, 1.0f); ctrl_point[20].position = XMFLOAT3(-1.0f, 0.0f, -1.0f); // bottom - back ctrl_point[21].position = XMFLOAT3( 0.0f, -1.0f, 0.0f); ctrl_point[22].position = XMFLOAT3( 1.0f, 0.0f, 1.0f); ctrl_point[23].position = XMFLOAT3(-1.0f, 0.0f, 1.0f); #endif D3D11_SUBRESOURCE_DATA bdata; bdata.pSysMem = ctrl_point; bdata.SysMemPitch = bdata.SysMemSlicePitch = 0; hr = _dxDev->CreateBuffer(&bdsc, &bdata, &m_vbControlPoints); if (FAILED(hr)) { MessageBoxA(0, "Error creating control points buffer", 0, 0); return false; } // Bezier surface effect if (!createEffect((PATH_SHADERS+string("tessBezierSurface.fxo")).c_str(), &m_fxTessBezierSurface)) MessageBoxA(0, "Error creating bezSurface effect", 0, 0); // PSP surface effect if (!createEffect((PATH_SHADERS+string("tessPSPSurface.fxo")).c_str(), &m_fxTessPSPSurface)) MessageBoxA(0, "Error creating pspSurface effect", 0, 0); // Sphere effect if (!createEffect((PATH_SHADERS+string("tessSphere.fxo")).c_str(), &m_fxTessSphere)) MessageBoxA(0, "Error creating tessSphere effect", 0, 0); // Mesh effect if (!createEffect((PATH_SHADERS+string("tessMesh.fxo")).c_str(), &m_fxTessMesh)) MessageBoxA(0, "Error creating tessMesh effect", 0, 0); // Terrain effect if (!createEffect((PATH_SHADERS+string("tessTerrain.fxo")).c_str(), &m_fxTessTerrain)) MessageBoxA(0, "Error creating tessMesh effect", 0, 0); ///____SINGLE_________ ZeroMemory(&bdsc, sizeof(bdsc)); bdsc.BindFlags = D3D11_BIND_VERTEX_BUFFER; bdsc.ByteWidth = sizeof(Vertex); bdsc.Usage = D3D11_USAGE_IMMUTABLE; Vertex vSingle[1]; ZeroMemory(&vSingle, sizeof(vSingle)); ZeroMemory(&bdata, sizeof(bdata)); bdata.pSysMem = vSingle; hr = _dxDev->CreateBuffer(&bdsc, &bdata, &m_vbSingle); if (FAILED(hr)) MessageBoxA(0, "Error creating single VB", 0, 0); if (!createEffect((PATH_SHADERS+string("tessSingle.fxo")).c_str(), &m_fxTessSingle)) MessageBoxA(0, "Error creating tessSingle effect", 0, 0); //_____________________ } mySphere.tessFactor = 5; mySphere.radius = 10.0f; setupScene(); // GUI TwInit(TW_DIRECT3D11, _dxDev); TwWindowSize(width(), height()); TwBar* myBar; myBar = TwNewBar("myBar"); TwAddButton(myBar, "Play", callback_Play, (void*)this, 0); TwAddButton(myBar, "Explode", callback_Explode, (void*)this, 0); // __________GS Alien TwAddVarRW(myBar, "Thorn length", TW_TYPE_FLOAT, &glb_fThornLength, "group=GS_Alien min=0.0 max=1.0 step=0.05"); // __________Selected Tessellated Object // Partitioning TwEnumVal twTessPartitioning[] = { { TessPartitioning::FRAC_EVEN, "Frac. Even" }, { TessPartitioning::FRAC_ODD, "Frac. Odd" }, { TessPartitioning::INTEGER, "Integer" }, { TessPartitioning::POW2 , "Pow2" } }; TwType twTessPartition; twTessPartition = TwDefineEnum("TessPartitioning", twTessPartitioning, 4); TwAddVarRW(myBar, "Partitioning Method", twTessPartition, &glb_selectedTessPartitioning, "group=Tessellated_Objects"); // Wireframe TwAddVarRW(myBar, "Wireframe", TW_TYPE_BOOL8, &glb_tessWireframe, "group=Tessellated_Objects"); // Inside Factor TwAddVarRW(myBar, "Inside Factor", TW_TYPE_FLOAT, &glb_insideTess, "group=Tessellated_Objects min=1 max=64 step=1"); // Edge Factor TwAddVarRW(myBar, "Edge Factor", TW_TYPE_FLOAT, &glb_edgeTess, "group=Tessellated_Objects min=1 max=64 step=1"); // Common inside/edge factor TwAddVarRW(myBar, "Common Factor", TW_TYPE_FLOAT, &glb_SingleTessFactor, "group=Tessellated_Objects min=1 max=64 step=1"); TwAddVarRW(myBar, "Single Factor", TW_TYPE_BOOL8, &glb_bSingleTessFactor, ""); ///////////////////// TwAddVarRW(myBar, "Terrain Height", TW_TYPE_FLOAT, &glb_terrainHeight, "group=Terrain min=0.0 max=1.0 step=0.05"); TwAddVarRW(myBar, "Patches Dimension", TW_TYPE_INT32, &glb_terrainPatchDim, "group=Terrain min=1 max=10 step=1"); TwAddVarRW(myBar, "Min Tess. Factor", TW_TYPE_FLOAT, &glb_terrainMinTessFactor, "group=Terrain min=1 max=63 step=1"); TwAddVarRW(myBar, "Max Tess. Factor", TW_TYPE_FLOAT, &glb_terrainMaxTessFactor, "group=Terrain min=1 max=63 step=1"); TwAddVarRW(myBar, "Min View Dist", TW_TYPE_FLOAT, &glb_terrainMinViewDist, "group=Terrain min=0.0 max=300.0 step=1.05"); TwAddVarRW(myBar, "Max View Dist", TW_TYPE_FLOAT, &glb_terrainMaxViewDist, "group=Terrain min=0.0 max=300.0 step=1.05"); TwAddVarRW(myBar, "Debug View", TW_TYPE_BOOL8, &glb_bTerrainDebugView, "group=Terrain"); // Terrain Editing TwAddVarRW(myBar, "Power", TW_TYPE_BOOL8, &glb_bOn, "group=Terrain_Edit"); TwAddVarRW(myBar, "Additive", TW_TYPE_BOOL8, &glb_bAdditive, "group=Terrain_Edit"); TwAddVarRW(myBar, "Range", TW_TYPE_FLOAT, &glb_Range, "group=Terrain_Edit min=0.0 max=1.0 step=0.05"); // Light TwAddVarRW(myBar, "Light Direction", TW_TYPE_DIR3F, &glb_lightDir, ""); TwAddVarRW(myBar, "Light Color", TW_TYPE_COLOR4F, &glb_lightColor, ""); // Implicit Depth TwAddVarRW(myBar, "Implicit Depth", TW_TYPE_INT32, &glb_iImplicitDepth, "group=Implicit min=1 max=3"); TwAddVarRW(myBar, "Wireframe Mode", TW_TYPE_BOOL8, &glb_bWireframe, ""); TwAddVarRW(myBar, "Sphere From Mesh", TW_TYPE_BOOL8, &glb_bSphereMesh, ""); return true; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setupScene(); }