Ejemplo n.º 1
0
int main(int argc, char** argv)
{
	
	Model = glm::mat4();;
	View = glm::mat4();
	Projection = glm::mat4();;

	if (!glfwInit())
    exit(EXIT_FAILURE);
	
	glfwWindowHint(GLFW_CLIENT_API,GLFW_OPENGL_API);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,4);
	
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT,GL_TRUE );
	glfwWindowHint(GLFW_OPENGL_PROFILE ,GLFW_OPENGL_CORE_PROFILE);
	
	glfwSetErrorCallback(glfw_error_callback);
	
    GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL);
	
	if (!window)
	{
		glfwTerminate();
		exit(EXIT_FAILURE);
	}
	
	glfwMakeContextCurrent(window);
	
	glfwSetMouseButtonCallback(window, mouse_button_callback);
	glfwSetScrollCallback(window, scroll_callback);
	glfwSetCursorPosCallback(window, cursor_pos_callback);
	
	
	glfwSwapInterval(1);
	pngObject.readPngDepthMap("1341841873.505863.png");
	 
	if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress))
    {
        std::cout << "Failed to initialize OpenGL context" << std::endl;
        return -1;
    }
	
	
	//glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
	glDebugMessageCallback(openglCallbackFunction, NULL);
	GLuint unusedIds = 0;
	glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, &unusedIds, true);
	
	init();
	
	int nbFrames;
	double currentTime = 0;
	double lastTime = 0;
	while (!glfwWindowShouldClose(window)){
	    display();

	    // Measure speed
	    double currentTime = glfwGetTime();
	    nbFrames++;

	    if (currentTime - lastTime >= 1.0) { // If last cout was more than 1 sec ago
	        char title[256];
	        title[255] = '\0';

	        snprintf(title, 255, "FPS: %d", nbFrames);

	        glfwSetWindowTitle(window, title);

	        nbFrames = 0;
	        lastTime += 1.0;
	    }

		glfwSwapBuffers(window);
		glfwPollEvents();

	}
	glfwDestroyWindow(window);
	glfwTerminate();
	
	return 0;
}