| 
							- //
 - // Copyright (c) 2013 Mikko Mononen memon@inside.org
 - //
 - // This software is provided 'as-is', without any express or implied
 - // warranty.  In no event will the authors be held liable for any damages
 - // arising from the use of this software.
 - // Permission is granted to anyone to use this software for any purpose,
 - // including commercial applications, and to alter it and redistribute it
 - // freely, subject to the following restrictions:
 - // 1. The origin of this software must not be misrepresented; you must not
 - //    claim that you wrote the original software. If you use this software
 - //    in a product, an acknowledgment in the product documentation would be
 - //    appreciated but is not required.
 - // 2. Altered source versions must be plainly marked as such, and must not be
 - //    misrepresented as being the original software.
 - // 3. This notice may not be removed or altered from any source distribution.
 - //
 - 
 - #include <stdio.h>
 - #ifdef NANOVG_GLEW
 - #	include <GL/glew.h>
 - #endif
 - #define GLFW_NO_GLU
 - #define GLFW_INCLUDE_GLCOREARB
 - #include <GLFW/glfw3.h>
 - #include "nanovg.h"
 - #define NANOVG_GL3_IMPLEMENTATION
 - #include "nanovg_gl3.h"
 - #include "demo.h"
 - 
 - 
 - void errorcb(int error, const char* desc)
 - {
 - 	printf("GLFW error: %s\n", desc);
 - }
 - 
 - int blowup = 0;
 - 
 - static void key(GLFWwindow* window, int key, int scancode, int action, int mods)
 - {
 - 	if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
 - 		glfwSetWindowShouldClose(window, GL_TRUE);
 - 	if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
 - 		blowup = !blowup;
 - }
 - 
 - int main()
 - {
 - 	GLFWwindow* window;
 - 	struct DemoData data;
 - 	struct NVGcontext* vg = NULL;
 - 	struct FPScounter fps;
 - 	double prevt = 0;
 - 
 - 	if (!glfwInit()) {
 - 		printf("Failed to init GLFW.");
 - 		return -1;
 - 	}
 - 
 - 	initFPS(&fps);
 - 
 - 	glfwSetErrorCallback(errorcb);
 - 
 - 	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
 - 	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
 -     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
 -     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
 - #ifdef DEMO_MSAA
 - 	glfwWindowHint(GLFW_SAMPLES, 4);
 - #endif
 - 
 - 	window = glfwCreateWindow(1000, 600, "NanoVG", NULL, NULL);
 - //	window = glfwCreateWindow(1000, 600, "NanoVG", glfwGetPrimaryMonitor(), NULL);
 - 	if (!window) {
 - 		glfwTerminate();
 - 		return -1;
 - 	}
 - 
 - 	glfwSetKeyCallback(window, key);
 - 
 - 	glfwMakeContextCurrent(window);
 - #ifdef NANOVG_GLEW
 - 	glewExperimental = GL_TRUE;
 -     if(glewInit() != GLEW_OK) {
 - 		printf("Could not init glew.\n");
 - 		return -1;
 - 	}
 - #endif
 - 
 - #ifdef DEMO_MSAA
 - 	vg = nvgCreateGL3(512, 512, 0);
 - #else
 - 	vg = nvgCreateGL3(512, 512, NVG_ANTIALIAS);
 - #endif
 - 	if (vg == NULL) {
 - 		printf("Could not init nanovg.\n");
 - 		return -1;
 - 	}
 - 
 - 	if (loadDemoData(vg, &data) == -1)
 - 		return -1;
 - 
 - 	glfwSwapInterval(0);
 - 
 - 	glfwSetTime(0);
 - 	prevt = glfwGetTime();
 - 
 - 	while (!glfwWindowShouldClose(window))
 - 	{
 - 		double mx, my, t, dt;
 - 		int width, height;
 - 
 - 		t = glfwGetTime();
 - 		dt = t - prevt;
 - 		prevt = t;
 - 		updateFPS(&fps, dt);
 - 
 - 		glfwGetCursorPos(window, &mx, &my);
 - 		glfwGetFramebufferSize(window, &width, &height);
 - 
 - 		// Update and render
 - 		glViewport(0, 0, width, height);
 - 		glClearColor(0.3f, 0.3f, 0.32f, 1.0f);
 - 		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
 - 		glEnable(GL_BLEND);
 - 		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 - 		glEnable(GL_CULL_FACE);
 - 		glDisable(GL_DEPTH_TEST);
 - 
 - 		nvgBeginFrame(vg, width, height);
 - 
 - 		renderDemo(vg, mx,my, width,height, t, blowup, &data);
 - 		renderFPS(vg, 5,5, &fps);
 - 
 - 		glEnable(GL_DEPTH_TEST);
 - 
 - 		glfwSwapBuffers(window);
 - 		glfwPollEvents();
 - 	}
 - 
 - 	freeDemoData(vg, &data);
 - 
 - 	nvgDeleteGL3(vg);
 - 
 - 	glfwTerminate();
 - 	return 0;
 - }
 
 
  |