static void MoveCamera(FPSCamera &cam, fwk::GfxDevice &device, float speed) { auto input = device.inputState(); if(input.isKeyPressed(InputKey::lshift)) speed *= 5.f; if(input.isMouseButtonPressed(InputButton::left)) { device.grabMouse(true); float dx = input.mouseMove().x; float dy = input.mouseMove().y; if(dx) cam.Rotate(-dx * 0.01); if(dy) cam.RotateY(dy * 0.01); } else { device.grabMouse(false); } Vec3f move(0, 0, 0); Camera tcam = (Camera)cam; if(input.isKeyPressed('w')) move += tcam.front; if(input.isKeyPressed('s')) move -= tcam.front; if(input.isKeyPressed('a')) move -= tcam.right; if(input.isKeyPressed('d')) move += tcam.right; if(input.isKeyPressed('r')) move += tcam.up; if(input.isKeyPressed('f')) move -= tcam.up; cam.Move(move * speed); }
void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if ( input.isKey(27) ) exit(0); // + - if ( input.isKeyClick('=') ) program->getStates().maxTessLevel++; if ( input.isKeyClick('-') ) program->getStates().maxTessLevel--; // < > if ( input.isKeyClick(',') ) program->getStates().detailLevel--; if ( input.isKeyClick('.') ) program->getStates().detailLevel++; // up, down if ( input.isSpecKeyClick(GLUT_KEY_UP) ) camSpeed += 0.01f; if ( input.isSpecKeyClick(GLUT_KEY_DOWN) ) camSpeed -= 0.01f; // ( ) if ( input.isKeyClick('9') && modeIndex > 0 ) modeIndex--; if ( input.isKeyClick('0') && modeIndex < 7 ) modeIndex++; if ( input.isKeyClick('r') ) { currentMode->unload(); currentMode->load(); } // reload if ( input.isKeyClick('p') ) wireframe = !wireframe; // 1..4 if ( input.isKey('1') ) modeIndex = 0; if ( input.isKey('2') ) modeIndex = 1; if ( input.isKey('3') ) modeIndex = 2; if ( input.isKey('4') ) modeIndex = 3; if ( input.isKey('5') ) modeIndex = 4; if ( input.isKey('6') ) modeIndex = 5; if ( input.isKey('7') ) modeIndex = 6; if ( input.isKey('8') ) modeIndex = 7; // F1..F7 if ( input.isSpecKeyClick(GLUT_KEY_F1) ) loadMode( 0 ); if ( input.isSpecKeyClick(GLUT_KEY_F2) ) loadMode( 1 ); if ( input.isSpecKeyClick(GLUT_KEY_F3) ) loadMode( 2 ); if ( input.isSpecKeyClick(GLUT_KEY_F4) ) loadMode( 3 ); if ( input.isSpecKeyClick(GLUT_KEY_F5) ) loadMode( 4 ); if ( input.isSpecKeyClick(GLUT_KEY_F6) ) loadMode( 5 ); if ( input.isSpecKeyClick(GLUT_KEY_F7) ) loadMode( 6 ); cam.rotate( input.mouseDelta() * 0.2f ); const float time_delta = sys.getTimeDelta() * camSpeed; cam.move( (input.isKey('w') - input.isKey('s')) * time_delta, (input.isKey('d') - input.isKey('a')) * time_delta, (input.isKey('q') - input.isKey('e')) * time_delta ); program->getStates().mvp = cam.toMatrixScale( 10.f ); currentMode->draw( modeIndex ); }
void init() { sys.setCurrentDirectory( "samples/blending/media" ); scene = new MultiMesh(); scene->load( "meshes/SMUT.3ds", "textures/" ); fullScreenQuad = new Mesh(); fullScreenQuad->makeQuad(); program = new Program(); currentMode = allModes[0]; currentMode->load(); glEnable( GL_DEPTH_CLAMP ); glEnable( GL_DEPTH_TEST ); //glCullFace( GL_FRONT ); glDisable( GL_CULL_FACE ); sys.swapInterval( 0 ); cam.init( 60.0f, float(sys.getWndSize().x) / float(sys.getWndSize().y), 0.1f, 500.0f ); glClearColor( 0.f, 0.3f, 1.f, 1.f ); glClearDepthf( 1.f ); }
void MasterRenderer::Render(Light& light, FPSCamera camera) { // Clear buffers and activate the shader glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Load terrain shader parameters and render terrains m_terrainShader.Use(); m_terrainShader.LoadLight(light, 0.1f); m_terrainShader.LoadViewMatrix(camera.GetViewMatrix()); m_terrainRenderer.Render(terrains); m_terrainShader.UnUse(); terrains.clear(); // Load basic shader parameters and render entities m_basicShader.Use(); m_basicShader.LoadLight(light, 0.1f); m_basicShader.LoadViewMatrix(camera.GetViewMatrix()); m_entityRenderer.Render(m_entities, camera.GetPosition()); m_basicShader.UnUse(); m_entities.clear(); }
void init() { sys.setCurrentDirectory( "media" ); gridMesh = new Mesh(); fullScreenQuad = new Mesh(); fullScreenQuad->makeQuad(); diffuseMap = new Texture( GL_TEXTURE_2D ); heightMap = new Texture( GL_TEXTURE_2D ); normalMap = new Texture( GL_TEXTURE_2D ); diffuseMap->loadDDS( "textures/grass.dds" ); heightMap->loadDDS( "textures/height.dds" ); normalMap->loadDDS( "textures/normal.dds" ); diffuseMap->bind(); diffuseMap->setWrap( GL_REPEAT, GL_REPEAT ); diffuseMap->setAnisotropy( 16 ); diffuseMap->unbind(); heightMap->bind(); heightMap->setWrap( GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE ); heightMap->unbind(); normalMap->bind(); normalMap->setWrap( GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE ); normalMap->unbind(); program = new Program(); currentMode = allModes[0]; currentView = new View(); currentView->init(); currentMode->load(); primitivesQuery = new Query(); glEnable( GL_DEPTH_CLAMP ); glEnable( GL_DEPTH_TEST ); glCullFace( GL_FRONT ); sys.swapInterval( 0 ); cam.init( 60.0f, float(sys.getWndSize().x) / float(sys.getWndSize().y), 1.f, 3000.0f, glm::vec3( -program->getStates().gridScale * 0.5f, program->getStates().heightScale * 0.1f, -program->getStates().gridScale * 0.5f ) ); }
static void MoveCamera(FPSCamera &cam, GLWindow &window, float speed) { if(window.Key(Key_lshift)) speed *= 5.f; if(window.MouseKey(0)) { window.GrabMouse(1); float dx = window.MouseMove().x; float dy = window.MouseMove().y; if(dx) cam.Rotate(dx * 0.005); if(dy) cam.RotateY(dy * 0.005); } else window.GrabMouse(0); Vec3f move(0, 0, 0); Camera tcam = (Camera)cam; if(window.Key('W')) move += tcam.front; if(window.Key('S')) move -= tcam.front; if(window.Key('A')) move += tcam.right; if(window.Key('D')) move -= tcam.right; if(window.Key('R')) move += tcam.up; if(window.Key('F')) move -= tcam.up; cam.Move(move * speed); }
void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if ( input.isKey(27) ) exit(0); // + - if ( input.isKeyClick('=') ) program->getStates().maxTessLevel++; if ( input.isKeyClick('-') ) program->getStates().maxTessLevel--; // < > if ( input.isKeyClick(',') ) program->getStates().detailLevel--; if ( input.isKeyClick('.') ) program->getStates().detailLevel++; // [ ] if ( input.isKeyClick('[') ) program->getStates().heightScale++; if ( input.isKeyClick(']') ) program->getStates().heightScale--; // left, right if ( input.isSpecKeyClick(GLUT_KEY_LEFT) ) program->getStates().gridScale -= 10.f; if ( input.isSpecKeyClick(GLUT_KEY_RIGHT)) program->getStates().gridScale += 10.f; // up, down if ( input.isSpecKeyClick(GLUT_KEY_UP) ) camSpeed += 0.01f; if ( input.isSpecKeyClick(GLUT_KEY_DOWN) ) camSpeed -= 0.01f; // ( ) if ( input.isKeyClick('9') && modeIndex > 0 ) modeIndex--; if ( input.isKeyClick('0') && modeIndex < 6 ) modeIndex++; if ( input.isKeyClick('r') ) { currentMode->unload(); // reload currentMode->load(); } if ( input.isKeyClick('c') ) viewIndex = VIEW_COLOR; // view color map if ( input.isKeyClick('n') ) viewIndex = VIEW_NORMAL; // view normal map if ( input.isKeyClick('t') ) viewIndex = VIEW_TESS; // view tess level map if ( input.isKeyClick('m') ) viewIndex = VIEW_COLOR_MIX_TESS; if ( input.isKeyClick('f') ) viewIndex = VIEW_FOG; if ( input.isKeyClick('p') ) wireframe = !wireframe; // 1..4 if ( input.isKey('1') ) modeIndex = 0; if ( input.isKey('2') ) modeIndex = 1; if ( input.isKey('3') ) modeIndex = 2; if ( input.isKey('4') ) modeIndex = 3; // F1..F7 if ( input.isSpecKeyClick(GLUT_KEY_F1) ) loadMode( 0 ); if ( input.isSpecKeyClick(GLUT_KEY_F2) ) loadMode( 1 ); if ( input.isSpecKeyClick(GLUT_KEY_F3) ) loadMode( 2 ); if ( input.isSpecKeyClick(GLUT_KEY_F4) ) loadMode( 3 ); if ( input.isSpecKeyClick(GLUT_KEY_F5) ) loadMode( 4 ); if ( input.isSpecKeyClick(GLUT_KEY_F6) ) loadMode( 5 ); if ( input.isSpecKeyClick(GLUT_KEY_F7) ) loadMode( 6 ); cam.rotate( input.mouseDelta() * 0.2f ); const float time_delta = sys.getTimeDelta() * camSpeed; cam.move( (input.isKey('w') - input.isKey('s')) * time_delta, (input.isKey('d') - input.isKey('a')) * time_delta, (input.isKey('q') - input.isKey('e')) * time_delta ); program->getStates().mvp = cam.toMatrix(); currentView->bind(); glPolygonMode( GL_FRONT_AND_BACK, wireframe ? GL_LINE : GL_FILL ); glEnable( GL_CULL_FACE ); if ( updateQuery ) primitivesQuery->begin( GL_PRIMITIVES_GENERATED ); currentMode->draw( modeIndex ); if ( updateQuery ) { primitivesQuery->end(); updateQuery = false; } glDisable( GL_CULL_FACE ); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); currentView->unbind(); currentView->draw( viewIndex ); }
static int tmain(int argc, char **argv) { if(argc>=2 && string("--help") == argv[1]) { PrintHelp(); return 0; } CameraConfigs camConfigs; try { Loader("scenes/cameras.dat") & camConfigs; } catch(...) { } int resx = 1024, resy = 1024; bool fullscreen = 0; int threads = 2; string sceneName = "/mnt/data/volumes/zatoki/dicom/"; bool flipNormals = 1, swapYZ = 0; string texPath = ""; int rebuild = 0, buildFlags = 8; int nInstances = 1; int nPlanes = 256; for(int n = 1; n < argc; n++) { if(string("-res") == argv[n] && n < argc-2) { resx = atoi(argv[n+1]); resy = atoi(argv[n+2]); n += 2; } else if(string("-rebuild") == argv[n]) rebuild = 1; else if(string("-threads") == argv[n] && n < argc - 1) { threads = atoi(argv[n + 1]); n += 1; } else if(string("-fullscreen") == argv[n]) fullscreen = 1; else if(string("-flipNormals") == argv[n]) flipNormals = 0; else if(string("-swapYZ") == argv[n]) swapYZ = 1; else if(string("-noDump") == argv[n]) buildFlags &= ~8; else if(string("-instances") == argv[n]) { nInstances = atoi(argv[n + 1]); n += 1; } else { if(argv[n][0] == '-') { printf("Unknown option: %s\n",argv[n]); exit(0); } else sceneName = argv[n]; } } if(texPath == "") { texPath = "scenes/" + sceneName; int pos = texPath.rfind('/'); if(pos == string::npos) texPath = ""; else texPath.resize(pos + 1); } float sceneScale = 1.0f; Vec3f sceneCenter(0, 0, 0); GLWindow window(resx, resy, fullscreen); window.SetTitle("Volume viewer v 0.002"); Font font; bool lightsEnabled = 1; bool staticEnabled = 0, orbiting = true; float speed = 10.0f; { VolumeData volume; volume.LoadDicom(sceneName.c_str()); sceneCenter = Vec3f(volume.width, volume.height, volume.depth) * 0.5f; sceneScale = Length(sceneCenter) * 2.0f; printf("\nUploading data (%d, %d, %d) to GPU: ", volume.width, volume.height, volume.depth); fflush(stdout); double uploadTime = GetTime(); uploadTime = GetTime() - uploadTime; Load3dTexture(volume); printf("%.2f msec\n", uploadTime * 1000.0); } FPSCamera cam; if(!camConfigs.GetConfig(string(sceneName),cam)) cam.SetPos(sceneCenter); OrbitingCamera ocam; ocam.Reset(sceneCenter, sceneScale); FrameCounter frmCounter; float lastFrameTime = 0.0f; double lastTime = GetTime(); while(window.PollEvents()) { frmCounter.NextFrame(); if(window.KeyUp(Key_esc)) break; if(window.KeyDown('C')) { if(orbiting) ocam.Reset(sceneCenter, sceneScale); else cam.SetPos(sceneCenter); cam.ang = 0; cam.pitch = 0; } if(window.KeyDown('P')) { camConfigs.AddConfig(string(sceneName),cam); Saver("cameras.dat") & camConfigs; cam.Print(); } if(window.KeyDown('O')) { if(orbiting) cam.SetPos(ocam.pos); else ocam.Reset(cam.pos, -sceneScale); orbiting ^= 1; printf("Orbiting: %s\n", orbiting? "true" : "false"); } if(window.KeyDown('P')) { camConfigs.AddConfig(string(sceneName),cam); Saver("scenes/cameras.dat") & camConfigs; cam.Print(); } float tspeed = speed * lastFrameTime * 20.0f; lastFrameTime = GetTime() - lastTime; lastTime = GetTime(); if(orbiting) MoveCamera(ocam, window, tspeed); else MoveCamera(cam, window, tspeed); for(int n = 1; n <= 8; n++) if(window.KeyDown('0' + n)) { threads = n; printf("Threads: %d\n", threads); } if(window.KeyDown(Key_f1)) nPlanes *= 2; if(window.KeyDown(Key_f2)) nPlanes /= 2; if(window.KeyDown(Key_f2)) { gVals[1]^=1; printf("Val 1 %s\n", gVals[1]?"on" : "off"); } if(window.KeyDown(Key_f3)) { gVals[2]^=1; printf("Val 2 %s\n", gVals[2]?"on" : "off"); } if(window.KeyDown(Key_f4)) { gVals[3]^=1; printf("Photons visible %s\n", gVals[3]?"on" : "off"); } if(window.KeyDown(Key_f5)) { gVals[4]^=1; printf("Photon tracing %s\n", gVals[4]?"on" : "off"); } if(window.KeyDown(Key_f6)) { gVals[5]^=1; printf("Scene complexity visualization %s\n",gVals[5]?"on":"off"); } if(window.KeyDown(Key_f7)) { gVals[6]^=1; printf("Advanced shading %s\n",gVals[6]?"on":"off"); } if(window.KeyDown(Key_f8)) { gVals[7]^=1; printf("Reflections 7 %s\n",gVals[7]?"on":"off"); } if(window.KeyDown(Key_f9)) { gVals[8]^=1; printf("Node tasks visualization 8 %s\n",gVals[8]?"on":"off"); } if(window.KeyDown(Key_f10)) { gVals[9]^=1; printf("Antialiasing 4x %s\n",gVals[9]?"on":"off"); } if(window.KeyDown(Key_f1)) { gVals[0]^=1; printf("Traversing from 8x8: %s\n", gVals[0]?"on" : "off"); } nPlanes = Clamp(nPlanes, 16, 2048); static float animPos = 0; if(window.Key(Key_space)) animPos+=0.025f; double time = GetTime(); Camera camera = orbiting?(Camera)ocam : (Camera)cam; time = GetTime() - time; RenderVolume(camera, float(resx) / resy, nPlanes); double fps = double(unsigned(frmCounter.FPS() * 100)) * 0.01; font.BeginDrawing(resx,resy); font.SetSize(Vec2f(30, 20)); font.PrintAt(Vec2f(5, 25), "FPS: ", fps, " Planes: ", nPlanes); font.FinishDrawing(); window.SwapBuffers(); } return 0; }
void TestScene::load() { //load skybox TextureCB* skybox = dynamic_cast<TextureCB*>(DDSLoader::loadDDSTex( "Assets\\skybox\\sbrightmip.dds", "Assets\\skybox\\sbleftmip.dds", "Assets\\skybox\\sbupmip.dds", "Assets\\skybox\\sbdownmip.dds", "Assets\\skybox\\sbbackmip.dds", "Assets\\skybox\\sbfrontmip.dds")); if (skybox != nullptr) addCubeMap(skybox); //load testmodel "uglypot" std::list<Model*> models = OBJLoader::loadOBJ("Assets\\Models\\uglypot.obj"); Texture2D* wooddiff = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\wooddiff_RGBA32UI.dds")); Texture2D* woodspec = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodspec_RGBA32UI.dds")); Texture2D* woodgloss = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodgloss_RGBA32UI.dds")); Texture2D* woodnormal = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodnormal_RGBA32UI.dds")); Texture2D* woodheight = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\woodheight_RGBA32UI.dds")); Texture2D* metaldiff = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metaldiff_RGBA32UI.dds")); Texture2D* metalspec = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalspec_RGBA32UI.dds")); Texture2D* metalgloss = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalgloss_RGBA32UI.dds")); Texture2D* metalnormal = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalnormal_RGBA32UI.dds")); Texture2D* metalheight = dynamic_cast<Texture2D*>(DDSLoader::loadDDSTex("Assets\\Materials\\metalheight_RGBA32UI.dds")); //this thing will be forward shaded ForwardShader* forward = new ForwardShader(); forward->load("BaseVertex.vert", "BaseFrag.frag"); addShader(forward); addTexture(wooddiff); addTexture(woodspec); addTexture(woodgloss); addTexture(woodnormal); addTexture(woodheight); addTexture(metaldiff); addTexture(metalspec); addTexture(metalgloss); addTexture(metalnormal); addTexture(metalheight); //load wood and metal material Material* wood = new Material(); wood->addTexture(wooddiff); wood->addTexture(woodspec); wood->addTexture(woodgloss); wood->addTexture(woodnormal); wood->addTexture(woodheight); wood->setShader(forward); Material* metal = new Material(); metal->addTexture(metaldiff); metal->addTexture(metalspec); metal->addTexture(metalgloss); metal->addTexture(metalnormal); metal->addTexture(metalheight); metal->setShader(forward); addMaterial(wood); addMaterial(metal); std::list<Model*>::iterator moit = models.begin(); std::vector<Mesh*>::iterator mshit = (*moit)->getMeshes().begin(); //2 submeshes (*mshit++)->setMaterial(wood); (*mshit)->setMaterial(metal); m_models.splice(end(m_models), models); //create an instance of this model and add it to the scene gameobjects RenderableGameObject* go = new RenderableGameObject(); go->setModel(*moit); go->getTransform().setTranslate(glm::vec3(0.0f, 0.0f, -2.0f)); addRenderable(go); //create a directional light DirectionalLight* dirlight = new DirectionalLight(glm::vec3(1.0f, -1.0f, -1.0f), Transform(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f)), glm::vec4(1.0f, 1.0f, 0.8f, 1.0f)); addDirectionalLight(dirlight); PointLight* pointlight = new PointLight(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), Transform(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f)), 1.0f, 0.7f, 1.8f, 7.0f); addPointLight(pointlight); //create a flycam FPSCamera* cam = new FPSCamera(45.0f, 800, 600, 0.1f, 100.0f, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f)); cam->Fly(true); cam->recalcProj(); m_camera = cam; int dummy = 0; }