Ejemplo n.º 1
0
    void Timer::update() {
        priv->realTime = SDL_GetTicks();
        priv->frames++;
        if(!priv->paused) {
            priv->dt = priv->time == 0 ? 0 : (priv->realTime - priv->pauseTime) - (priv->time - priv->pauseTime);
            priv->time = priv->realTime;
        }
        countFps();

        for(Timer* timer: priv->timers) {
            timer->update();
        }
    }
Ejemplo n.º 2
0
void OGLApp::v_run()
{	
	app = std::make_shared<OGLApp>(*this);

	std::cout << "Starting GLFW context" << std::endl;
	if (!glfwInit())
	{
		std::cerr << "Failed to initialize GLFW" << std::endl;
		return;
	}
	sw = WindowInfo::getInstance()->getWidth();
	sh = WindowInfo::getInstance()->getHeight();

	int MonitorCount;
	GLFWmonitor ** monitors = glfwGetMonitors(&MonitorCount);

#ifdef _DEBUG
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, true);
#endif
	//glfwGetPrimaryMonitor(), 
	pWindow = glfwCreateWindow(sw, sh, WindowInfo::getInstance()->getTitle().c_str(), nullptr, nullptr);
	glfwSetWindowPos(pWindow, WindowInfo::getInstance()->getPosX() - 100, WindowInfo::getInstance()->getPosY() - 100);
	glfwMakeContextCurrent(pWindow);

	glfwSetCursorPosCallback(pWindow, glfw_mouse);          // - Directly redirect GLFW mouse position events to AntTweakBar
	glfwSetScrollCallback(pWindow, glfw_scroll);    // - Directly redirect GLFW mouse wheel events to AntTweakBar
	glfwSetKeyCallback(pWindow, glfw_key);                         // - Directly redirect GLFW key events to AntTweakBar
#ifdef USE_ANT
	glfwSetMouseButtonCallback(pWindow, glfw_mouseButton); // - Directly redirect GLFW mouse button events to AntTweakBar
	glfwSetCharCallback(pWindow, glfw_char);                      // - Directly redirect GLFW char events to AntTweakBar
#endif
	glfwSetWindowSizeCallback(pWindow, glfw_resize);


	//glfwSetInputMode(pWindow, GLFW_STICKY_KEYS, GL_TRUE);
	// GLFW Options
    //glfwSetInputMode(pWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);


	if (pWindow == NULL) {
		std::cerr << "Failed to create GLFW pWindow" << std::endl;
		glfwTerminate();
		return;
	}
	glewExperimental = GL_TRUE;

	//Check the GLSL and OpenGL status 
	if (glewInit() != GLEW_OK)
	{
		std::cerr << "Failed to initialize GLEW" << std::endl;
		return;
	}
	const GLubyte *renderer = glGetString(GL_RENDERER);
	const GLubyte *vendor = glGetString(GL_VENDOR);
	const GLubyte *version = glGetString(GL_VERSION);
	const GLubyte *glslVersion = glGetString(GL_SHADING_LANGUAGE_VERSION);

	m_GLRenderer = (const char *)renderer;
	m_GLVersion  = (const char *)version;
	m_GLSLVersion = (const char *)glslVersion;

	GLint major, minor;
	glGetIntegerv(GL_MAJOR_VERSION, &major);
	glGetIntegerv(GL_MINOR_VERSION, &minor);
	std::cout << "GL Vendor    :" << vendor << std::endl;
	std::cout << "GL Renderer  : " << renderer << std::endl;
	std::cout << "GL Version (std::string)  : " << version << std::endl;
	std::cout << "GL Version (integer) : " << major << "." << minor << std::endl;
	std::cout << "GLSL Version : " << glslVersion << std::endl;
	std::cout << "--------------------------------------------------------------------------------"
		<< std::endl;
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);

#ifdef USE_FONT
	m_pFont.init();
#endif
#ifdef USE_CEGUI
	OGLCEGUI::getInstance()->init();
	OGLCEGUI::getInstance()->setupCallbacks(pWindow);
#endif
	v_init();


	while (!glfwWindowShouldClose(pWindow))
	{
		glfwPollEvents();
		v_movement(pWindow);

		countFps();

		static GLfloat lastFrame = static_cast<float>(glfwGetTime());
		GLfloat currentFrame = static_cast<float>(glfwGetTime());
		GLfloat deltaTime = currentFrame - lastFrame;
		lastFrame = currentFrame;

		v_update();
		v_render();

#ifdef USE_FONT
		glDisable(GL_DEPTH_TEST);
		m_pFont.render("Graphics card: " + m_GLRenderer, 10, sh - 40);
		m_pFont.render("GL Version: " + m_GLVersion, 10, sh - 70);
		m_pFont.render("GLSL Version: " + m_GLSLVersion, 10, sh - 100);
		m_pFont.render("FPS: " + std::to_string(m_fps), 10, 30);
		//glEnable(GL_DEPTH_TEST);
#endif

#ifdef USE_CEGUI
		 OGLCEGUI::getInstance()->render();
#endif
		glfwSwapBuffers(pWindow);
	}

	v_shutdown();

	glfwTerminate();
}
Ejemplo n.º 3
0
	void RenderSystem::v_Update()
	{
		countFps();
	}
Ejemplo n.º 4
0
	void RenderSystem::v_Update()
	{
		countFps();

		m_TessTriangle.Update();
	}