/** * Class constructor, set window properties from Configuration object and init SDL and OpenGL widnow. * @param configuration is pointer to Configuration class. */ WindowManager::WindowManager() { windowCaption ="Kernel Panic"; initializeSDL(); Configuration* config = Configuration::getInstance(); _putenv(_strdup("SDL_VIDEO_CENTERED=1")); if (!config->getFullscreen()) windowScreen = SDL_SetVideoMode(config->getWidth(), config->getHeight(), config->getColorDepth(), SDL_OPENGL| SDL_DOUBLEBUF | SDL_HWSURFACE); else windowScreen = SDL_SetVideoMode(config->getWidth(), config->getHeight(), config->getColorDepth(), SDL_OPENGL | SDL_FULLSCREEN); if(!windowScreen) { printf("Video set mode failed: %s\n", SDL_GetError()); exit(0); } SDL_WM_SetCaption(windowCaption.c_str(), NULL); //SDL_WM_GrabInput(SDL_GRAB_ON); resizeOpenGL(config->getWidth(),config->getHeight()); initializeOpenGL(); }
Engine::Engine(const std::string& title, int screenWidth, int screenHeight, bool screenFull) : m_titile(title) , m_screenWidth(screenWidth) , m_screenHeight(screenHeight) , m_screenFull(screenFull) , m_appActive(true) , m_mouseFocus(true) , m_inputFocus(true) , m_translate_x(0.0f) , m_translate_y(0.0f) , m_translate_z(0.0f) , m_scale(SCALE) , m_game(0) { try { initializeSDL(); initializeOpenGL(); SDL_WM_SetCaption(title.c_str(), title.c_str()); } catch (EngineError e) { SDL_Quit(); throw e; } // Mark all keys as not pressed for (int i = 0; i < SDLK_LAST; ++i) { m_keys[i] = false; } new ResourceMgr; // Required by GUI SDL_EnableUNICODE(1); new GuiMgr; }
SDLWindow::SDLWindow(Parameters& parameters) : AbstractWindow(parameters) { initializeSDL(); //initializeSDLimage(); //initializeSDLttf(); initializeOpenGL(); m_renderer->initialize(); // Called here after the context is created. }
/** * Method is used to initialize and configure engine context. */ void ContextManager::initializeContextManager() { initializeContext(); resizeWindow(resolutionWidth, resolutionHeight); initializeOpenGL(); contextWindow->setActive(); sf::Mouse::setPosition(sf::Vector2i(resolutionWidth/2,resolutionHeight/2),*contextWindow); contextWindow->setMouseCursorVisible(false); }
bool Display::initialize() { m_pGLPlatform = GLPlatform::create(); if (NULL == m_pGLPlatform) { return false; } if (false == initializeOpenGL()) { return false; } return true; }
SelectionPointer::SelectionPointer(Drawer *drawer) : QObject(0), m_labelShader(0), m_pointShader(0), m_labelObj(0), m_pointObj(0), m_textureHelper(0), m_cachedTheme(drawer->theme()), m_labelBackground(false), m_drawer(drawer), m_cachedScene(0) { initializeOpenGL(); QObject::connect(m_drawer, &Drawer::drawerChanged, this, &SelectionPointer::handleDrawerChange); }
bool GameScreen::initializeScreen() { if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 ) { return false; } if( !initializeSDLGLState() ) { return false; } SDL_putenv("SDL_VIDEO_CENTERED=center"); width = 1280; height = 720; if( (screen = SDL_SetVideoMode(width, height, 32, SDL_OPENGL /*| SDL_FULLSCREEN*/) ) == NULL) { return false; } initializeSDLFeatures(); if( !initializeOpenGL() ) { return false; } if ( TTF_Init() < 0 ) { return false; } SDL_WM_SetCaption( windowName.c_str(), NULL ); return true; }
void RotationsViewer::init(int argc, char** argv, int winwidth, int winheight, int winstartx, int winstarty) { mWindowWidth = winwidth; mWindowHeight = winheight; theInstance = this; glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(winwidth, winheight); glutInitWindowPosition(winstartx, winstarty); glutCreateWindow("Basic Viewer"); const bool lSupportVBO = initializeOpenGL(); glutDisplayFunc(RotationsViewer::onDrawCb); glutKeyboardFunc(RotationsViewer::onKeyboardCb); glutSpecialFunc(RotationsViewer::onKeyboardSpecialCb); glutMouseFunc(RotationsViewer::onMouseCb); glutMotionFunc(RotationsViewer::onMouseMotionCb); glutReshapeFunc(RotationsViewer::onResizeCb); glutTimerFunc(100, RotationsViewer::onTimerCb, 0); initializeGui(); }
int main (int argc, char* argv[]) { srand (static_cast<unsigned>(time(0))); // Magic glewExperimental = GL_TRUE; // Init GLEW and GLFW if(initializeOpenGL() == -1) { return -1; } scene = new Scene(); utilHandler = new Utils(); createPreDefinedVoronoiPoints(); scene->setPreComputedVoronoiPoints(sVoronoiPoints); // Create geometries and add them to the scene // Floor floor_rect = new Rectangle(1.0f, 1.0f, Vector3<float>(0.0f, 0.0f, 0.0f)); floor_rect->rotate(Vector3<float>(1.0f, 0.0f, 0.0f), 90.0f); floor_rect->scale(Vector3<float>(2.5f, 1.0f, 2.0f)); floor_rect->translate(Vector3<float>(0.0f, -0.35f, 0.0f)); // HalfEdge mesh mesh = new HalfEdgeMesh(Vector4<float>(0.2f, 0.8f, 0.2f, 0.4f)); mesh->addVoronoiPoint(Vector3<float>(0.0f, 0.0f, 0.0f)); mesh->setDebugMode(true); // The following meshes has pre-defined voronoi patterns //mesh->createMesh("pillar"); //mesh->createMesh("icosphere"); //mesh->createMesh("bunnySmall_reduced"); //mesh->createMesh("cube"); mesh->createMesh("cow_2"); mesh->markCurrentVoronoiPoint(currentVoronoiIndex, Vector4<float>(1.0f, 1.0f, 1.0f, 1.0f)); scene->addGeometry(floor_rect, STATIC); scene->addGeometry(mesh, STATIC); initializeScene(); //Set functions to handle mouse input glfwSetMouseButtonCallback(window, mouseButton); glfwSetCursorPosCallback(window, mouseMotion); glfwSetScrollCallback(window, mouseScroll); glfwSetKeyCallback(window, keyboardInput); // render-loop do { calcFPS(1.0, windowTitle); // Clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // render all geometries scene->render(); scene->stepSimulation(); // Swap buffers glfwSwapBuffers(window); glfwPollEvents(); } // Check if the ESC key was pressed or the window was closed while ( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0 ); // Clean-up delete scene; // Close OpenGL window and terminate GLFW glfwTerminate(); return 0; }
int main() { srand(time(0)); // magic glewExperimental = GL_TRUE; // Init GLEW and GLFW if(initializeOpenGL() == -1) return -1; // Create scene here. scene = new Scene(); geometry = new Geometry(); geometry->loadObject("bunny"); //geometry->loadObject("cube"); geometry->translate(glm::vec3(.5f, -.5f, 0.0f)); scene->addGeometry(geometry); //scene->addGeometry(geometry2); scene->initialize(); //init nanogui if(!initGUI() ) return false; //set mouse handlers glfwSetMouseButtonCallback(window, mouseButton); glfwSetCursorPosCallback(window, mouseMotion); glfwSetScrollCallback(window, mouseScroll); glfwSetKeyCallback(window, keyCallback); glfwSetCharCallback(window, charCallback); // render-loop do { calculateFPS(1.0, windowTitle); // Clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); scene->getGeometryAt(currentObj)->setColor(glm::vec4(cWheel->color().r(), cWheel->color().g(), cWheel->color().b(), aSlider->value())); scene->setLightColor(glm::vec3(lWheel->color().r(), lWheel->color().g(), lWheel->color().b())); // render scene scene->render(); screen->drawWidgets(); // Swap buffers glfwSwapBuffers(window); glfwPollEvents(); } // Check if the ESC key was pressed or the window was closed while ( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0 ); //deallocate nanogui -> call for all ~() nanogui::shutdown(); // Close OpenGL window and terminate GLFW glfwTerminate(); return EXIT_SUCCESS; }
int main() { // Magic glewExperimental = GL_TRUE; // Init GLEW and GLFW if(initializeOpenGL() == -1) { return -1; } // Create scene here. scene = new Scene(); loadGeometryData(); std::cout << "\nPre-processing...\n" << std::endl; torus = new Geometry(geometryData["torus"], glm::vec3(0.5f, 0.4f, 0.3f), 24, 0.15f); sphere = new Geometry(geometryData["sphere"], glm::vec3(0.5f, 0.4f, 0.3f), 24, 0.15f, false); plane = new Geometry(geometryData["plane"], glm::vec3(0.5f, 0.4f, 0.3f), 24, 0.15f, false); monkey = new Geometry(geometryData["monkey"], glm::vec3(0.5f, 0.4f, 0.3f), 24, 0.15f, false); bunny = new Geometry(geometryData["bunny"], glm::vec3(0.5f, 0.4f, 0.3f), 24, 0.15f, false); teapot = new Geometry(geometryData["teapot"], glm::vec3(0.5f, 0.4f, 0.3f), 24, 0.15f, false); scene->addGeometry(torus); scene->addGeometry(sphere); scene->addGeometry(plane); scene->addGeometry(monkey); scene->addGeometry(bunny); scene->addGeometry(teapot); scene->addShaderPair("shaders/phongvertexshader.glsl", "shaders/phongfragmentshader.glsl"); scene->addShaderPair("shaders/furvertexshader.glsl", "shaders/furfragmentshader.glsl"); // Initialize scene scene->initialize(); mesh = torus; // Initialze AntTweakBar initializeAntTweakBar(); std::cout << "\nPre-processing complete!" << std::endl; // Bind mouse and keyboard callback functions glfwSetMouseButtonCallback(window, mouseButton); glfwSetCursorPosCallback(window, mouseMotion); glfwSetScrollCallback(window, mouseScroll); glfwSetKeyCallback(window, keyboardInput); float time, previousTime = 0; // Render-loop do { calculateFPS(1.0, windowTitle); // Clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); time = static_cast<float>(glfwGetTime()); scene->update(time - previousTime); scene->setCurrentTime(time); updateTweakBarVariables(); previousTime = time; // Render scene scene->render(); // Render AntTweakBar TwDraw(); // Swap buffers glfwSwapBuffers(window); glfwPollEvents(); } // Check if the ESC key was pressed or the window was closed while ( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0 ); // Clean-up delete scene; // Uninitialize AntTweakBar TwTerminate(); // Close OpenGL window and terminate GLFW glfwTerminate(); return EXIT_SUCCESS; }