Exemplo n.º 1
1
int main(int argc, char **argv)
{
	if (!glfwInit()) {
		printf("Failed to init GLFW.");
		return -1;
	}
	glfwSetErrorCallback(errorcb);
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1);
	GLFWwindow* window = glfwCreateWindow(1024, 768, "scanner", NULL, NULL);
	if (!window) {
		glfwTerminate();
		return -1;
	}
	glfwSetKeyCallback(window, key);
	glfwSetCharCallback(window, charevent);
	glfwSetCursorPosCallback(window, cursorpos);
	glfwSetMouseButtonCallback(window, mousebutton);
	glfwSetScrollCallback(window, scrollevent);
	glfwMakeContextCurrent(window);
	glfwSwapInterval(1); // vsync

	glewExperimental = GL_TRUE;
	if(glewInit() != GLEW_OK) {
		printf("Could not init glew.\n");
		return -1;
	}
	glGetError(); // GLEW generates GL error because it calls glGetString(GL_EXTENSIONS).

	struct NVGcontext* vg = nvgCreateGL2(NVG_ANTIALIAS);
	if (vg == NULL) {
		printf("Could not init nanovg.\n");
		return -1;
	}

	UIcontext *uictx = uiCreateContext(4096, 1 << 20);
	uiMakeCurrent(uictx);
	uiSetHandler(ui_handler);
	uiInit(vg, "oui-blendish/DejaVuSans.ttf", "oui-blendish/blender_icons16.png");

	gui_init(vg);

	glfwSetTime(0);
	while (!glfwWindowShouldClose(window))
	{
		double mx, my;
		glfwGetCursorPos(window, &mx, &my);
		int winWidth, winHeight;
		glfwGetWindowSize(window, &winWidth, &winHeight);
		int fbWidth, fbHeight;
		glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
		float pxRatio = (float)fbWidth / (float)winWidth;

		gui_frame(vg, winWidth, winHeight, pxRatio, glfwGetTime());

		glfwSwapBuffers(window);
		glfwPollEvents();
	}

	gui_quit(vg);

	uiDestroyContext(uictx);
	nvgDeleteGL2(vg);
	glfwTerminate();
	return 0;
}
Exemplo n.º 2
0
void setup()
{
    size(640, 320);
    glfwSetKeyCallback(window, keyevent);
    glfwSetCharCallback(window, charevent);

    uictx = uiCreateContext();
    uiMakeCurrent(uictx);

    bndSetFont(nvgCreateFont(vg, "system", "../3rdparty/blendish/DejaVuSans.ttf"));
    bndSetIconImage(nvgCreateImage(vg, "../3rdparty/blendish/blender_icons16.png", NVG_IMAGE_GENERATE_MIPMAPS));
}
Exemplo n.º 3
0
int main()
{
	GLFWwindow* window;
    UIcontext *uictx;
    
    uictx = uiCreateContext(4096, 1<<20);
    uiMakeCurrent(uictx);
    uiSetHandler(ui_handler);

	if (!glfwInit()) {
		printf("Failed to init GLFW.");
		return -1;
	}

	glfwSetErrorCallback(errorcb);
#ifndef _WIN32 // don't require this on win32, and works with more cards
	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);
#endif
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1);

	window = glfwCreateWindow(650, 650, "OUI Blendish Demo", NULL, NULL);
	if (!window) {
		glfwTerminate();
		return -1;
	}

	glfwSetKeyCallback(window, key);
    glfwSetCharCallback(window, charevent);
    glfwSetCursorPosCallback(window, cursorpos);
    glfwSetMouseButtonCallback(window, mousebutton);    
    glfwSetScrollCallback(window, scrollevent);

	glfwMakeContextCurrent(window);
#ifdef NANOVG_GLEW
	glewExperimental = GL_TRUE;
	if(glewInit() != GLEW_OK) {
		printf("Could not init glew.\n");
		return -1;
	}
	// GLEW generates GL error because it calls glGetString(GL_EXTENSIONS), we'll consume it here.
	glGetError();
#endif

	//_vg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
	_vg = nvgCreateGL3(NVG_ANTIALIAS);
	if (_vg == NULL) {
		printf("Could not init nanovg.\n");
		return -1;
	}
	
	init(_vg);

    printf("sizeof(UIitem)=%lu\n", sizeof(UIitem));

	glfwSwapInterval(0);

	glfwSetTime(0);

	double c = 0.0;
	int total = 0;

	int peak_items = 0;
	unsigned int peak_alloc = 0;

	while (!glfwWindowShouldClose(window))
	{
		double mx, my;
		int winWidth, winHeight;
		int fbWidth, fbHeight;
		float pxRatio;

		glfwGetCursorPos(window, &mx, &my);
		glfwGetWindowSize(window, &winWidth, &winHeight);
		glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
		// Calculate pixel ration for hi-dpi devices.
		pxRatio = (float)fbWidth / (float)winWidth;

		// Update and render
		glViewport(0, 0, fbWidth, fbHeight);
		glClearColor(0,0,0,1);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);

        double t = glfwGetTime();
		nvgBeginFrame(_vg, winWidth, winHeight, pxRatio);

        draw(_vg, winWidth, winHeight);
        peak_items = (peak_items > uiGetItemCount())?peak_items:uiGetItemCount();
        peak_alloc = (peak_alloc > uiGetAllocSize())?peak_alloc:uiGetAllocSize();

		nvgEndFrame(_vg);
        double t2 = glfwGetTime();
        c += (t2 - t);
        total++;
        if (total > (1*60)) {
            printf("%fms\n", (c / (double)total)*1000.0);
            total = 0;
            c = 0.0;
        }

		glfwSwapBuffers(window);
		glfwPollEvents();
	}
	printf("Peak item count: %i (%lu bytes)\nPeak allocated handles: %u bytes\n",
	        peak_items, peak_items * sizeof(UIitem), peak_alloc);

    uiDestroyContext(uictx);

	nvgDeleteGL3(_vg);

	glfwTerminate();
	return 0;
}