void App::onInit() { setScene(Scene::create()); logPrintf("App::onInit()\n"); createDeveloperHUD(); showRenderingStats = false; developerWindow->cameraControlWindow->setVisible(false); developerWindow->setVisible(false); developerWindow->videoRecordDialog->setCaptureGui(false); m_debugCamera->filmSettings().setAntialiasingEnabled(true); if (filename != "") { window()->setCaption(filenameBaseExt(filename) + " - G3D Viewer"); } lighting = shared_ptr<LocalLightingEnvironment>(new LocalLightingEnvironment()); lighting->lightArray.clear(); // The spot light is designed to just barely fit the 3D models. Note that it has no attenuation lighting->lightArray.append(Light::spotTarget("Light", Point3(20, 200, 20), Point3::zero(), 8 * units::degrees(), Power3(25.0f), 1, 0, 0, true, 8192)); lighting->environmentMapArray.append(ScaledTexture(Texture::fromFile(System::findDataFile("uffizi/uffizi*.jpg"), ImageFormat::SRGB8(), Texture::DIM_CUBE_MAP, Texture::Settings::cubeMap()), 0.65f)); lighting->ambientOcclusionSettings.numSamples = 24; // High-quality AO lighting->ambientOcclusionSettings.radius = 1.6f * units::meters(); lighting->ambientOcclusionSettings.intensity = 1.0f; lighting->ambientOcclusionSettings.bias = 0.002f * units::meters(); m_debugCamera->setFarPlaneZ(-1000); m_debugCamera->setNearPlaneZ(-0.05f); // Don't clip to the near plane glDisable(GL_DEPTH_CLAMP); colorClear = Color3::white() * 0.9f; //modelController = ThirdPersonManipulator::create(); setViewer(filename); logPrintf("Done App::onInit()\n"); }
void App::onInit() { GApp::onInit(); renderDevice->setSwapBuffersAutomatically(true); logPrintf("App::onInit()\n"); createDeveloperHUD(); showRenderingStats = false; developerWindow->cameraControlWindow->setVisible(false); developerWindow->setVisible(false); developerWindow->videoRecordDialog->setCaptureGui(false); m_debugCamera->filmSettings().setBloomStrength(0.20f); m_debugCamera->filmSettings().setBloomRadiusFraction(0.017f); m_debugCamera->filmSettings().setAntialiasingEnabled(true); m_debugCamera->filmSettings().setCelluloidToneCurve(); if (! filename.empty()) { window()->setCaption(filenameBaseExt(filename) + " - G3D Viewer"); } lighting = shared_ptr<LightingEnvironment>(new LightingEnvironment()); lighting->lightArray.clear(); // The spot light is designed to just barely fit the 3D models. Note that it has no attenuation lighting->lightArray.append(Light::spotTarget("Light", Point3(40, 120, 80), Point3::zero(), 10 * units::degrees(), Power3(50.0f), 1, 0, 0, true, 8192)); lighting->lightArray.last()->shadowMap()->setBias(0.1f); Texture::Encoding e; e.readMultiplyFirst = Color4(Color3(0.5f)); e.format = ImageFormat::RGB32F(); lighting->environmentMapArray.append(Texture::fromFile(System::findDataFile("uffizi/uffizi-*.exr"), e, Texture::DIM_CUBE_MAP)); lighting->ambientOcclusionSettings.numSamples = 24; lighting->ambientOcclusionSettings.radius = 0.75f * units::meters(); lighting->ambientOcclusionSettings.intensity = 2.0f; lighting->ambientOcclusionSettings.bias = 0.06f * units::meters(); lighting->ambientOcclusionSettings.useDepthPeelBuffer = true; m_debugCamera->setFarPlaneZ(-finf()); m_debugCamera->setNearPlaneZ(-0.05f); // Don't clip to the near plane glDisable(GL_DEPTH_CLAMP); colorClear = Color3::white() * 0.9f; //modelController = ThirdPersonManipulator::create(); m_gbufferSpecification.encoding[GBuffer::Field::CS_POSITION_CHANGE].format = NULL; gbuffer()->setSpecification(m_gbufferSpecification); setViewer(filename); developerWindow->sceneEditorWindow->setVisible(false); logPrintf("Done App::onInit()\n"); }
void App::onInit() { showRenderingStats = false; window()->setCaption(filenameBaseExt(filename) + " - G3D Viewer"); sky = Sky::fromFile(System::findDataFile("sky")); skyParameters = SkyParameters( G3D::toSeconds(10, 00, 00, AM) ); lighting = Lighting::fromSky( sky, skyParameters, Color3::white() ); lighting->ambientTop = Color3::white() * 0.3f; lighting->ambientBottom = Color3::white() * 0.1f; colorClear = Color3::white(); //modelController = ThirdPersonManipulator::create(); setViewer(filename); }
shared_ptr<GFont> GFont::fromFile(const String& filename) { if (! FileSystem::exists(filename)) { debugAssertM(false, format("Could not load font: %s", filename.c_str())); return shared_ptr<GFont>(); } String key = filenameBaseExt(filename); shared_ptr<GFont> font = _internal::fontCache()[key]; if (isNull(font)) { BinaryInput b(filename, G3D_LITTLE_ENDIAN, true); font.reset(new GFont(filename, b)); _internal::fontCache().set(key, font); } return font; }
int main(int argc, char** argv) { // Argument parsing if ((argc == 1) || ((argc >= 2) && (std::string("--help") == argv[1]))) { printHelp(); return 0; } if ((argc == 2) && (std::string("--version") == argv[1])) { printVersion(); return 0; } std::string src = ""; std::string dst = ""; // Figure out source and dest filenames if (argc >= 4) { if (std::string("-o") != argv[1]) { printf("Invalid command line to GLSLCheck. Expected '-o' or" " filename as 1st argument, found: '%s'\n", argv[1]); return -1; } dst = argv[2]; src = argv[3]; } else { src = argv[1]; } if (! fileExists(src)) { printf("GLSLCheck error : input file '%s' not found\n", src.c_str()); return -4; } if (endsWith(dst, "/") || endsWith(dst, "\\")) { if (! fileExists(dst.substr(0, dst.size() - 1))) { printf("GLSLCheck error : output directory '%s' not found\n", dst.c_str()); return -5; } // Add the filename part of src to dst, since dst is a directory dst = dst + filenameBaseExt(src); } Mode mode; if (endsWith(toLower(src), ".vert")) { mode = VERTEX; } else if (endsWith(toLower(src), ".frag")) { mode = FRAGMENT; } else { printf("Invalid filename; source file must end with .vert or .frag\n"); return -2; } // We must create a GL context before loading extensions. GWindowSettings settings; settings.visible = false; settings.width = 200; settings.height = 200; GWindow* window; #ifdef G3D_WIN32 window = new Win32Window(settings); #else window = new SDLWindow(settings); #endif GLCaps::loadExtensions(); if (! VertexAndPixelShader::fullySupported()) { printf("GLSL not supported by your graphics card and driver.\n"); return -3; } int result = check(mode, src); if ((result == 0) && (dst != "")) { copyFile(src, dst); } delete window; return result; }
void App::setViewer(const G3D::String& newFilename) { logPrintf("App::setViewer(\"%s\")\n", filename.c_str()); drawMessage("Loading " + newFilename); filename = newFilename; m_debugCamera->setFrame(CFrame::fromXYZYPRDegrees(-11.8f, 25.2f, 31.8f, -23.5f, -39.0f, 0.0f)); m_debugController->setFrame(m_debugCamera->frame()); //modelController->setFrame(CoordinateFrame(Matrix3::fromAxisAngle(Vector3(0,1,0), toRadians(180)))); delete viewer; viewer = NULL; if (filename == "<events>") { viewer = new EventViewer(); } else { G3D::String ext = toLower(filenameExt(filename)); G3D::String base = toLower(filenameBase(filename)); if ((ext == "3ds") || (ext == "ifs") || (ext == "obj") || (ext == "ply2") || (ext == "off") || (ext == "ply") || (ext == "bsp") || (ext == "stl") || (ext == "lwo") || (ext == "stla") || (ext == "dae") || (ext == "fbx") || (ext == "any" && endsWith(base, ".material")) || (ext == "any" && endsWith(base, ".universalmaterial")) || ((ext == "any" && endsWith(base, ".am")) || (ext == "any" && endsWith(base, ".articulatedmodel")))) { showDebugText = false; viewer = new ArticulatedViewer(); } else if (Texture::isSupportedImage(filename)) { // Images can be either a Texture or a Sky, TextureViewer will figure it out viewer = new TextureViewer(); // Angle the camera slightly so a sky/cube map doesn't see only 1 face m_debugController->setFrame(Matrix3::fromAxisAngle(Vector3::unitY(), (float)halfPi() / 2.0f) * Matrix3::fromAxisAngle(Vector3::unitX(), (float)halfPi() / 2.0f)); } else if (ext == "fnt") { viewer = new FontViewer(debugFont); /* } else if (ext == "bsp") { viewer = new BSPViewer(); */ } else if (ext == "md2") { viewer = new MD2Viewer(); } else if (ext == "md3") { viewer = new MD3Viewer(); } else if (ext == "gtm") { viewer = new GUIViewer(this); } else if (ext == "icn") { viewer = new IconSetViewer(debugFont); } else if (ext == "pk3") { // Something in Quake format - figure out what we should load Array <String> files; bool set = false; // First, try for a .bsp map G3D::String search = filename + "/maps/*"; FileSystem::getFiles(search, files, true); for (int t = 0; t < files.length(); ++t) { if (filenameExt(files[t]) == "bsp") { filename = files[t]; viewer = new ArticulatedViewer(); set = true; } } if (! set) { viewer = new EmptyViewer(); } } else if (ext == "avi" || ext == "wmv" || ext == "mp4" || ext == "asf" || (ext == "mov") || (ext == "dv") || (ext == "qt") || (ext == "asf") || (ext == "mpg")) { viewer = new VideoViewer(); } else { viewer = new EmptyViewer(); } } if (viewer != NULL) { viewer->onInit(filename); } if (filename != "") { if (filename == "<events>") { window()->setCaption("Events - G3D Viewer"); } else { window()->setCaption(filenameBaseExt(filename) + " - G3D Viewer"); } } logPrintf("Done App::setViewer(...)\n"); }
bool CameraControlWindow::onEvent(const GEvent& event) { // Allow super class to process the event if (GuiWindow::onEvent(event)) { return true; } // Accelerator key for toggling camera control. Active even when the window is hidden. if ((event.type == GEventType::KEY_DOWN) && (event.key.keysym.sym == GKey::F2)) { manualOperation = ! manualOperation; sync(); return true; } if (! visible()) { return false; } // Special buttons if (event.type == GEventType::GUI_ACTION) { GuiControl* control = event.gui.control; if (control == drawerButton) { // Change the window size m_expanded = ! m_expanded; morphTo(Rect2D::xywh(rect().x0y0(), m_expanded ? bigSize : smallSize)); drawerButton->setCaption(m_expanded ? drawerCollapseCaption : drawerExpandCaption); } else if (control == trackList) { if (trackFileArray[trackFileIndex] != untitled) { // Load the new spline loadSpline(trackFileArray[trackFileIndex] + ".trk"); // When we load, we lose our temporarily recorded spline, // so remove that display from the menu. if (trackFileArray.last() == untitled) { trackFileArray.remove(trackFileArray.size() - 1); } } } else if (control == playButton) { // Take over manual operation manualOperation = true; // Restart at the beginning of the path trackManipulator->setTime(0); } else if ((control == recordButton) || (control == cameraLocationTextBox)) { // Take over manual operation and reset the recording manualOperation = true; trackManipulator->clear(); trackManipulator->setTime(0); // Select the untitled path if ((trackFileArray.size() == 0) || (trackFileArray.last() != untitled)) { trackFileArray.append(untitled); } trackFileIndex = trackFileArray.size() - 1; saveButton->setEnabled(true); } else if (control == saveButton) { // Save std::string saveName; if (_internal::SaveDialog::getFilename(saveName, this)) { saveName = filenameBaseExt(trimWhitespace(saveName)); if (saveName != "") { saveName = saveName.substr(0, saveName.length() - filenameExt(saveName).length()); BinaryOutput b(saveName + ".trk", G3D_LITTLE_ENDIAN); trackManipulator->spline().serialize(b); b.commit(); updateTrackFiles(); // Select the one we just saved trackFileIndex = iMax(0, trackFileArray.findIndex(saveName)); saveButton->setEnabled(false); } } } sync(); } else if (trackManipulator->mode() == UprightSplineManipulator::RECORD_KEY_MODE) { // Check if the user has added a point yet sync(); } return false; }
void App::setViewer(const std::string& newFilename) { filename = newFilename; defaultCamera.setCoordinateFrame(CoordinateFrame(Vector3(0,0,5))); defaultController->setFrame(CoordinateFrame(Vector3(0,0,5))); //modelController->setFrame(CoordinateFrame(Matrix3::fromAxisAngle(Vector3(0,1,0), toRadians(180)))); delete viewer; viewer = NULL; shadowMap->setSize(0); std::string ext = toLower(filenameExt(filename)); std::string base = toLower(filenameBase(filename)); if ((ext == "3ds") || (ext == "ifs") || (ext == "obj") || (ext == "ply2") || (ext == "off") || (ext == "ply") || (ext == "any" && endsWith(base, ".am"))) { shadowMap->setSize(2048); viewer = new ArticulatedViewer(); } else if (Texture::isSupportedImage(filename)) { // Images can be either a Texture or a Sky, TextureViewer will figure it out viewer = new TextureViewer(); // Angle the camera slightly so a sky/cube map doesn't see only 1 face defaultController->setFrame(Matrix3::fromAxisAngle(Vector3::unitY(), halfPi() / 2.0) * Matrix3::fromAxisAngle(Vector3::unitX(), halfPi() / 2.0)); } else if (ext == "fnt") { viewer = new FontViewer(debugFont); } else if (ext == "bsp") { viewer = new BSPViewer(); } else if (ext == "md2") { viewer = new MD2Viewer(); } else if (ext == "gtm") { viewer = new GUIViewer(this); } else if (ext == "icn") { viewer = new IconSetViewer(debugFont); } else if (ext == "pk3") { // Something in Quake format - figure out what we should load Array <std::string> files; bool set = false; // First, try for a .bsp map std::string search = filename + "/maps/*"; FileSystem::getFiles(search, files, true); for (int t = 0; t < files.length(); ++t) { if (filenameExt(files[t]) == "bsp") { filename = files[t]; viewer = new BSPViewer(); set = true; } } if (!set) { viewer = new EmptyViewer(); } } else if (ext == "avi" || ext == "wmv" || ext == "mp4" || ext == "asf" || (ext == "mov") || (ext == "dv") || (ext == "qt") || (ext == "asf") || (ext == "mpg")) { viewer = new VideoViewer(); } else { viewer = new EmptyViewer(); } if (viewer != NULL) { viewer->onInit(filename); } window()->setCaption(filenameBaseExt(filename) + " - G3D Viewer"); }